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 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2760 SetPixelRed(image,ClampToQuantum(background.red),q);
2761 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2762 SetPixelGreen(image,ClampToQuantum(background.green),q);
2763 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2764 SetPixelBlue(image,ClampToQuantum(background.blue),q);
2765 if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
2766 SetPixelBlack(image,ClampToQuantum(background.black),q);
2767 if ((GetPixelAlphaTraits(image) & CopyPixelTrait) != 0)
2768 SetPixelAlpha(image,ClampToQuantum(background.alpha),q);
2769 q+=GetPixelChannels(image);
2771 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2774 image_view=DestroyCacheView(image_view);
2779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2783 % S e t I m a g e C o l o r %
2787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2789 % SetImageColor() set the entire image canvas to the specified color.
2791 % The format of the SetImageColor method is:
2793 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color)
2795 % A description of each parameter follows:
2797 % o image: the image.
2799 % o background: the image color.
2802 MagickExport MagickBooleanType SetImageColor(Image *image,
2803 const PixelInfo *color)
2817 assert(image != (Image *) NULL);
2818 if (image->debug != MagickFalse)
2819 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2820 assert(image->signature == MagickSignature);
2821 assert(color != (const PixelInfo *) NULL);
2822 image->colorspace=color->colorspace;
2823 image->matte=color->matte;
2824 image->fuzz=color->fuzz;
2825 image->depth=color->depth;
2827 exception=(&image->exception);
2828 image_view=AcquireCacheView(image);
2829 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2830 #pragma omp parallel for schedule(dynamic,4) shared(status)
2832 for (y=0; y < (ssize_t) image->rows; y++)
2840 if (status == MagickFalse)
2842 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2843 if (q == (Quantum *) NULL)
2848 for (x=0; x < (ssize_t) image->columns; x++)
2850 SetPixelPixelInfo(image,color,q);
2851 q+=GetPixelChannels(image);
2853 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2856 image_view=DestroyCacheView(image_view);
2861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2865 % S e t I m a g e S t o r a g e C l a s s %
2869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2871 % SetImageStorageClass() sets the image class: DirectClass for true color
2872 % images or PseudoClass for colormapped images.
2874 % The format of the SetImageStorageClass method is:
2876 % MagickBooleanType SetImageStorageClass(Image *image,
2877 % const ClassType storage_class,ExceptionInfo *exception)
2879 % A description of each parameter follows:
2881 % o image: the image.
2883 % o storage_class: The image class.
2885 % o exception: return any errors or warnings in this structure.
2888 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2889 const ClassType storage_class,ExceptionInfo *exception)
2891 image->storage_class=storage_class;
2892 return(SyncImagePixelCache(image,exception));
2896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2900 % S e t I m a g e C l i p M a s k %
2904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2906 % SetImageClipMask() associates a clip path with the image. The clip path
2907 % must be the same dimensions as the image. Set any pixel component of
2908 % the clip path to TransparentAlpha to prevent that corresponding image
2909 % pixel component from being updated when SyncAuthenticPixels() is applied.
2911 % The format of the SetImageClipMask method is:
2913 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2914 % ExceptionInfo *exception)
2916 % A description of each parameter follows:
2918 % o image: the image.
2920 % o clip_mask: the image clip path.
2922 % o exception: return any errors or warnings in this structure.
2925 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2926 const Image *clip_mask,ExceptionInfo *exception)
2928 assert(image != (Image *) NULL);
2929 if (image->debug != MagickFalse)
2930 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2931 assert(image->signature == MagickSignature);
2932 if (clip_mask != (const Image *) NULL)
2933 if ((clip_mask->columns != image->columns) ||
2934 (clip_mask->rows != image->rows))
2935 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2936 if (image->clip_mask != (Image *) NULL)
2937 image->clip_mask=DestroyImage(image->clip_mask);
2938 image->clip_mask=NewImageList();
2939 if (clip_mask == (Image *) NULL)
2941 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
2942 return(MagickFalse);
2943 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2944 if (image->clip_mask == (Image *) NULL)
2945 return(MagickFalse);
2950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2954 % S e t I m a g e E x t e n t %
2958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2960 % SetImageExtent() sets the image size (i.e. columns & rows).
2962 % The format of the SetImageExtent method is:
2964 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2965 % const size_t rows,ExceptionInfo *exception)
2967 % A description of each parameter follows:
2969 % o image: the image.
2971 % o columns: The image width in pixels.
2973 % o rows: The image height in pixels.
2975 % o exception: return any errors or warnings in this structure.
2978 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2979 const size_t rows,ExceptionInfo *exception)
2981 if ((columns == 0) || (rows == 0))
2982 return(MagickFalse);
2983 image->columns=columns;
2985 return(SyncImagePixelCache(image,exception));
2989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2993 + S e t I m a g e I n f o %
2997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2999 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
3000 % It is set to a type of image format based on the prefix or suffix of the
3001 % filename. For example, `ps:image' returns PS indicating a Postscript image.
3002 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
3003 % precendence over the suffix. Use an optional index enclosed in brackets
3004 % after a file name to specify a desired scene of a multi-resolution image
3005 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
3006 % indicates success.
3008 % The format of the SetImageInfo method is:
3010 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
3011 % const unsigned int frames,ExceptionInfo *exception)
3013 % A description of each parameter follows:
3015 % o image_info: the image info.
3017 % o frames: the number of images you intend to write.
3019 % o exception: return any errors or warnings in this structure.
3022 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
3023 const unsigned int frames,ExceptionInfo *exception)
3026 extension[MaxTextExtent],
3027 filename[MaxTextExtent],
3028 magic[MaxTextExtent],
3030 subimage[MaxTextExtent];
3054 magick[2*MaxTextExtent];
3057 Look for 'image.format' in filename.
3059 assert(image_info != (ImageInfo *) NULL);
3060 assert(image_info->signature == MagickSignature);
3061 if (image_info->debug != MagickFalse)
3062 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3063 image_info->filename);
3067 GetPathComponent(image_info->filename,SubimagePath,subimage);
3068 if (*subimage != '\0')
3071 Look for scene specification (e.g. img0001.pcd[4]).
3073 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3075 if (IsGeometry(subimage) != MagickFalse)
3076 (void) CloneString(&image_info->extract,subimage);
3084 (void) CloneString(&image_info->scenes,subimage);
3085 image_info->scene=StringToUnsignedLong(image_info->scenes);
3086 image_info->number_scenes=image_info->scene;
3087 p=image_info->scenes;
3088 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3090 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3093 first=(size_t) strtol(p,&q,10);
3095 while (isspace((int) ((unsigned char) *q)) != 0)
3098 last=(size_t) strtol(q+1,&q,10);
3101 if (first < image_info->scene)
3102 image_info->scene=first;
3103 if (last > image_info->number_scenes)
3104 image_info->number_scenes=last;
3107 image_info->number_scenes-=image_info->scene-1;
3112 GetPathComponent(image_info->filename,ExtensionPath,extension);
3113 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3114 if (*extension != '\0')
3115 if ((LocaleCompare(extension,"gz") == 0) ||
3116 (LocaleCompare(extension,"Z") == 0) ||
3117 (LocaleCompare(extension,"wmz") == 0))
3120 path[MaxTextExtent];
3122 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3123 path[strlen(path)-strlen(extension)-1]='\0';
3124 GetPathComponent(path,ExtensionPath,extension);
3127 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3128 if (*extension != '\0')
3129 if (LocaleCompare(extension,"bz2") == 0)
3132 path[MaxTextExtent];
3134 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3135 path[strlen(path)-strlen(extension)-1]='\0';
3136 GetPathComponent(path,ExtensionPath,extension);
3139 image_info->affirm=MagickFalse;
3140 sans_exception=AcquireExceptionInfo();
3141 if (*extension != '\0')
3150 *format_type_formats[] =
3173 User specified image format.
3175 (void) CopyMagickString(magic,extension,MaxTextExtent);
3178 Look for explicit image formats.
3180 format_type=UndefinedFormatType;
3182 while ((format_type == UndefinedFormatType) &&
3183 (format_type_formats[i] != (char *) NULL))
3185 if ((*magic == *format_type_formats[i]) &&
3186 (LocaleCompare(magic,format_type_formats[i]) == 0))
3187 format_type=ExplicitFormatType;
3190 magick_info=GetMagickInfo(magic,sans_exception);
3191 if ((magick_info != (const MagickInfo *) NULL) &&
3192 (magick_info->format_type != UndefinedFormatType))
3193 format_type=magick_info->format_type;
3194 if (format_type == UndefinedFormatType)
3195 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3197 if (format_type == ExplicitFormatType)
3199 image_info->affirm=MagickTrue;
3200 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3202 if (LocaleCompare(magic,"RGB") == 0)
3203 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3206 Look for explicit 'format:image' in filename.
3209 GetPathComponent(image_info->filename,MagickPath,magic);
3211 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3215 User specified image format.
3218 if (IsMagickConflict(magic) == MagickFalse)
3220 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3221 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3222 image_info->affirm=MagickTrue;
3224 image_info->temporary=MagickTrue;
3227 magick_info=GetMagickInfo(magic,sans_exception);
3228 sans_exception=DestroyExceptionInfo(sans_exception);
3229 if ((magick_info == (const MagickInfo *) NULL) ||
3230 (GetMagickEndianSupport(magick_info) == MagickFalse))
3231 image_info->endian=UndefinedEndian;
3232 GetPathComponent(image_info->filename,CanonicalPath,filename);
3233 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3234 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3237 Test for multiple image support (e.g. image%02d.png).
3239 (void) InterpretImageFilename(image_info,(Image *) NULL,
3240 image_info->filename,(int) image_info->scene,filename);
3241 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3242 (strchr(filename,'%') == (char *) NULL))
3243 image_info->adjoin=MagickFalse;
3245 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3248 Some image formats do not support multiple frames per file.
3250 magick_info=GetMagickInfo(magic,exception);
3251 if (magick_info != (const MagickInfo *) NULL)
3252 if (GetMagickAdjoin(magick_info) == MagickFalse)
3253 image_info->adjoin=MagickFalse;
3255 if (image_info->affirm != MagickFalse)
3260 Determine the image format from the first few bytes of the file.
3262 image=AcquireImage(image_info);
3263 (void) CopyMagickString(image->filename,image_info->filename,
3265 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3266 if (status == MagickFalse)
3268 image=DestroyImage(image);
3269 return(MagickFalse);
3271 if ((IsBlobSeekable(image) == MagickFalse) ||
3272 (IsBlobExempt(image) != MagickFalse))
3275 Copy standard input or pipe to temporary file.
3278 status=ImageToFile(image,filename,exception);
3279 (void) CloseBlob(image);
3280 if (status == MagickFalse)
3282 image=DestroyImage(image);
3283 return(MagickFalse);
3285 SetImageInfoFile(image_info,(FILE *) NULL);
3286 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3287 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3288 if (status == MagickFalse)
3290 image=DestroyImage(image);
3291 return(MagickFalse);
3293 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3294 image_info->temporary=MagickTrue;
3296 (void) ResetMagickMemory(magick,0,sizeof(magick));
3297 count=ReadBlob(image,2*MaxTextExtent,magick);
3298 (void) CloseBlob(image);
3299 image=DestroyImage(image);
3301 Check magic.xml configuration file.
3303 sans_exception=AcquireExceptionInfo();
3304 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3305 if ((magic_info != (const MagicInfo *) NULL) &&
3306 (GetMagicName(magic_info) != (char *) NULL))
3308 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
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);
3317 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3318 if ((magick_info == (const MagickInfo *) NULL) ||
3319 (GetMagickEndianSupport(magick_info) == MagickFalse))
3320 image_info->endian=UndefinedEndian;
3321 sans_exception=DestroyExceptionInfo(sans_exception);
3327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3331 % S e t I m a g e I n f o B l o b %
3335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3337 % SetImageInfoBlob() sets the image info blob member.
3339 % The format of the SetImageInfoBlob method is:
3341 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3342 % const size_t length)
3344 % A description of each parameter follows:
3346 % o image_info: the image info.
3350 % o length: the blob length.
3353 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3354 const size_t length)
3356 assert(image_info != (ImageInfo *) NULL);
3357 assert(image_info->signature == MagickSignature);
3358 if (image_info->debug != MagickFalse)
3359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3360 image_info->filename);
3361 image_info->blob=(void *) blob;
3362 image_info->length=length;
3366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3370 % S e t I m a g e I n f o F i l e %
3374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3376 % SetImageInfoFile() sets the image info file member.
3378 % The format of the SetImageInfoFile method is:
3380 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3382 % A description of each parameter follows:
3384 % o image_info: the image info.
3389 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3391 assert(image_info != (ImageInfo *) NULL);
3392 assert(image_info->signature == MagickSignature);
3393 if (image_info->debug != MagickFalse)
3394 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3395 image_info->filename);
3396 image_info->file=file;
3400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3404 % S e t I m a g e M a s k %
3408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3410 % SetImageMask() associates a mask with the image. The mask must be the same
3411 % dimensions as the image.
3413 % The format of the SetImageMask method is:
3415 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3416 % ExceptionInfo *exception)
3418 % A description of each parameter follows:
3420 % o image: the image.
3422 % o mask: the image mask.
3424 % o exception: return any errors or warnings in this structure.
3427 MagickExport MagickBooleanType SetImageMask(Image *image,
3428 const Image *mask,ExceptionInfo *exception)
3430 assert(image != (Image *) NULL);
3431 if (image->debug != MagickFalse)
3432 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3433 assert(image->signature == MagickSignature);
3434 if (mask != (const Image *) NULL)
3435 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3436 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3437 if (image->mask != (Image *) NULL)
3438 image->mask=DestroyImage(image->mask);
3439 image->mask=NewImageList();
3440 if (mask == (Image *) NULL)
3442 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
3443 return(MagickFalse);
3444 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3445 if (image->mask == (Image *) NULL)
3446 return(MagickFalse);
3451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3455 % S e t I m a g e O p a c i t y %
3459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3461 % SetImageOpacity() sets the opacity levels of the image.
3463 % The format of the SetImageOpacity method is:
3465 % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3467 % A description of each parameter follows:
3469 % o image: the image.
3471 % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3472 % fully transparent.
3475 MagickExport MagickBooleanType SetImageOpacity(Image *image,
3476 const Quantum opacity)
3490 assert(image != (Image *) NULL);
3491 if (image->debug != MagickFalse)
3492 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3493 assert(image->signature == MagickSignature);
3494 image->matte=opacity != OpaqueAlpha ? MagickTrue : MagickFalse;
3496 exception=(&image->exception);
3497 image_view=AcquireCacheView(image);
3498 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3499 #pragma omp parallel for schedule(dynamic,4) shared(status)
3501 for (y=0; y < (ssize_t) image->rows; y++)
3509 if (status == MagickFalse)
3511 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3512 if (q == (Quantum *) NULL)
3517 for (x=0; x < (ssize_t) image->columns; x++)
3519 SetPixelAlpha(image,opacity,q);
3520 q+=GetPixelChannels(image);
3522 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3525 image_view=DestroyCacheView(image_view);
3530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3534 % S e t I m a g e T y p e %
3538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3540 % SetImageType() sets the type of image. Choose from these types:
3542 % Bilevel Grayscale GrayscaleMatte
3543 % Palette PaletteMatte TrueColor
3544 % TrueColorMatte ColorSeparation ColorSeparationMatte
3547 % The format of the SetImageType method is:
3549 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3550 % ExceptionInfo *exception)
3552 % A description of each parameter follows:
3554 % o image: the image.
3556 % o type: Image type.
3558 % o exception: return any errors or warnings in this structure.
3561 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3562 ExceptionInfo *exception)
3576 assert(image != (Image *) NULL);
3577 if (image->debug != MagickFalse)
3578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3579 assert(image->signature == MagickSignature);
3581 image_info=AcquireImageInfo();
3582 image_info->dither=image->dither;
3583 artifact=GetImageArtifact(image,"dither");
3584 if (artifact != (const char *) NULL)
3585 (void) SetImageOption(image_info,"dither",artifact);
3590 if (IsImageGray(image,&image->exception) == MagickFalse)
3591 status=TransformImageColorspace(image,GRAYColorspace);
3592 if (IsImageMonochrome(image,&image->exception) == MagickFalse)
3594 quantize_info=AcquireQuantizeInfo(image_info);
3595 quantize_info->number_colors=2;
3596 quantize_info->colorspace=GRAYColorspace;
3597 status=QuantizeImage(quantize_info,image,exception);
3598 quantize_info=DestroyQuantizeInfo(quantize_info);
3600 image->matte=MagickFalse;
3605 if (IsImageGray(image,&image->exception) == MagickFalse)
3606 status=TransformImageColorspace(image,GRAYColorspace);
3607 image->matte=MagickFalse;
3610 case GrayscaleMatteType:
3612 if (IsImageGray(image,&image->exception) == MagickFalse)
3613 status=TransformImageColorspace(image,GRAYColorspace);
3614 if (image->matte == MagickFalse)
3615 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3620 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3621 status=TransformImageColorspace(image,RGBColorspace);
3622 if ((image->storage_class == DirectClass) || (image->colors > 256))
3624 quantize_info=AcquireQuantizeInfo(image_info);
3625 quantize_info->number_colors=256;
3626 status=QuantizeImage(quantize_info,image,exception);
3627 quantize_info=DestroyQuantizeInfo(quantize_info);
3629 image->matte=MagickFalse;
3632 case PaletteBilevelMatteType:
3637 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3638 status=TransformImageColorspace(image,RGBColorspace);
3639 if (image->matte == MagickFalse)
3640 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3641 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3642 (void) BilevelImage(image,(double) QuantumRange/2.0);
3643 (void) SetPixelChannelMask(image,channel_mask);
3644 quantize_info=AcquireQuantizeInfo(image_info);
3645 status=QuantizeImage(quantize_info,image,exception);
3646 quantize_info=DestroyQuantizeInfo(quantize_info);
3649 case PaletteMatteType:
3651 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3652 status=TransformImageColorspace(image,RGBColorspace);
3653 if (image->matte == MagickFalse)
3654 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3655 quantize_info=AcquireQuantizeInfo(image_info);
3656 quantize_info->colorspace=TransparentColorspace;
3657 status=QuantizeImage(quantize_info,image,exception);
3658 quantize_info=DestroyQuantizeInfo(quantize_info);
3663 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3664 status=TransformImageColorspace(image,RGBColorspace);
3665 if (image->storage_class != DirectClass)
3666 status=SetImageStorageClass(image,DirectClass,&image->exception);
3667 image->matte=MagickFalse;
3670 case TrueColorMatteType:
3672 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3673 status=TransformImageColorspace(image,RGBColorspace);
3674 if (image->storage_class != DirectClass)
3675 status=SetImageStorageClass(image,DirectClass,&image->exception);
3676 if (image->matte == MagickFalse)
3677 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3680 case ColorSeparationType:
3682 if (image->colorspace != CMYKColorspace)
3684 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3685 status=TransformImageColorspace(image,RGBColorspace);
3686 status=TransformImageColorspace(image,CMYKColorspace);
3688 if (image->storage_class != DirectClass)
3689 status=SetImageStorageClass(image,DirectClass,&image->exception);
3690 image->matte=MagickFalse;
3693 case ColorSeparationMatteType:
3695 if (image->colorspace != CMYKColorspace)
3697 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3698 status=TransformImageColorspace(image,RGBColorspace);
3699 status=TransformImageColorspace(image,CMYKColorspace);
3701 if (image->storage_class != DirectClass)
3702 status=SetImageStorageClass(image,DirectClass,&image->exception);
3703 if (image->matte == MagickFalse)
3704 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3712 image_info=DestroyImageInfo(image_info);
3717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3721 % 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 %
3725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3727 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3728 % image and returns the previous setting. A virtual pixel is any pixel access
3729 % that is outside the boundaries of the image cache.
3731 % The format of the SetImageVirtualPixelMethod() method is:
3733 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3734 % const VirtualPixelMethod virtual_pixel_method)
3736 % A description of each parameter follows:
3738 % o image: the image.
3740 % o virtual_pixel_method: choose the type of virtual pixel.
3743 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3744 const VirtualPixelMethod virtual_pixel_method)
3746 assert(image != (const Image *) NULL);
3747 assert(image->signature == MagickSignature);
3748 if (image->debug != MagickFalse)
3749 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3750 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3758 % S m u s h I m a g e s %
3762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3764 % SmushImages() takes all images from the current image pointer to the end
3765 % of the image list and smushes them to each other top-to-bottom if the
3766 % stack parameter is true, otherwise left-to-right.
3768 % The current gravity setting now effects how the image is justified in the
3771 % The format of the SmushImages method is:
3773 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3774 % ExceptionInfo *exception)
3776 % A description of each parameter follows:
3778 % o images: the image sequence.
3780 % o stack: A value other than 0 stacks the images top-to-bottom.
3782 % o offset: minimum distance in pixels between images.
3784 % o exception: return any errors or warnings in this structure.
3788 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3789 const ssize_t offset,ExceptionInfo *exception)
3803 register const Quantum
3816 if (images->previous == (Image *) NULL)
3819 SetGeometry(smush_image,&right_geometry);
3820 GravityAdjustGeometry(right_image->columns,right_image->rows,
3821 right_image->gravity,&right_geometry);
3822 left_image=images->previous;
3823 SetGeometry(smush_image,&left_geometry);
3824 GravityAdjustGeometry(left_image->columns,left_image->rows,
3825 left_image->gravity,&left_geometry);
3826 gap=right_image->columns;
3827 left_view=AcquireCacheView(left_image);
3828 right_view=AcquireCacheView(right_image);
3829 for (y=0; y < (ssize_t) smush_image->rows; y++)
3831 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3833 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3834 if ((p == (const Quantum *) NULL) ||
3835 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3836 ((left_image->columns-x-1) >= gap))
3839 i=(ssize_t) left_image->columns-x-1;
3840 for (x=0; x < (ssize_t) right_image->columns; x++)
3842 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3844 if ((p == (const Quantum *) NULL) ||
3845 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3846 ((x+i) >= (ssize_t) gap))
3849 if ((x+i) < (ssize_t) gap)
3852 right_view=DestroyCacheView(right_view);
3853 left_view=DestroyCacheView(left_view);
3854 if (y < (ssize_t) smush_image->rows)
3856 return((ssize_t) gap-offset);
3859 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3860 const ssize_t offset,ExceptionInfo *exception)
3874 register const Quantum
3887 if (images->previous == (Image *) NULL)
3889 bottom_image=images;
3890 SetGeometry(smush_image,&bottom_geometry);
3891 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3892 bottom_image->gravity,&bottom_geometry);
3893 top_image=images->previous;
3894 SetGeometry(smush_image,&top_geometry);
3895 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3897 gap=bottom_image->rows;
3898 top_view=AcquireCacheView(top_image);
3899 bottom_view=AcquireCacheView(bottom_image);
3900 for (x=0; x < (ssize_t) smush_image->columns; x++)
3902 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3904 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3905 if ((p == (const Quantum *) NULL) ||
3906 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3907 ((top_image->rows-y-1) >= gap))
3910 i=(ssize_t) top_image->rows-y-1;
3911 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3913 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3915 if ((p == (const Quantum *) NULL) ||
3916 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3917 ((y+i) >= (ssize_t) gap))
3920 if ((y+i) < (ssize_t) gap)
3923 bottom_view=DestroyCacheView(bottom_view);
3924 top_view=DestroyCacheView(top_view);
3925 if (x < (ssize_t) smush_image->columns)
3927 return((ssize_t) gap-offset);
3930 MagickExport Image *SmushImages(const Image *images,
3931 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3933 #define SmushImageTag "Smush/Image"
3955 register const Image
3968 Compute maximum area of smushed area.
3970 assert(images != (Image *) NULL);
3971 assert(images->signature == MagickSignature);
3972 if (images->debug != MagickFalse)
3973 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3974 assert(exception != (ExceptionInfo *) NULL);
3975 assert(exception->signature == MagickSignature);
3979 width=image->columns;
3981 next=GetNextImageInList(image);
3982 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3984 if (next->matte != MagickFalse)
3987 if (stack != MagickFalse)
3989 if (next->columns > width)
3990 width=next->columns;
3992 if (next->previous != (Image *) NULL)
3996 width+=next->columns;
3997 if (next->previous != (Image *) NULL)
3999 if (next->rows > height)
4005 smush_image=CloneImage(image,width,height,MagickTrue,exception);
4006 if (smush_image == (Image *) NULL)
4007 return((Image *) NULL);
4008 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
4010 smush_image=DestroyImage(smush_image);
4011 return((Image *) NULL);
4013 smush_image->matte=matte;
4014 (void) SetImageBackgroundColor(smush_image);
4018 smush_view=AcquireCacheView(smush_image);
4019 for (n=0; n < (MagickOffsetType) number_images; n++)
4021 SetGeometry(smush_image,&geometry);
4022 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4023 if (stack != MagickFalse)
4025 x_offset-=geometry.x;
4026 y_offset-=SmushYGap(smush_image,image,offset,exception);
4030 x_offset-=SmushXGap(smush_image,image,offset,exception);
4031 y_offset-=geometry.y;
4033 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
4034 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4035 if (proceed == MagickFalse)
4037 if (stack == MagickFalse)
4039 x_offset+=(ssize_t) image->columns;
4045 y_offset+=(ssize_t) image->rows;
4047 image=GetNextImageInList(image);
4049 if (stack == MagickFalse)
4050 smush_image->columns=(size_t) x_offset;
4052 smush_image->rows=(size_t) y_offset;
4053 smush_view=DestroyCacheView(smush_view);
4054 if (status == MagickFalse)
4055 smush_image=DestroyImage(smush_image);
4056 return(smush_image);
4060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4064 % S t r i p I m a g e %
4068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4070 % StripImage() strips an image of all profiles and comments.
4072 % The format of the StripImage method is:
4074 % MagickBooleanType StripImage(Image *image)
4076 % A description of each parameter follows:
4078 % o image: the image.
4081 MagickExport MagickBooleanType StripImage(Image *image)
4083 assert(image != (Image *) NULL);
4084 if (image->debug != MagickFalse)
4085 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4086 DestroyImageProfiles(image);
4087 (void) DeleteImageProperty(image,"comment");
4088 (void) DeleteImageProperty(image,"date:create");
4089 (void) DeleteImageProperty(image,"date:modify");
4090 (void) SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4099 + S y n c I m a g e %
4103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4105 % SyncImage() initializes the red, green, and blue intensities of each pixel
4106 % as defined by the colormap index.
4108 % The format of the SyncImage method is:
4110 % MagickBooleanType SyncImage(Image *image)
4112 % A description of each parameter follows:
4114 % o image: the image.
4118 static inline Quantum PushColormapIndex(Image *image,
4119 const size_t index,MagickBooleanType *range_exception)
4121 if (index < image->colors)
4122 return((Quantum) index);
4123 *range_exception=MagickTrue;
4124 return((Quantum) 0);
4127 MagickExport MagickBooleanType SyncImage(Image *image)
4142 assert(image != (Image *) NULL);
4143 if (image->debug != MagickFalse)
4144 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4145 assert(image->signature == MagickSignature);
4146 if (image->storage_class == DirectClass)
4147 return(MagickFalse);
4148 range_exception=MagickFalse;
4150 exception=(&image->exception);
4151 image_view=AcquireCacheView(image);
4152 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4153 #pragma omp parallel for schedule(dynamic,4) shared(status)
4155 for (y=0; y < (ssize_t) image->rows; y++)
4166 if (status == MagickFalse)
4168 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4169 if (q == (Quantum *) NULL)
4174 for (x=0; x < (ssize_t) image->columns; x++)
4176 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4178 SetPixelPacket(image,image->colormap+(ssize_t) index,q);
4179 q+=GetPixelChannels(image);
4181 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4184 image_view=DestroyCacheView(image_view);
4185 if (range_exception != MagickFalse)
4186 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4187 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4196 % S y n c I m a g e S e t t i n g s %
4200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4202 % SyncImageSettings() sync the image info options to the image.
4204 % The format of the SyncImageSettings method is:
4206 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4208 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4211 % A description of each parameter follows:
4213 % o image_info: the image info.
4215 % o image: the image.
4219 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4225 assert(image_info != (const ImageInfo *) NULL);
4226 assert(image_info->signature == MagickSignature);
4227 assert(images != (Image *) NULL);
4228 assert(images->signature == MagickSignature);
4229 if (images->debug != MagickFalse)
4230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4232 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4233 (void) SyncImageSettings(image_info,image);
4234 (void) DeleteImageOption(image_info,"page");
4238 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4242 property[MaxTextExtent];
4260 assert(image_info != (const ImageInfo *) NULL);
4261 assert(image_info->signature == MagickSignature);
4262 assert(image != (Image *) NULL);
4263 assert(image->signature == MagickSignature);
4264 if (image->debug != MagickFalse)
4265 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4266 option=GetImageOption(image_info,"background");
4267 if (option != (const char *) NULL)
4268 (void) QueryColorDatabase(option,&image->background_color,
4270 option=GetImageOption(image_info,"bias");
4271 if (option != (const char *) NULL)
4272 image->bias=SiPrefixToDouble(option,QuantumRange);
4273 option=GetImageOption(image_info,"black-point-compensation");
4274 if (option != (const char *) NULL)
4275 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4276 MagickBooleanOptions,MagickFalse,option);
4277 option=GetImageOption(image_info,"blue-primary");
4278 if (option != (const char *) NULL)
4280 flags=ParseGeometry(option,&geometry_info);
4281 image->chromaticity.blue_primary.x=geometry_info.rho;
4282 image->chromaticity.blue_primary.y=geometry_info.sigma;
4283 if ((flags & SigmaValue) == 0)
4284 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4286 option=GetImageOption(image_info,"bordercolor");
4287 if (option != (const char *) NULL)
4288 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4289 option=GetImageOption(image_info,"colors");
4290 if (option != (const char *) NULL)
4291 image->colors=StringToUnsignedLong(option);
4292 option=GetImageOption(image_info,"compose");
4293 if (option != (const char *) NULL)
4294 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4295 MagickFalse,option);
4296 option=GetImageOption(image_info,"compress");
4297 if (option != (const char *) NULL)
4298 image->compression=(CompressionType) ParseCommandOption(
4299 MagickCompressOptions,MagickFalse,option);
4300 option=GetImageOption(image_info,"debug");
4301 if (option != (const char *) NULL)
4302 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4303 MagickFalse,option);
4304 option=GetImageOption(image_info,"density");
4305 if (option != (const char *) NULL)
4313 flags=ParseGeometry(option,&geometry_info);
4314 image->x_resolution=geometry_info.rho;
4315 image->y_resolution=geometry_info.sigma;
4316 if ((flags & SigmaValue) == 0)
4317 image->y_resolution=image->x_resolution;
4319 option=GetImageOption(image_info,"depth");
4320 if (option != (const char *) NULL)
4321 image->depth=StringToUnsignedLong(option);
4322 option=GetImageOption(image_info,"endian");
4323 if (option != (const char *) NULL)
4324 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4325 MagickFalse,option);
4326 option=GetImageOption(image_info,"filter");
4327 if (option != (const char *) NULL)
4328 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4329 MagickFalse,option);
4330 option=GetImageOption(image_info,"fuzz");
4331 if (option != (const char *) NULL)
4332 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4333 option=GetImageOption(image_info,"gravity");
4334 if (option != (const char *) NULL)
4335 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4336 MagickFalse,option);
4337 option=GetImageOption(image_info,"green-primary");
4338 if (option != (const char *) NULL)
4340 flags=ParseGeometry(option,&geometry_info);
4341 image->chromaticity.green_primary.x=geometry_info.rho;
4342 image->chromaticity.green_primary.y=geometry_info.sigma;
4343 if ((flags & SigmaValue) == 0)
4344 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4346 option=GetImageOption(image_info,"intent");
4347 if (option != (const char *) NULL)
4348 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4349 MagickIntentOptions,MagickFalse,option);
4350 option=GetImageOption(image_info,"interlace");
4351 if (option != (const char *) NULL)
4352 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4353 MagickFalse,option);
4354 option=GetImageOption(image_info,"interpolate");
4355 if (option != (const char *) NULL)
4356 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4357 MagickInterpolateOptions,MagickFalse,option);
4358 option=GetImageOption(image_info,"loop");
4359 if (option != (const char *) NULL)
4360 image->iterations=StringToUnsignedLong(option);
4361 option=GetImageOption(image_info,"mattecolor");
4362 if (option != (const char *) NULL)
4363 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4364 option=GetImageOption(image_info,"orient");
4365 if (option != (const char *) NULL)
4366 image->orientation=(OrientationType) ParseCommandOption(
4367 MagickOrientationOptions,MagickFalse,option);
4368 option=GetImageOption(image_info,"page");
4369 if (option != (const char *) NULL)
4374 geometry=GetPageGeometry(option);
4375 flags=ParseAbsoluteGeometry(geometry,&image->page);
4376 geometry=DestroyString(geometry);
4378 option=GetImageOption(image_info,"quality");
4379 if (option != (const char *) NULL)
4380 image->quality=StringToUnsignedLong(option);
4381 option=GetImageOption(image_info,"red-primary");
4382 if (option != (const char *) NULL)
4384 flags=ParseGeometry(option,&geometry_info);
4385 image->chromaticity.red_primary.x=geometry_info.rho;
4386 image->chromaticity.red_primary.y=geometry_info.sigma;
4387 if ((flags & SigmaValue) == 0)
4388 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4390 if (image_info->quality != UndefinedCompressionQuality)
4391 image->quality=image_info->quality;
4392 option=GetImageOption(image_info,"scene");
4393 if (option != (const char *) NULL)
4394 image->scene=StringToUnsignedLong(option);
4395 option=GetImageOption(image_info,"taint");
4396 if (option != (const char *) NULL)
4397 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4398 MagickFalse,option);
4399 option=GetImageOption(image_info,"tile-offset");
4400 if (option != (const char *) NULL)
4405 geometry=GetPageGeometry(option);
4406 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4407 geometry=DestroyString(geometry);
4409 option=GetImageOption(image_info,"transparent-color");
4410 if (option != (const char *) NULL)
4411 (void) QueryColorDatabase(option,&image->transparent_color,
4413 option=GetImageOption(image_info,"type");
4414 if (option != (const char *) NULL)
4415 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4417 option=GetImageOption(image_info,"units");
4418 if (option != (const char *) NULL)
4419 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4420 MagickFalse,option);
4422 units = image_info->units;
4423 if (units != UndefinedResolution)
4425 if (image->units != units)
4426 switch (image->units)
4428 case PixelsPerInchResolution:
4430 if (units == PixelsPerCentimeterResolution)
4432 image->x_resolution/=2.54;
4433 image->y_resolution/=2.54;
4437 case PixelsPerCentimeterResolution:
4439 if (units == PixelsPerInchResolution)
4441 image->x_resolution=(double) ((size_t) (100.0*2.54*
4442 image->x_resolution+0.5))/100.0;
4443 image->y_resolution=(double) ((size_t) (100.0*2.54*
4444 image->y_resolution+0.5))/100.0;
4453 option=GetImageOption(image_info,"white-point");
4454 if (option != (const char *) NULL)
4456 flags=ParseGeometry(option,&geometry_info);
4457 image->chromaticity.white_point.x=geometry_info.rho;
4458 image->chromaticity.white_point.y=geometry_info.sigma;
4459 if ((flags & SigmaValue) == 0)
4460 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4462 ResetImageOptionIterator(image_info);
4463 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4465 value=GetImageOption(image_info,option);
4466 if (value != (const char *) NULL)
4468 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4469 (void) SetImageArtifact(image,property,value);
4471 option=GetNextImageOption(image_info);