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,ExceptionInfo *exception)
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,
146 % o exception: return any errors or warnings in this structure.
149 MagickExport Image *AcquireImage(const ImageInfo *image_info,
150 ExceptionInfo *exception)
162 Allocate image structure.
164 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
165 image=(Image *) AcquireMagickMemory(sizeof(*image));
166 if (image == (Image *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 (void) ResetMagickMemory(image,0,sizeof(*image));
170 Initialize Image structure.
172 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
173 image->storage_class=DirectClass;
174 image->depth=MAGICKCORE_QUANTUM_DEPTH;
175 image->colorspace=RGBColorspace;
176 image->interlace=NoInterlace;
177 image->ticks_per_second=UndefinedTicksPerSecond;
178 image->compose=OverCompositeOp;
180 GetExceptionInfo(&image->exception);
181 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
182 &image->background_color,exception);
183 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
185 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
187 (void) QueryColorCompliance(TransparentColor,AllCompliance,
188 &image->transparent_color,exception);
189 image->x_resolution=DefaultResolution;
190 image->y_resolution=DefaultResolution;
191 image->units=PixelsPerInchResolution;
192 GetTimerInfo(&image->timer);
193 image->ping=MagickFalse;
194 image->cache=AcquirePixelCache(0);
195 image->channel_mask=DefaultChannels;
196 image->channel_map=AcquirePixelChannelMap();
197 image->blob=CloneBlobInfo((BlobInfo *) NULL);
198 image->debug=IsEventLogging();
199 image->reference_count=1;
200 image->semaphore=AllocateSemaphoreInfo();
201 image->signature=MagickSignature;
202 if (image_info == (ImageInfo *) NULL)
207 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
209 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
210 (void) CopyMagickString(image->magick_filename,image_info->filename,
212 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
213 if (image_info->size != (char *) NULL)
215 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
216 image->columns=image->extract_info.width;
217 image->rows=image->extract_info.height;
218 image->offset=image->extract_info.x;
219 image->extract_info.x=0;
220 image->extract_info.y=0;
222 if (image_info->extract != (char *) NULL)
227 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
228 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
230 image->extract_info=geometry;
231 Swap(image->columns,image->extract_info.width);
232 Swap(image->rows,image->extract_info.height);
235 image->compression=image_info->compression;
236 image->quality=image_info->quality;
237 image->endian=image_info->endian;
238 image->interlace=image_info->interlace;
239 image->units=image_info->units;
240 if (image_info->density != (char *) NULL)
245 flags=ParseGeometry(image_info->density,&geometry_info);
246 image->x_resolution=geometry_info.rho;
247 image->y_resolution=geometry_info.sigma;
248 if ((flags & SigmaValue) == 0)
249 image->y_resolution=image->x_resolution;
251 if (image_info->page != (char *) NULL)
256 image->page=image->extract_info;
257 geometry=GetPageGeometry(image_info->page);
258 (void) ParseAbsoluteGeometry(geometry,&image->page);
259 geometry=DestroyString(geometry);
261 if (image_info->depth != 0)
262 image->depth=image_info->depth;
263 image->dither=image_info->dither;
264 image->background_color=image_info->background_color;
265 image->border_color=image_info->border_color;
266 image->matte_color=image_info->matte_color;
267 image->transparent_color=image_info->transparent_color;
268 image->ping=image_info->ping;
269 image->progress_monitor=image_info->progress_monitor;
270 image->client_data=image_info->client_data;
271 if (image_info->cache != (void *) NULL)
272 ClonePixelCacheMethods(image->cache,image_info->cache);
273 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
274 (void) SyncImageSettings(image_info,image);
275 option=GetImageOption(image_info,"delay");
276 if (option != (const char *) NULL)
281 flags=ParseGeometry(option,&geometry_info);
282 if ((flags & GreaterValue) != 0)
284 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
285 image->delay=(size_t) floor(geometry_info.rho+0.5);
288 if ((flags & LessValue) != 0)
290 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
291 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
294 image->delay=(size_t) floor(geometry_info.rho+0.5);
295 if ((flags & SigmaValue) != 0)
296 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
298 option=GetImageOption(image_info,"dispose");
299 if (option != (const char *) NULL)
300 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % A c q u i r e I m a g e I n f o %
314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 % AcquireImageInfo() allocates the ImageInfo structure.
318 % The format of the AcquireImageInfo method is:
320 % ImageInfo *AcquireImageInfo(void)
323 MagickExport ImageInfo *AcquireImageInfo(void)
328 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
329 if (image_info == (ImageInfo *) NULL)
330 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
331 GetImageInfo(image_info);
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 % A c q u i r e N e x t I m a g e %
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 % AcquireNextImage() initializes the next image in a sequence to
347 % default values. The next member of image points to the newly allocated
348 % image. If there is a memory shortage, next is assigned NULL.
350 % The format of the AcquireNextImage method is:
352 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
353 % ExceptionInfo *exception)
355 % A description of each parameter follows:
357 % o image_info: Many of the image default values are set from this
358 % structure. For example, filename, compression, depth, background color,
361 % o image: the image.
363 % o exception: return any errors or warnings in this structure.
366 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
367 ExceptionInfo *exception)
370 Allocate image structure.
372 assert(image != (Image *) NULL);
373 assert(image->signature == MagickSignature);
374 if (image->debug != MagickFalse)
375 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
376 image->next=AcquireImage(image_info,exception);
377 if (GetNextImageInList(image) == (Image *) NULL)
379 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
381 if (image_info != (ImageInfo *) NULL)
382 (void) CopyMagickString(GetNextImageInList(image)->filename,
383 image_info->filename,MaxTextExtent);
384 DestroyBlob(GetNextImageInList(image));
385 image->next->blob=ReferenceBlob(image->blob);
386 image->next->endian=image->endian;
387 image->next->scene=image->scene+1;
388 image->next->previous=image;
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 % A p p e n d I m a g e s %
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 % AppendImages() takes all images from the current image pointer to the end
403 % of the image list and appends them to each other top-to-bottom if the
404 % stack parameter is true, otherwise left-to-right.
406 % The current gravity setting now effects how the image is justified in the
409 % The format of the AppendImages method is:
411 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
412 % ExceptionInfo *exception)
414 % A description of each parameter follows:
416 % o images: the image sequence.
418 % o stack: A value other than 0 stacks the images top-to-bottom.
420 % o exception: return any errors or warnings in this structure.
423 MagickExport Image *AppendImages(const Image *images,
424 const MagickBooleanType stack,ExceptionInfo *exception)
426 #define AppendImageTag "Append/Image"
463 Compute maximum area of appended area.
465 assert(images != (Image *) NULL);
466 assert(images->signature == MagickSignature);
467 if (images->debug != MagickFalse)
468 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
469 assert(exception != (ExceptionInfo *) NULL);
470 assert(exception->signature == MagickSignature);
474 width=image->columns;
476 next=GetNextImageInList(image);
477 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
479 if (next->matte != MagickFalse)
482 if (stack != MagickFalse)
484 if (next->columns > width)
489 width+=next->columns;
490 if (next->rows > height)
496 append_image=CloneImage(image,width,height,MagickTrue,exception);
497 if (append_image == (Image *) NULL)
498 return((Image *) NULL);
499 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
501 append_image=DestroyImage(append_image);
502 return((Image *) NULL);
504 append_image->matte=matte;
505 (void) SetImageBackgroundColor(append_image);
509 append_view=AcquireCacheView(append_image);
510 for (n=0; n < (MagickOffsetType) number_images; n++)
512 SetGeometry(append_image,&geometry);
513 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
514 if (stack != MagickFalse)
515 x_offset-=geometry.x;
517 y_offset-=geometry.y;
518 image_view=AcquireCacheView(image);
519 #if defined(MAGICKCORE_OPENMP_SUPPORT)
520 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
522 for (y=0; y < (ssize_t) image->rows; y++)
527 register const Quantum
536 if (status == MagickFalse)
538 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
539 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
540 image->columns,1,exception);
541 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
546 for (x=0; x < (ssize_t) image->columns; x++)
551 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
560 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
561 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
562 append_traits=GetPixelChannelMapTraits(append_image,channel);
563 if ((traits == UndefinedPixelTrait) ||
564 (append_traits == UndefinedPixelTrait))
566 SetPixelChannel(append_image,channel,p[i],q);
568 p+=GetPixelChannels(image);
569 q+=GetPixelChannels(append_image);
571 sync=SyncCacheViewAuthenticPixels(append_view,exception);
572 if (sync == MagickFalse)
575 image_view=DestroyCacheView(image_view);
576 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
577 if (proceed == MagickFalse)
579 if (stack == MagickFalse)
581 x_offset+=(ssize_t) image->columns;
587 y_offset+=(ssize_t) image->rows;
589 image=GetNextImageInList(image);
591 append_view=DestroyCacheView(append_view);
592 if (status == MagickFalse)
593 append_image=DestroyImage(append_image);
594 return(append_image);
598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
602 % C a t c h I m a g e E x c e p t i o n %
606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608 % CatchImageException() returns if no exceptions are found in the image
609 % sequence, otherwise it determines the most severe exception and reports
610 % it as a warning or error depending on the severity.
612 % The format of the CatchImageException method is:
614 % ExceptionType CatchImageException(Image *image)
616 % A description of each parameter follows:
618 % o image: An image sequence.
621 MagickExport ExceptionType CatchImageException(Image *image)
629 assert(image != (const Image *) NULL);
630 assert(image->signature == MagickSignature);
631 if (image->debug != MagickFalse)
632 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
633 exception=AcquireExceptionInfo();
634 GetImageException(image,exception);
635 CatchException(exception);
636 severity=exception->severity;
637 exception=DestroyExceptionInfo(exception);
642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 % C l i p I m a g e P a t h %
650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652 % ClipImagePath() sets the image clip mask based any clipping path information
655 % The format of the ClipImagePath method is:
657 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
658 % const MagickBooleanType inside,ExceptionInfo *exception)
660 % A description of each parameter follows:
662 % o image: the image.
664 % o pathname: name of clipping path resource. If name is preceded by #, use
665 % clipping path numbered by name.
667 % o inside: if non-zero, later operations take effect inside clipping path.
668 % Otherwise later operations take effect outside clipping path.
670 % o exception: return any errors or warnings in this structure.
674 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
676 return(ClipImagePath(image,"#1",MagickTrue,exception));
679 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
680 const MagickBooleanType inside,ExceptionInfo *exception)
682 #define ClipImagePathTag "ClipPath/Image"
696 assert(image != (const Image *) NULL);
697 assert(image->signature == MagickSignature);
698 if (image->debug != MagickFalse)
699 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
700 assert(pathname != NULL);
701 property=AcquireString(pathname);
702 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
704 value=GetImageProperty(image,property);
705 property=DestroyString(property);
706 if (value == (const char *) NULL)
708 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
712 image_info=AcquireImageInfo();
713 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
714 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
715 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
716 image_info=DestroyImageInfo(image_info);
717 if (clip_mask == (Image *) NULL)
719 if (clip_mask->storage_class == PseudoClass)
721 (void) SyncImage(clip_mask);
722 if (SetImageStorageClass(clip_mask,DirectClass,&image->exception) == MagickFalse)
725 if (inside == MagickFalse)
726 (void) NegateImage(clip_mask,MagickFalse,&image->exception);
727 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
728 "8BIM:1999,2998:%s\nPS",pathname);
729 (void) SetImageClipMask(image,clip_mask,exception);
730 clip_mask=DestroyImage(clip_mask);
735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
739 % C l o n e I m a g e %
743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
745 % CloneImage() copies an image and returns the copy as a new image object.
747 % If the specified columns and rows is 0, an exact copy of the image is
748 % returned, otherwise the pixel data is undefined and must be initialized
749 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
750 % failure, a NULL image is returned and exception describes the reason for the
753 % The format of the CloneImage method is:
755 % Image *CloneImage(const Image *image,const size_t columns,
756 % const size_t rows,const MagickBooleanType orphan,
757 % ExceptionInfo *exception)
759 % A description of each parameter follows:
761 % o image: the image.
763 % o columns: the number of columns in the cloned image.
765 % o rows: the number of rows in the cloned image.
767 % o detach: With a value other than 0, the cloned image is detached from
768 % its parent I/O stream.
770 % o exception: return any errors or warnings in this structure.
773 MagickExport Image *CloneImage(const Image *image,const size_t columns,
774 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
788 assert(image != (const Image *) NULL);
789 assert(image->signature == MagickSignature);
790 if (image->debug != MagickFalse)
791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
792 assert(exception != (ExceptionInfo *) NULL);
793 assert(exception->signature == MagickSignature);
794 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
795 if (clone_image == (Image *) NULL)
796 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
797 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
798 clone_image->signature=MagickSignature;
799 clone_image->storage_class=image->storage_class;
800 clone_image->number_channels=image->number_channels;
801 clone_image->number_meta_channels=image->number_meta_channels;
802 clone_image->metacontent_extent=image->metacontent_extent;
803 clone_image->colorspace=image->colorspace;
804 clone_image->matte=image->matte;
805 clone_image->columns=image->columns;
806 clone_image->rows=image->rows;
807 clone_image->dither=image->dither;
808 if (image->colormap != (PixelPacket *) NULL)
811 Allocate and copy the image colormap.
813 clone_image->colors=image->colors;
814 length=(size_t) image->colors;
815 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
816 sizeof(*clone_image->colormap));
817 if (clone_image->colormap == (PixelPacket *) NULL)
818 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
819 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
820 sizeof(*clone_image->colormap));
822 (void) CloneImageProfiles(clone_image,image);
823 (void) CloneImageProperties(clone_image,image);
824 (void) CloneImageArtifacts(clone_image,image);
825 GetTimerInfo(&clone_image->timer);
826 GetExceptionInfo(&clone_image->exception);
827 InheritException(&clone_image->exception,&image->exception);
828 if (image->ascii85 != (void *) NULL)
829 Ascii85Initialize(clone_image);
830 clone_image->magick_columns=image->magick_columns;
831 clone_image->magick_rows=image->magick_rows;
832 clone_image->type=image->type;
833 clone_image->sync=image->sync;
834 clone_image->channel_mask=image->channel_mask;
835 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
836 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
838 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
839 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
840 clone_image->progress_monitor=image->progress_monitor;
841 clone_image->client_data=image->client_data;
842 clone_image->reference_count=1;
843 clone_image->next=image->next;
844 clone_image->previous=image->previous;
845 clone_image->list=NewImageList();
846 clone_image->clip_mask=NewImageList();
847 clone_image->mask=NewImageList();
848 if (detach == MagickFalse)
849 clone_image->blob=ReferenceBlob(image->blob);
852 clone_image->next=NewImageList();
853 clone_image->previous=NewImageList();
854 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
856 clone_image->ping=image->ping;
857 clone_image->debug=IsEventLogging();
858 clone_image->semaphore=AllocateSemaphoreInfo();
859 if ((columns == 0) && (rows == 0))
861 if (image->montage != (char *) NULL)
862 (void) CloneString(&clone_image->montage,image->montage);
863 if (image->directory != (char *) NULL)
864 (void) CloneString(&clone_image->directory,image->directory);
865 if (image->clip_mask != (Image *) NULL)
866 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
868 if (image->mask != (Image *) NULL)
869 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
870 clone_image->cache=ReferencePixelCache(image->cache);
873 if ((columns == image->columns) && (rows == image->rows))
875 if (image->clip_mask != (Image *) NULL)
876 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
878 if (image->mask != (Image *) NULL)
879 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
881 scale=(MagickRealType) columns/(MagickRealType) image->columns;
882 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
883 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
884 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
885 scale=(MagickRealType) rows/(MagickRealType) image->rows;
886 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
887 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
888 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
889 clone_image->columns=columns;
890 clone_image->rows=rows;
891 clone_image->cache=ClonePixelCache(image->cache);
896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 % C l o n e I m a g e I n f o %
904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
906 % CloneImageInfo() makes a copy of the given image info structure. If
907 % NULL is specified, a new image info structure is created initialized to
910 % The format of the CloneImageInfo method is:
912 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
914 % A description of each parameter follows:
916 % o image_info: the image info.
919 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
924 clone_info=AcquireImageInfo();
925 if (image_info == (ImageInfo *) NULL)
927 clone_info->compression=image_info->compression;
928 clone_info->temporary=image_info->temporary;
929 clone_info->adjoin=image_info->adjoin;
930 clone_info->antialias=image_info->antialias;
931 clone_info->scene=image_info->scene;
932 clone_info->number_scenes=image_info->number_scenes;
933 clone_info->depth=image_info->depth;
934 if (image_info->size != (char *) NULL)
935 (void) CloneString(&clone_info->size,image_info->size);
936 if (image_info->extract != (char *) NULL)
937 (void) CloneString(&clone_info->extract,image_info->extract);
938 if (image_info->scenes != (char *) NULL)
939 (void) CloneString(&clone_info->scenes,image_info->scenes);
940 if (image_info->page != (char *) NULL)
941 (void) CloneString(&clone_info->page,image_info->page);
942 clone_info->interlace=image_info->interlace;
943 clone_info->endian=image_info->endian;
944 clone_info->units=image_info->units;
945 clone_info->quality=image_info->quality;
946 if (image_info->sampling_factor != (char *) NULL)
947 (void) CloneString(&clone_info->sampling_factor,
948 image_info->sampling_factor);
949 if (image_info->server_name != (char *) NULL)
950 (void) CloneString(&clone_info->server_name,image_info->server_name);
951 if (image_info->font != (char *) NULL)
952 (void) CloneString(&clone_info->font,image_info->font);
953 if (image_info->texture != (char *) NULL)
954 (void) CloneString(&clone_info->texture,image_info->texture);
955 if (image_info->density != (char *) NULL)
956 (void) CloneString(&clone_info->density,image_info->density);
957 clone_info->pointsize=image_info->pointsize;
958 clone_info->fuzz=image_info->fuzz;
959 clone_info->background_color=image_info->background_color;
960 clone_info->border_color=image_info->border_color;
961 clone_info->matte_color=image_info->matte_color;
962 clone_info->transparent_color=image_info->transparent_color;
963 clone_info->dither=image_info->dither;
964 clone_info->monochrome=image_info->monochrome;
965 clone_info->colors=image_info->colors;
966 clone_info->colorspace=image_info->colorspace;
967 clone_info->type=image_info->type;
968 clone_info->orientation=image_info->orientation;
969 clone_info->preview_type=image_info->preview_type;
970 clone_info->group=image_info->group;
971 clone_info->ping=image_info->ping;
972 clone_info->verbose=image_info->verbose;
973 if (image_info->view != (char *) NULL)
974 (void) CloneString(&clone_info->view,image_info->view);
975 clone_info->progress_monitor=image_info->progress_monitor;
976 clone_info->client_data=image_info->client_data;
977 clone_info->cache=image_info->cache;
978 if (image_info->cache != (void *) NULL)
979 clone_info->cache=ReferencePixelCache(image_info->cache);
980 if (image_info->profile != (void *) NULL)
981 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
982 image_info->profile);
983 SetImageInfoFile(clone_info,image_info->file);
984 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
985 clone_info->stream=image_info->stream;
986 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
987 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
988 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
989 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
990 (void) CopyMagickString(clone_info->filename,image_info->filename,
992 clone_info->channel=image_info->channel;
994 (void) CloneImageOptions(clone_info,image_info);
995 clone_info->debug=IsEventLogging();
996 clone_info->signature=image_info->signature;
1001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1005 % C o m b i n e I m a g e s %
1009 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1011 % CombineImages() combines one or more images into a single image. The
1012 % grayscale value of the pixels of each image in the sequence is assigned in
1013 % order to the specified channels of the combined image. The typical
1014 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
1016 % The format of the CombineImages method is:
1018 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
1020 % A description of each parameter follows:
1022 % o image: the image.
1024 % o exception: return any errors or warnings in this structure.
1028 static inline size_t MagickMin(const size_t x,const size_t y)
1035 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1037 #define CombineImageTag "Combine/Image"
1055 Ensure the image are the same size.
1057 assert(image != (const Image *) NULL);
1058 assert(image->signature == MagickSignature);
1059 if (image->debug != MagickFalse)
1060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1061 assert(exception != (ExceptionInfo *) NULL);
1062 assert(exception->signature == MagickSignature);
1063 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1064 if (combine_image == (Image *) NULL)
1065 return((Image *) NULL);
1066 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1068 combine_image=DestroyImage(combine_image);
1069 return((Image *) NULL);
1071 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1072 combine_image->matte=MagickTrue;
1078 combine_view=AcquireCacheView(combine_image);
1079 for (y=0; y < (ssize_t) combine_image->rows; y++)
1090 register const Quantum
1099 if (status == MagickFalse)
1101 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1103 if (pixels == (Quantum *) NULL)
1109 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1121 if (next == (Image *) NULL)
1123 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1124 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1125 combine_traits=GetPixelChannelMapTraits(combine_image,channel);
1126 if ((traits == UndefinedPixelTrait) ||
1127 (combine_traits == UndefinedPixelTrait))
1129 image_view=AcquireCacheView(next);
1130 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1131 if (p == (const Quantum *) NULL)
1134 for (x=0; x < (ssize_t) combine_image->columns; x++)
1136 if (x < (ssize_t) image->columns)
1139 p+=GetPixelChannels(image);
1141 q+=GetPixelChannels(combine_image);
1143 image_view=DestroyCacheView(image_view);
1144 next=GetNextImageInList(next);
1145 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1147 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1152 proceed=SetImageProgress(image,CombineImageTag,progress++,
1153 combine_image->rows);
1154 if (proceed == MagickFalse)
1159 combine_view=DestroyCacheView(combine_view);
1160 if (status == MagickFalse)
1161 combine_image=DestroyImage(combine_image);
1162 return(combine_image);
1166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1170 % D e s t r o y I m a g e %
1174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1176 % DestroyImage() dereferences an image, deallocating memory associated with
1177 % the image if the reference count becomes zero.
1179 % The format of the DestroyImage method is:
1181 % Image *DestroyImage(Image *image)
1183 % A description of each parameter follows:
1185 % o image: the image.
1188 MagickExport Image *DestroyImage(Image *image)
1196 assert(image != (Image *) NULL);
1197 assert(image->signature == MagickSignature);
1198 if (image->debug != MagickFalse)
1199 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1200 destroy=MagickFalse;
1201 LockSemaphoreInfo(image->semaphore);
1202 image->reference_count--;
1203 if (image->reference_count == 0)
1205 UnlockSemaphoreInfo(image->semaphore);
1206 if (destroy == MagickFalse)
1207 return((Image *) NULL);
1211 DestroyImagePixels(image);
1212 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1213 if (image->clip_mask != (Image *) NULL)
1214 image->clip_mask=DestroyImage(image->clip_mask);
1215 if (image->mask != (Image *) NULL)
1216 image->mask=DestroyImage(image->mask);
1217 if (image->montage != (char *) NULL)
1218 image->montage=DestroyString(image->montage);
1219 if (image->directory != (char *) NULL)
1220 image->directory=DestroyString(image->directory);
1221 if (image->colormap != (PixelPacket *) NULL)
1222 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1223 if (image->geometry != (char *) NULL)
1224 image->geometry=DestroyString(image->geometry);
1225 DestroyImageProfiles(image);
1226 DestroyImageProperties(image);
1227 DestroyImageArtifacts(image);
1228 if (image->ascii85 != (Ascii85Info*) NULL)
1229 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1231 (void) DestroyExceptionInfo(&image->exception);
1232 if (image->semaphore != (SemaphoreInfo *) NULL)
1233 DestroySemaphoreInfo(&image->semaphore);
1234 image->signature=(~MagickSignature);
1235 image=(Image *) RelinquishMagickMemory(image);
1240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1244 % D e s t r o y I m a g e I n f o %
1248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1250 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1253 % The format of the DestroyImageInfo method is:
1255 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1257 % A description of each parameter follows:
1259 % o image_info: the image info.
1262 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1264 assert(image_info != (ImageInfo *) NULL);
1265 assert(image_info->signature == MagickSignature);
1266 if (image_info->debug != MagickFalse)
1267 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1268 image_info->filename);
1269 if (image_info->size != (char *) NULL)
1270 image_info->size=DestroyString(image_info->size);
1271 if (image_info->extract != (char *) NULL)
1272 image_info->extract=DestroyString(image_info->extract);
1273 if (image_info->scenes != (char *) NULL)
1274 image_info->scenes=DestroyString(image_info->scenes);
1275 if (image_info->page != (char *) NULL)
1276 image_info->page=DestroyString(image_info->page);
1277 if (image_info->sampling_factor != (char *) NULL)
1278 image_info->sampling_factor=DestroyString(
1279 image_info->sampling_factor);
1280 if (image_info->server_name != (char *) NULL)
1281 image_info->server_name=DestroyString(
1282 image_info->server_name);
1283 if (image_info->font != (char *) NULL)
1284 image_info->font=DestroyString(image_info->font);
1285 if (image_info->texture != (char *) NULL)
1286 image_info->texture=DestroyString(image_info->texture);
1287 if (image_info->density != (char *) NULL)
1288 image_info->density=DestroyString(image_info->density);
1289 if (image_info->view != (char *) NULL)
1290 image_info->view=DestroyString(image_info->view);
1291 if (image_info->cache != (void *) NULL)
1292 image_info->cache=DestroyPixelCache(image_info->cache);
1293 if (image_info->profile != (StringInfo *) NULL)
1294 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1295 image_info->profile);
1296 DestroyImageOptions(image_info);
1297 image_info->signature=(~MagickSignature);
1298 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1307 + D i s a s s o c i a t e I m a g e S t r e a m %
1311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1313 % DisassociateImageStream() disassociates the image stream.
1315 % The format of the DisassociateImageStream method is:
1317 % MagickBooleanType DisassociateImageStream(const Image *image)
1319 % A description of each parameter follows:
1321 % o image: the image.
1324 MagickExport void DisassociateImageStream(Image *image)
1326 assert(image != (const Image *) NULL);
1327 assert(image->signature == MagickSignature);
1328 if (image->debug != MagickFalse)
1329 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1330 (void) DetachBlob(image->blob);
1334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1338 % G e t I m a g e A l p h a C h a n n e l %
1342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1344 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1345 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1348 % The format of the GetImageAlphaChannel method is:
1350 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1352 % A description of each parameter follows:
1354 % o image: the image.
1357 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1359 assert(image != (const Image *) NULL);
1360 if (image->debug != MagickFalse)
1361 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1362 assert(image->signature == MagickSignature);
1363 return(image->matte);
1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1371 % G e t I m a g e C l i p M a s k %
1375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1377 % GetImageClipMask() returns the clip path associated with the image.
1379 % The format of the GetImageClipMask method is:
1381 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1383 % A description of each parameter follows:
1385 % o image: the image.
1388 MagickExport Image *GetImageClipMask(const Image *image,
1389 ExceptionInfo *exception)
1391 assert(image != (const Image *) NULL);
1392 if (image->debug != MagickFalse)
1393 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1394 assert(image->signature == MagickSignature);
1395 if (image->clip_mask == (Image *) NULL)
1396 return((Image *) NULL);
1397 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405 % G e t I m a g e E x c e p t i o n %
1409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1411 % GetImageException() traverses an image sequence and returns any
1412 % error more severe than noted by the exception parameter.
1414 % The format of the GetImageException method is:
1416 % void GetImageException(Image *image,ExceptionInfo *exception)
1418 % A description of each parameter follows:
1420 % o image: Specifies a pointer to a list of one or more images.
1422 % o exception: return the highest severity exception.
1425 MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1430 assert(image != (Image *) NULL);
1431 assert(image->signature == MagickSignature);
1432 if (image->debug != MagickFalse)
1433 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1434 assert(exception != (ExceptionInfo *) NULL);
1435 assert(exception->signature == MagickSignature);
1436 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1438 if (next->exception.severity == UndefinedException)
1440 if (next->exception.severity > exception->severity)
1441 InheritException(exception,&next->exception);
1442 next->exception.severity=UndefinedException;
1447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1451 % G e t I m a g e I n f o %
1455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1457 % GetImageInfo() initializes image_info to default values.
1459 % The format of the GetImageInfo method is:
1461 % void GetImageInfo(ImageInfo *image_info)
1463 % A description of each parameter follows:
1465 % o image_info: the image info.
1468 MagickExport void GetImageInfo(ImageInfo *image_info)
1477 File and image dimension members.
1479 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1480 assert(image_info != (ImageInfo *) NULL);
1481 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1482 image_info->adjoin=MagickTrue;
1483 image_info->interlace=NoInterlace;
1484 image_info->channel=DefaultChannels;
1485 image_info->quality=UndefinedCompressionQuality;
1486 image_info->antialias=MagickTrue;
1487 image_info->dither=MagickTrue;
1488 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1489 if (synchronize != (const char *) NULL)
1490 image_info->synchronize=IsMagickTrue(synchronize);
1491 exception=AcquireExceptionInfo();
1492 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1493 &image_info->background_color,exception);
1494 (void) QueryColorCompliance(BorderColor,AllCompliance,
1495 &image_info->border_color,exception);
1496 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1498 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1499 &image_info->transparent_color,exception);
1500 exception=DestroyExceptionInfo(exception);
1501 image_info->debug=IsEventLogging();
1502 image_info->signature=MagickSignature;
1506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1510 % G e t I m a g e I n f o F i l e %
1514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1516 % GetImageInfoFile() returns the image info file member.
1518 % The format of the GetImageInfoFile method is:
1520 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1522 % A description of each parameter follows:
1524 % o image_info: the image info.
1527 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1529 return(image_info->file);
1533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 % G e t I m a g e M a s k %
1541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1543 % GetImageMask() returns the mask associated with the image.
1545 % The format of the GetImageMask method is:
1547 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1549 % A description of each parameter follows:
1551 % o image: the image.
1554 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1556 assert(image != (const Image *) NULL);
1557 if (image->debug != MagickFalse)
1558 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1559 assert(image->signature == MagickSignature);
1560 if (image->mask == (Image *) NULL)
1561 return((Image *) NULL);
1562 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1570 + G e t I m a g e R e f e r e n c e C o u n t %
1574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1576 % GetImageReferenceCount() returns the image reference count.
1578 % The format of the GetReferenceCount method is:
1580 % ssize_t GetImageReferenceCount(Image *image)
1582 % A description of each parameter follows:
1584 % o image: the image.
1587 MagickExport ssize_t GetImageReferenceCount(Image *image)
1592 assert(image != (Image *) NULL);
1593 assert(image->signature == MagickSignature);
1594 if (image->debug != MagickFalse)
1595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1596 LockSemaphoreInfo(image->semaphore);
1597 reference_count=image->reference_count;
1598 UnlockSemaphoreInfo(image->semaphore);
1599 return(reference_count);
1603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1607 % 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 %
1611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1613 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1614 % image. A virtual pixel is any pixel access that is outside the boundaries
1615 % of the image cache.
1617 % The format of the GetImageVirtualPixelMethod() method is:
1619 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1621 % A description of each parameter follows:
1623 % o image: the image.
1626 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1628 assert(image != (Image *) NULL);
1629 assert(image->signature == MagickSignature);
1630 if (image->debug != MagickFalse)
1631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1632 return(GetPixelCacheVirtualMethod(image));
1636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 % I n t e r p r e t I m a g e F i l e n a m e %
1644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1646 % InterpretImageFilename() interprets embedded characters in an image filename.
1647 % The filename length is returned.
1649 % The format of the InterpretImageFilename method is:
1651 % size_t InterpretImageFilename(const ImageInfo *image_info,
1652 % Image *image,const char *format,int value,char *filename)
1654 % A description of each parameter follows.
1656 % o image_info: the image info..
1658 % o image: the image.
1660 % o format: A filename describing the format to use to write the numeric
1661 % argument. Only the first numeric format identifier is replaced.
1663 % o value: Numeric value to substitute into format filename.
1665 % o filename: return the formatted filename in this character buffer.
1668 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1669 Image *image,const char *format,int value,char *filename)
1686 canonical=MagickFalse;
1688 (void) CopyMagickString(filename,format,MaxTextExtent);
1689 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1702 value=(ssize_t) strtol(q,&q,10);
1714 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1715 (p-format)),p,value);
1717 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1718 canonical=MagickTrue;
1727 pattern[MaxTextExtent];
1744 if (strchr(p,']') == (char *) NULL)
1748 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1759 if (LocaleNCompare(pattern,"filename:",9) != 0)
1761 value=(const char *) NULL;
1762 if ((image_info != (const ImageInfo *) NULL) &&
1763 (image != (const Image *) NULL))
1764 value=GetMagickProperty(image_info,image,pattern);
1766 if (image != (Image *) NULL)
1767 value=GetImageProperty(image,pattern);
1769 if (image_info != (ImageInfo *) NULL)
1770 value=GetImageOption(image_info,pattern);
1771 if (value == (const char *) NULL)
1776 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1777 (MaxTextExtent-(p-format-length)));
1778 length+=strlen(pattern)-1;
1780 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1781 canonical=MagickTrue;
1791 for (q=filename; *q != '\0'; q++)
1792 if ((*q == '%') && (*(q+1) == '%'))
1794 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1795 canonical=MagickTrue;
1797 if (canonical == MagickFalse)
1798 (void) CopyMagickString(filename,format,MaxTextExtent);
1799 return(strlen(filename));
1803 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1807 % I s H i g h D y n a m i c R a n g e I m a g e %
1811 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1813 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1814 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1817 % The format of the IsHighDynamicRangeImage method is:
1819 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1820 % ExceptionInfo *exception)
1822 % A description of each parameter follows:
1824 % o image: the image.
1826 % o exception: return any errors or warnings in this structure.
1829 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1830 ExceptionInfo *exception)
1832 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1835 return(MagickFalse);
1846 assert(image != (Image *) NULL);
1847 assert(image->signature == MagickSignature);
1848 if (image->debug != MagickFalse)
1849 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1851 GetPixelInfo(image,&zero);
1852 image_view=AcquireCacheView(image);
1853 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1854 #pragma omp parallel for schedule(dynamic,4) shared(status)
1856 for (y=0; y < (ssize_t) image->rows; y++)
1861 register const Quantum
1867 if (status == MagickFalse)
1869 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1870 if (p == (const Quantum *) NULL)
1876 for (x=0; x < (ssize_t) image->columns; x++)
1884 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1889 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1890 if (traits == UndefinedPixelTrait)
1892 pixel=(MagickRealType) p[i];
1893 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1894 (pixel != (QuantumAny) pixel))
1897 p+=GetPixelChannels(image);
1898 if (i < (ssize_t) GetPixelChannels(image))
1901 if (x < (ssize_t) image->columns)
1904 image_view=DestroyCacheView(image_view);
1905 return(status != MagickFalse ? MagickFalse : MagickTrue);
1910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1914 % I s I m a g e O b j e c t %
1918 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1920 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1921 % set of image objects.
1923 % The format of the IsImageObject method is:
1925 % MagickBooleanType IsImageObject(const Image *image)
1927 % A description of each parameter follows:
1929 % o image: the image.
1932 MagickExport MagickBooleanType IsImageObject(const Image *image)
1934 register const Image
1937 assert(image != (Image *) NULL);
1938 if (image->debug != MagickFalse)
1939 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1940 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1941 if (p->signature != MagickSignature)
1942 return(MagickFalse);
1947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1951 % I s T a i n t I m a g e %
1955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1957 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1958 % since it was first constituted.
1960 % The format of the IsTaintImage method is:
1962 % MagickBooleanType IsTaintImage(const Image *image)
1964 % A description of each parameter follows:
1966 % o image: the image.
1969 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1972 magick[MaxTextExtent],
1973 filename[MaxTextExtent];
1975 register const Image
1978 assert(image != (Image *) NULL);
1979 if (image->debug != MagickFalse)
1980 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1981 assert(image->signature == MagickSignature);
1982 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1983 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1984 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1986 if (p->taint != MagickFalse)
1988 if (LocaleCompare(p->magick,magick) != 0)
1990 if (LocaleCompare(p->filename,filename) != 0)
1993 return(MagickFalse);
1997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001 % M o d i f y I m a g e %
2005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2007 % ModifyImage() ensures that there is only a single reference to the image
2008 % to be modified, updating the provided image pointer to point to a clone of
2009 % the original image if necessary.
2011 % The format of the ModifyImage method is:
2013 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2015 % A description of each parameter follows:
2017 % o image: the image.
2019 % o exception: return any errors or warnings in this structure.
2022 MagickExport MagickBooleanType ModifyImage(Image **image,
2023 ExceptionInfo *exception)
2028 assert(image != (Image **) NULL);
2029 assert(*image != (Image *) NULL);
2030 assert((*image)->signature == MagickSignature);
2031 if ((*image)->debug != MagickFalse)
2032 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2033 if (GetImageReferenceCount(*image) <= 1)
2035 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2036 LockSemaphoreInfo((*image)->semaphore);
2037 (*image)->reference_count--;
2038 UnlockSemaphoreInfo((*image)->semaphore);
2044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2048 % N e w M a g i c k I m a g e %
2052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2054 % NewMagickImage() creates a blank image canvas of the specified size and
2057 % The format of the NewMagickImage method is:
2059 % Image *NewMagickImage(const ImageInfo *image_info,
2060 % const size_t width,const size_t height,const PixelInfo *background)
2062 % A description of each parameter follows:
2064 % o image: the image.
2066 % o width: the image width.
2068 % o height: the image height.
2070 % o background: the image color.
2073 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2074 const size_t width,const size_t height,const PixelInfo *background)
2091 assert(image_info != (const ImageInfo *) NULL);
2092 if (image_info->debug != MagickFalse)
2093 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2094 assert(image_info->signature == MagickSignature);
2095 assert(background != (const PixelInfo *) NULL);
2096 image=AcquireImage(image_info,exception);
2097 image->columns=width;
2099 image->colorspace=background->colorspace;
2100 image->matte=background->matte;
2101 image->fuzz=background->fuzz;
2102 image->depth=background->depth;
2104 exception=(&image->exception);
2105 image_view=AcquireCacheView(image);
2106 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2107 #pragma omp parallel for schedule(dynamic,4) shared(status)
2109 for (y=0; y < (ssize_t) image->rows; y++)
2117 if (status == MagickFalse)
2119 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2120 if (q == (Quantum *) NULL)
2125 for (x=0; x < (ssize_t) image->columns; x++)
2127 SetPixelPixelInfo(image,background,q);
2128 q+=GetPixelChannels(image);
2130 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2133 image_view=DestroyCacheView(image_view);
2134 if (status == MagickFalse)
2135 image=DestroyImage(image);
2140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2144 % R e f e r e n c e I m a g e %
2148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2150 % ReferenceImage() increments the reference count associated with an image
2151 % returning a pointer to the image.
2153 % The format of the ReferenceImage method is:
2155 % Image *ReferenceImage(Image *image)
2157 % A description of each parameter follows:
2159 % o image: the image.
2162 MagickExport Image *ReferenceImage(Image *image)
2164 assert(image != (Image *) NULL);
2165 if (image->debug != MagickFalse)
2166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2167 assert(image->signature == MagickSignature);
2168 LockSemaphoreInfo(image->semaphore);
2169 image->reference_count++;
2170 UnlockSemaphoreInfo(image->semaphore);
2175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2179 % R e s e t I m a g e P a g e %
2183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2185 % ResetImagePage() resets the image page canvas and position.
2187 % The format of the ResetImagePage method is:
2189 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2191 % A description of each parameter follows:
2193 % o image: the image.
2195 % o page: the relative page specification.
2198 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2206 assert(image != (Image *) NULL);
2207 assert(image->signature == MagickSignature);
2208 if (image->debug != MagickFalse)
2209 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2210 flags=ParseAbsoluteGeometry(page,&geometry);
2211 if ((flags & WidthValue) != 0)
2213 if ((flags & HeightValue) == 0)
2214 geometry.height=geometry.width;
2215 image->page.width=geometry.width;
2216 image->page.height=geometry.height;
2218 if ((flags & AspectValue) != 0)
2220 if ((flags & XValue) != 0)
2221 image->page.x+=geometry.x;
2222 if ((flags & YValue) != 0)
2223 image->page.y+=geometry.y;
2227 if ((flags & XValue) != 0)
2229 image->page.x=geometry.x;
2230 if ((image->page.width == 0) && (geometry.x > 0))
2231 image->page.width=image->columns+geometry.x;
2233 if ((flags & YValue) != 0)
2235 image->page.y=geometry.y;
2236 if ((image->page.height == 0) && (geometry.y > 0))
2237 image->page.height=image->rows+geometry.y;
2244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2248 % S e p a r a t e I m a g e C h a n n e l %
2252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2254 % SeparateImage() separates a channel from the image and returns it as
2255 % a grayscale image. A channel is a particular color component of each pixel
2258 % The format of the SeparateImage method is:
2260 % MagickBooleanType SeparateImage(Image *image)
2262 % A description of each parameter follows:
2264 % o image: the image.
2267 MagickExport MagickBooleanType SeparateImage(Image *image)
2269 #define SeparateImageTag "Separate/Image"
2286 assert(image != (Image *) NULL);
2287 assert(image->signature == MagickSignature);
2288 if (image->debug != MagickFalse)
2289 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2290 exception=(&image->exception);
2291 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2292 return(MagickFalse);
2294 Separate image channels.
2298 image_view=AcquireCacheView(image);
2299 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2300 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2302 for (y=0; y < (ssize_t) image->rows; y++)
2310 if (status == MagickFalse)
2312 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2313 if (q == (Quantum *) NULL)
2318 for (x=0; x < (ssize_t) image->columns; x++)
2323 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2331 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2332 if (traits == UndefinedPixelTrait)
2334 if ((traits & UpdatePixelTrait) != 0)
2335 for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
2338 q+=GetPixelChannels(image);
2340 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2342 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2347 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2348 #pragma omp critical (MagickCore_SeparateImage)
2350 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2351 if (proceed == MagickFalse)
2355 image_view=DestroyCacheView(image_view);
2356 (void) SetImageColorspace(image,RGBColorspace,exception);
2361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2365 % S e p a r a t e I m a g e s %
2369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2371 % SeparateImages() returns a separate grayscale image for each channel
2374 % The format of the SeparateImages method is:
2376 % MagickBooleanType SeparateImages(const Image *image,
2377 % ExceptionInfo *exception)
2379 % A description of each parameter follows:
2381 % o image: the image.
2383 % o exception: return any errors or warnings in this structure.
2386 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2398 assert(image != (Image *) NULL);
2399 assert(image->signature == MagickSignature);
2400 if (image->debug != MagickFalse)
2401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2402 images=NewImageList();
2403 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2408 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2409 if (traits == UndefinedPixelTrait)
2411 if ((traits & UpdatePixelTrait) != 0)
2413 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2414 if (separate_image != (Image *) NULL)
2416 channel_mask=SetPixelChannelMask(separate_image,
2417 (ChannelType) (1 << i));
2418 (void) SeparateImage(separate_image);
2419 (void) SetPixelChannelMap(separate_image,channel_mask);
2420 AppendImageToList(&images,separate_image);
2428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2432 % S e t I m a g e A l p h a C h a n n e l %
2436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2438 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2441 % The format of the SetImageAlphaChannel method is:
2443 % MagickBooleanType SetImageAlphaChannel(Image *image,
2444 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2446 % A description of each parameter follows:
2448 % o image: the image.
2450 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2451 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2452 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2453 % TransparentAlphaChannel.
2455 % o exception: return any errors or warnings in this structure.
2458 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2459 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2467 assert(image != (Image *) NULL);
2468 if (image->debug != MagickFalse)
2469 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2470 assert(image->signature == MagickSignature);
2474 case ActivateAlphaChannel:
2476 image->matte=MagickTrue;
2479 case BackgroundAlphaChannel:
2494 Set transparent pixels to background color.
2496 if (image->matte == MagickFalse)
2498 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2500 GetPixelInfo(image,&background);
2501 SetPixelInfoPacket(image,&image->background_color,&background);
2502 if (image->colorspace == CMYKColorspace)
2503 ConvertRGBToCMYK(&background);
2504 SetPacketPixelInfo(image,&background,&pixel);
2505 image_view=AcquireCacheView(image);
2506 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2507 #pragma omp parallel for schedule(dynamic,4) shared(status)
2509 for (y=0; y < (ssize_t) image->rows; y++)
2517 if (status == MagickFalse)
2519 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2521 if (q == (Quantum *) NULL)
2526 for (x=0; x < (ssize_t) image->columns; x++)
2528 if (GetPixelAlpha(image,q) == TransparentAlpha)
2529 SetPixelPixelInfo(image,&background,q);
2530 q+=GetPixelChannels(image);
2532 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2535 image_view=DestroyCacheView(image_view);
2538 case DeactivateAlphaChannel:
2540 image->matte=MagickFalse;
2543 case ShapeAlphaChannel:
2544 case CopyAlphaChannel:
2547 Special usage case for SeparateImage(): copy grayscale color to
2550 channel_mask=SetPixelChannelMask(image,GrayChannel);
2551 status=SeparateImage(image);
2552 (void) SetPixelChannelMask(image,channel_mask);
2553 image->matte=MagickTrue; /* make sure transparency is now on! */
2554 if (alpha_type == ShapeAlphaChannel)
2560 Reset all color channels to background color.
2562 GetPixelInfo(image,&background);
2563 SetPixelInfoPacket(image,&(image->background_color),&background);
2564 (void) LevelImageColors(image,&background,&background,MagickTrue,
2569 case ExtractAlphaChannel:
2571 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2572 status=SeparateImage(image);
2573 (void) SetPixelChannelMask(image,channel_mask);
2574 image->matte=MagickFalse;
2577 case OpaqueAlphaChannel:
2579 status=SetImageAlpha(image,OpaqueAlpha);
2580 image->matte=MagickTrue;
2583 case TransparentAlphaChannel:
2585 status=SetImageAlpha(image,TransparentAlpha);
2586 image->matte=MagickTrue;
2589 case SetAlphaChannel:
2591 if (image->matte == MagickFalse)
2593 status=SetImageAlpha(image,OpaqueAlpha);
2594 image->matte=MagickTrue;
2598 case UndefinedAlphaChannel:
2601 if (status == MagickFalse)
2603 return(SyncImagePixelCache(image,exception));
2607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2611 % S e t I m a g e B a c k g r o u n d C o l o r %
2615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2617 % SetImageBackgroundColor() initializes the image pixels to the image
2618 % background color. The background color is defined by the background_color
2619 % member of the image structure.
2621 % The format of the SetImage method is:
2623 % MagickBooleanType SetImageBackgroundColor(Image *image)
2625 % A description of each parameter follows:
2627 % o image: the image.
2630 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2650 assert(image != (Image *) NULL);
2651 if (image->debug != MagickFalse)
2652 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2653 assert(image->signature == MagickSignature);
2654 exception=(&image->exception);
2655 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2656 return(MagickFalse);
2657 if (image->background_color.alpha != OpaqueAlpha)
2658 image->matte=MagickTrue;
2659 GetPixelInfo(image,&background);
2660 SetPixelInfoPacket(image,&image->background_color,&background);
2661 if (image->colorspace == CMYKColorspace)
2662 ConvertRGBToCMYK(&background);
2663 SetPacketPixelInfo(image,&background,&pixel);
2665 Set image background color.
2669 image_view=AcquireCacheView(image);
2670 for (y=0; y < (ssize_t) image->rows; y++)
2678 if (status == MagickFalse)
2680 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2681 if (q == (Quantum *) NULL)
2686 for (x=0; x < (ssize_t) image->columns; x++)
2688 SetPixelPixelInfo(image,&background,q);
2689 q+=GetPixelChannels(image);
2691 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2694 image_view=DestroyCacheView(image_view);
2699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2703 % S e t I m a g e C o l o r %
2707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2709 % SetImageColor() set the entire image canvas to the specified color.
2711 % The format of the SetImageColor method is:
2713 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color)
2715 % A description of each parameter follows:
2717 % o image: the image.
2719 % o background: the image color.
2722 MagickExport MagickBooleanType SetImageColor(Image *image,
2723 const PixelInfo *color)
2737 assert(image != (Image *) NULL);
2738 if (image->debug != MagickFalse)
2739 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2740 assert(image->signature == MagickSignature);
2741 assert(color != (const PixelInfo *) NULL);
2742 image->colorspace=color->colorspace;
2743 image->matte=color->matte;
2744 image->fuzz=color->fuzz;
2745 image->depth=color->depth;
2747 exception=(&image->exception);
2748 image_view=AcquireCacheView(image);
2749 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2750 #pragma omp parallel for schedule(dynamic,4) shared(status)
2752 for (y=0; y < (ssize_t) image->rows; y++)
2760 if (status == MagickFalse)
2762 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2763 if (q == (Quantum *) NULL)
2768 for (x=0; x < (ssize_t) image->columns; x++)
2770 SetPixelPixelInfo(image,color,q);
2771 q+=GetPixelChannels(image);
2773 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2776 image_view=DestroyCacheView(image_view);
2781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2785 % S e t I m a g e S t o r a g e C l a s s %
2789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2791 % SetImageStorageClass() sets the image class: DirectClass for true color
2792 % images or PseudoClass for colormapped images.
2794 % The format of the SetImageStorageClass method is:
2796 % MagickBooleanType SetImageStorageClass(Image *image,
2797 % const ClassType storage_class,ExceptionInfo *exception)
2799 % A description of each parameter follows:
2801 % o image: the image.
2803 % o storage_class: The image class.
2805 % o exception: return any errors or warnings in this structure.
2808 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2809 const ClassType storage_class,ExceptionInfo *exception)
2811 image->storage_class=storage_class;
2812 return(SyncImagePixelCache(image,exception));
2816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2820 % S e t I m a g e C l i p M a s k %
2824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2826 % SetImageClipMask() associates a clip path with the image. The clip path
2827 % must be the same dimensions as the image. Set any pixel component of
2828 % the clip path to TransparentAlpha to prevent that corresponding image
2829 % pixel component from being updated when SyncAuthenticPixels() is applied.
2831 % The format of the SetImageClipMask method is:
2833 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2834 % ExceptionInfo *exception)
2836 % A description of each parameter follows:
2838 % o image: the image.
2840 % o clip_mask: the image clip path.
2842 % o exception: return any errors or warnings in this structure.
2845 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2846 const Image *clip_mask,ExceptionInfo *exception)
2848 assert(image != (Image *) NULL);
2849 if (image->debug != MagickFalse)
2850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2851 assert(image->signature == MagickSignature);
2852 if (clip_mask != (const Image *) NULL)
2853 if ((clip_mask->columns != image->columns) ||
2854 (clip_mask->rows != image->rows))
2855 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2856 if (image->clip_mask != (Image *) NULL)
2857 image->clip_mask=DestroyImage(image->clip_mask);
2858 image->clip_mask=NewImageList();
2859 if (clip_mask == (Image *) NULL)
2861 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
2862 return(MagickFalse);
2863 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2864 if (image->clip_mask == (Image *) NULL)
2865 return(MagickFalse);
2870 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2874 % S e t I m a g e E x t e n t %
2878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2880 % SetImageExtent() sets the image size (i.e. columns & rows).
2882 % The format of the SetImageExtent method is:
2884 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2885 % const size_t rows,ExceptionInfo *exception)
2887 % A description of each parameter follows:
2889 % o image: the image.
2891 % o columns: The image width in pixels.
2893 % o rows: The image height in pixels.
2895 % o exception: return any errors or warnings in this structure.
2898 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2899 const size_t rows,ExceptionInfo *exception)
2901 if ((columns == 0) || (rows == 0))
2902 return(MagickFalse);
2903 image->columns=columns;
2905 return(SyncImagePixelCache(image,exception));
2909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2913 + S e t I m a g e I n f o %
2917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2919 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2920 % It is set to a type of image format based on the prefix or suffix of the
2921 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2922 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2923 % precendence over the suffix. Use an optional index enclosed in brackets
2924 % after a file name to specify a desired scene of a multi-resolution image
2925 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2926 % indicates success.
2928 % The format of the SetImageInfo method is:
2930 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2931 % const unsigned int frames,ExceptionInfo *exception)
2933 % A description of each parameter follows:
2935 % o image_info: the image info.
2937 % o frames: the number of images you intend to write.
2939 % o exception: return any errors or warnings in this structure.
2942 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2943 const unsigned int frames,ExceptionInfo *exception)
2946 extension[MaxTextExtent],
2947 filename[MaxTextExtent],
2948 magic[MaxTextExtent],
2950 subimage[MaxTextExtent];
2974 magick[2*MaxTextExtent];
2977 Look for 'image.format' in filename.
2979 assert(image_info != (ImageInfo *) NULL);
2980 assert(image_info->signature == MagickSignature);
2981 if (image_info->debug != MagickFalse)
2982 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2983 image_info->filename);
2987 GetPathComponent(image_info->filename,SubimagePath,subimage);
2988 if (*subimage != '\0')
2991 Look for scene specification (e.g. img0001.pcd[4]).
2993 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2995 if (IsGeometry(subimage) != MagickFalse)
2996 (void) CloneString(&image_info->extract,subimage);
3004 (void) CloneString(&image_info->scenes,subimage);
3005 image_info->scene=StringToUnsignedLong(image_info->scenes);
3006 image_info->number_scenes=image_info->scene;
3007 p=image_info->scenes;
3008 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3010 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3013 first=(size_t) strtol(p,&q,10);
3015 while (isspace((int) ((unsigned char) *q)) != 0)
3018 last=(size_t) strtol(q+1,&q,10);
3021 if (first < image_info->scene)
3022 image_info->scene=first;
3023 if (last > image_info->number_scenes)
3024 image_info->number_scenes=last;
3027 image_info->number_scenes-=image_info->scene-1;
3032 GetPathComponent(image_info->filename,ExtensionPath,extension);
3033 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3034 if (*extension != '\0')
3035 if ((LocaleCompare(extension,"gz") == 0) ||
3036 (LocaleCompare(extension,"Z") == 0) ||
3037 (LocaleCompare(extension,"wmz") == 0))
3040 path[MaxTextExtent];
3042 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3043 path[strlen(path)-strlen(extension)-1]='\0';
3044 GetPathComponent(path,ExtensionPath,extension);
3047 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3048 if (*extension != '\0')
3049 if (LocaleCompare(extension,"bz2") == 0)
3052 path[MaxTextExtent];
3054 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3055 path[strlen(path)-strlen(extension)-1]='\0';
3056 GetPathComponent(path,ExtensionPath,extension);
3059 image_info->affirm=MagickFalse;
3060 sans_exception=AcquireExceptionInfo();
3061 if (*extension != '\0')
3070 *format_type_formats[] =
3093 User specified image format.
3095 (void) CopyMagickString(magic,extension,MaxTextExtent);
3098 Look for explicit image formats.
3100 format_type=UndefinedFormatType;
3102 while ((format_type == UndefinedFormatType) &&
3103 (format_type_formats[i] != (char *) NULL))
3105 if ((*magic == *format_type_formats[i]) &&
3106 (LocaleCompare(magic,format_type_formats[i]) == 0))
3107 format_type=ExplicitFormatType;
3110 magick_info=GetMagickInfo(magic,sans_exception);
3111 if ((magick_info != (const MagickInfo *) NULL) &&
3112 (magick_info->format_type != UndefinedFormatType))
3113 format_type=magick_info->format_type;
3114 if (format_type == UndefinedFormatType)
3115 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3117 if (format_type == ExplicitFormatType)
3119 image_info->affirm=MagickTrue;
3120 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3122 if (LocaleCompare(magic,"RGB") == 0)
3123 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3126 Look for explicit 'format:image' in filename.
3129 GetPathComponent(image_info->filename,MagickPath,magic);
3131 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3135 User specified image format.
3138 if (IsMagickConflict(magic) == MagickFalse)
3140 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3141 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3142 image_info->affirm=MagickTrue;
3144 image_info->temporary=MagickTrue;
3147 magick_info=GetMagickInfo(magic,sans_exception);
3148 sans_exception=DestroyExceptionInfo(sans_exception);
3149 if ((magick_info == (const MagickInfo *) NULL) ||
3150 (GetMagickEndianSupport(magick_info) == MagickFalse))
3151 image_info->endian=UndefinedEndian;
3152 GetPathComponent(image_info->filename,CanonicalPath,filename);
3153 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3154 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3157 Test for multiple image support (e.g. image%02d.png).
3159 (void) InterpretImageFilename(image_info,(Image *) NULL,
3160 image_info->filename,(int) image_info->scene,filename);
3161 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3162 (strchr(filename,'%') == (char *) NULL))
3163 image_info->adjoin=MagickFalse;
3165 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3168 Some image formats do not support multiple frames per file.
3170 magick_info=GetMagickInfo(magic,exception);
3171 if (magick_info != (const MagickInfo *) NULL)
3172 if (GetMagickAdjoin(magick_info) == MagickFalse)
3173 image_info->adjoin=MagickFalse;
3175 if (image_info->affirm != MagickFalse)
3180 Determine the image format from the first few bytes of the file.
3182 image=AcquireImage(image_info,exception);
3183 (void) CopyMagickString(image->filename,image_info->filename,
3185 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3186 if (status == MagickFalse)
3188 image=DestroyImage(image);
3189 return(MagickFalse);
3191 if ((IsBlobSeekable(image) == MagickFalse) ||
3192 (IsBlobExempt(image) != MagickFalse))
3195 Copy standard input or pipe to temporary file.
3198 status=ImageToFile(image,filename,exception);
3199 (void) CloseBlob(image);
3200 if (status == MagickFalse)
3202 image=DestroyImage(image);
3203 return(MagickFalse);
3205 SetImageInfoFile(image_info,(FILE *) NULL);
3206 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3207 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3208 if (status == MagickFalse)
3210 image=DestroyImage(image);
3211 return(MagickFalse);
3213 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3214 image_info->temporary=MagickTrue;
3216 (void) ResetMagickMemory(magick,0,sizeof(magick));
3217 count=ReadBlob(image,2*MaxTextExtent,magick);
3218 (void) CloseBlob(image);
3219 image=DestroyImage(image);
3221 Check magic.xml configuration file.
3223 sans_exception=AcquireExceptionInfo();
3224 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3225 if ((magic_info != (const MagicInfo *) NULL) &&
3226 (GetMagicName(magic_info) != (char *) NULL))
3228 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3230 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3231 if ((magick_info == (const MagickInfo *) NULL) ||
3232 (GetMagickEndianSupport(magick_info) == MagickFalse))
3233 image_info->endian=UndefinedEndian;
3234 sans_exception=DestroyExceptionInfo(sans_exception);
3237 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3238 if ((magick_info == (const MagickInfo *) NULL) ||
3239 (GetMagickEndianSupport(magick_info) == MagickFalse))
3240 image_info->endian=UndefinedEndian;
3241 sans_exception=DestroyExceptionInfo(sans_exception);
3247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3251 % S e t I m a g e I n f o B l o b %
3255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3257 % SetImageInfoBlob() sets the image info blob member.
3259 % The format of the SetImageInfoBlob method is:
3261 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3262 % const size_t length)
3264 % A description of each parameter follows:
3266 % o image_info: the image info.
3270 % o length: the blob length.
3273 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3274 const size_t length)
3276 assert(image_info != (ImageInfo *) NULL);
3277 assert(image_info->signature == MagickSignature);
3278 if (image_info->debug != MagickFalse)
3279 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3280 image_info->filename);
3281 image_info->blob=(void *) blob;
3282 image_info->length=length;
3286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3290 % S e t I m a g e I n f o F i l e %
3294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3296 % SetImageInfoFile() sets the image info file member.
3298 % The format of the SetImageInfoFile method is:
3300 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3302 % A description of each parameter follows:
3304 % o image_info: the image info.
3309 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3311 assert(image_info != (ImageInfo *) NULL);
3312 assert(image_info->signature == MagickSignature);
3313 if (image_info->debug != MagickFalse)
3314 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3315 image_info->filename);
3316 image_info->file=file;
3320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3324 % S e t I m a g e M a s k %
3328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3330 % SetImageMask() associates a mask with the image. The mask must be the same
3331 % dimensions as the image.
3333 % The format of the SetImageMask method is:
3335 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3336 % ExceptionInfo *exception)
3338 % A description of each parameter follows:
3340 % o image: the image.
3342 % o mask: the image mask.
3344 % o exception: return any errors or warnings in this structure.
3347 MagickExport MagickBooleanType SetImageMask(Image *image,
3348 const Image *mask,ExceptionInfo *exception)
3350 assert(image != (Image *) NULL);
3351 if (image->debug != MagickFalse)
3352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3353 assert(image->signature == MagickSignature);
3354 if (mask != (const Image *) NULL)
3355 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3356 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3357 if (image->mask != (Image *) NULL)
3358 image->mask=DestroyImage(image->mask);
3359 image->mask=NewImageList();
3360 if (mask == (Image *) NULL)
3362 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
3363 return(MagickFalse);
3364 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3365 if (image->mask == (Image *) NULL)
3366 return(MagickFalse);
3371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3375 % S e t I m a g e A l p h a %
3379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3381 % SetImageAlphs() sets the alpha levels of the image.
3383 % The format of the SetImageAlpha method is:
3385 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha)
3387 % A description of each parameter follows:
3389 % o image: the image.
3391 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3392 % fully transparent.
3395 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha)
3409 assert(image != (Image *) NULL);
3410 if (image->debug != MagickFalse)
3411 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3412 assert(image->signature == MagickSignature);
3413 image->matte=alpha != OpaqueAlpha ? MagickTrue : MagickFalse;
3415 exception=(&image->exception);
3416 image_view=AcquireCacheView(image);
3417 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3418 #pragma omp parallel for schedule(dynamic,4) shared(status)
3420 for (y=0; y < (ssize_t) image->rows; y++)
3428 if (status == MagickFalse)
3430 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3431 if (q == (Quantum *) NULL)
3436 for (x=0; x < (ssize_t) image->columns; x++)
3438 SetPixelAlpha(image,alpha,q);
3439 q+=GetPixelChannels(image);
3441 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3444 image_view=DestroyCacheView(image_view);
3449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3453 % S e t I m a g e T y p e %
3457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3459 % SetImageType() sets the type of image. Choose from these types:
3461 % Bilevel Grayscale GrayscaleMatte
3462 % Palette PaletteMatte TrueColor
3463 % TrueColorMatte ColorSeparation ColorSeparationMatte
3466 % The format of the SetImageType method is:
3468 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3469 % ExceptionInfo *exception)
3471 % A description of each parameter follows:
3473 % o image: the image.
3475 % o type: Image type.
3477 % o exception: return any errors or warnings in this structure.
3480 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3481 ExceptionInfo *exception)
3495 assert(image != (Image *) NULL);
3496 if (image->debug != MagickFalse)
3497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3498 assert(image->signature == MagickSignature);
3500 image_info=AcquireImageInfo();
3501 image_info->dither=image->dither;
3502 artifact=GetImageArtifact(image,"dither");
3503 if (artifact != (const char *) NULL)
3504 (void) SetImageOption(image_info,"dither",artifact);
3509 if (IsImageGray(image,&image->exception) == MagickFalse)
3510 status=TransformImageColorspace(image,GRAYColorspace);
3511 if (IsImageMonochrome(image,&image->exception) == MagickFalse)
3513 quantize_info=AcquireQuantizeInfo(image_info);
3514 quantize_info->number_colors=2;
3515 quantize_info->colorspace=GRAYColorspace;
3516 status=QuantizeImage(quantize_info,image,exception);
3517 quantize_info=DestroyQuantizeInfo(quantize_info);
3519 image->matte=MagickFalse;
3524 if (IsImageGray(image,&image->exception) == MagickFalse)
3525 status=TransformImageColorspace(image,GRAYColorspace);
3526 image->matte=MagickFalse;
3529 case GrayscaleMatteType:
3531 if (IsImageGray(image,&image->exception) == MagickFalse)
3532 status=TransformImageColorspace(image,GRAYColorspace);
3533 if (image->matte == MagickFalse)
3534 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3539 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3540 status=TransformImageColorspace(image,RGBColorspace);
3541 if ((image->storage_class == DirectClass) || (image->colors > 256))
3543 quantize_info=AcquireQuantizeInfo(image_info);
3544 quantize_info->number_colors=256;
3545 status=QuantizeImage(quantize_info,image,exception);
3546 quantize_info=DestroyQuantizeInfo(quantize_info);
3548 image->matte=MagickFalse;
3551 case PaletteBilevelMatteType:
3556 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3557 status=TransformImageColorspace(image,RGBColorspace);
3558 if (image->matte == MagickFalse)
3559 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3560 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3561 (void) BilevelImage(image,(double) QuantumRange/2.0);
3562 (void) SetPixelChannelMask(image,channel_mask);
3563 quantize_info=AcquireQuantizeInfo(image_info);
3564 status=QuantizeImage(quantize_info,image,exception);
3565 quantize_info=DestroyQuantizeInfo(quantize_info);
3568 case PaletteMatteType:
3570 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3571 status=TransformImageColorspace(image,RGBColorspace);
3572 if (image->matte == MagickFalse)
3573 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3574 quantize_info=AcquireQuantizeInfo(image_info);
3575 quantize_info->colorspace=TransparentColorspace;
3576 status=QuantizeImage(quantize_info,image,exception);
3577 quantize_info=DestroyQuantizeInfo(quantize_info);
3582 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3583 status=TransformImageColorspace(image,RGBColorspace);
3584 if (image->storage_class != DirectClass)
3585 status=SetImageStorageClass(image,DirectClass,&image->exception);
3586 image->matte=MagickFalse;
3589 case TrueColorMatteType:
3591 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3592 status=TransformImageColorspace(image,RGBColorspace);
3593 if (image->storage_class != DirectClass)
3594 status=SetImageStorageClass(image,DirectClass,&image->exception);
3595 if (image->matte == MagickFalse)
3596 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3599 case ColorSeparationType:
3601 if (image->colorspace != CMYKColorspace)
3603 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3604 status=TransformImageColorspace(image,RGBColorspace);
3605 status=TransformImageColorspace(image,CMYKColorspace);
3607 if (image->storage_class != DirectClass)
3608 status=SetImageStorageClass(image,DirectClass,&image->exception);
3609 image->matte=MagickFalse;
3612 case ColorSeparationMatteType:
3614 if (image->colorspace != CMYKColorspace)
3616 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3617 status=TransformImageColorspace(image,RGBColorspace);
3618 status=TransformImageColorspace(image,CMYKColorspace);
3620 if (image->storage_class != DirectClass)
3621 status=SetImageStorageClass(image,DirectClass,&image->exception);
3622 if (image->matte == MagickFalse)
3623 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3631 image_info=DestroyImageInfo(image_info);
3636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3640 % 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 %
3644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3646 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3647 % image and returns the previous setting. A virtual pixel is any pixel access
3648 % that is outside the boundaries of the image cache.
3650 % The format of the SetImageVirtualPixelMethod() method is:
3652 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3653 % const VirtualPixelMethod virtual_pixel_method)
3655 % A description of each parameter follows:
3657 % o image: the image.
3659 % o virtual_pixel_method: choose the type of virtual pixel.
3662 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3663 const VirtualPixelMethod virtual_pixel_method)
3665 assert(image != (const Image *) NULL);
3666 assert(image->signature == MagickSignature);
3667 if (image->debug != MagickFalse)
3668 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3669 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3677 % S m u s h I m a g e s %
3681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3683 % SmushImages() takes all images from the current image pointer to the end
3684 % of the image list and smushes them to each other top-to-bottom if the
3685 % stack parameter is true, otherwise left-to-right.
3687 % The current gravity setting now effects how the image is justified in the
3690 % The format of the SmushImages method is:
3692 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3693 % ExceptionInfo *exception)
3695 % A description of each parameter follows:
3697 % o images: the image sequence.
3699 % o stack: A value other than 0 stacks the images top-to-bottom.
3701 % o offset: minimum distance in pixels between images.
3703 % o exception: return any errors or warnings in this structure.
3707 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3708 const ssize_t offset,ExceptionInfo *exception)
3722 register const Quantum
3735 if (images->previous == (Image *) NULL)
3738 SetGeometry(smush_image,&right_geometry);
3739 GravityAdjustGeometry(right_image->columns,right_image->rows,
3740 right_image->gravity,&right_geometry);
3741 left_image=images->previous;
3742 SetGeometry(smush_image,&left_geometry);
3743 GravityAdjustGeometry(left_image->columns,left_image->rows,
3744 left_image->gravity,&left_geometry);
3745 gap=right_image->columns;
3746 left_view=AcquireCacheView(left_image);
3747 right_view=AcquireCacheView(right_image);
3748 for (y=0; y < (ssize_t) smush_image->rows; y++)
3750 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3752 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3753 if ((p == (const Quantum *) NULL) ||
3754 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3755 ((left_image->columns-x-1) >= gap))
3758 i=(ssize_t) left_image->columns-x-1;
3759 for (x=0; x < (ssize_t) right_image->columns; x++)
3761 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3763 if ((p == (const Quantum *) NULL) ||
3764 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3765 ((x+i) >= (ssize_t) gap))
3768 if ((x+i) < (ssize_t) gap)
3771 right_view=DestroyCacheView(right_view);
3772 left_view=DestroyCacheView(left_view);
3773 if (y < (ssize_t) smush_image->rows)
3775 return((ssize_t) gap-offset);
3778 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3779 const ssize_t offset,ExceptionInfo *exception)
3793 register const Quantum
3806 if (images->previous == (Image *) NULL)
3808 bottom_image=images;
3809 SetGeometry(smush_image,&bottom_geometry);
3810 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3811 bottom_image->gravity,&bottom_geometry);
3812 top_image=images->previous;
3813 SetGeometry(smush_image,&top_geometry);
3814 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3816 gap=bottom_image->rows;
3817 top_view=AcquireCacheView(top_image);
3818 bottom_view=AcquireCacheView(bottom_image);
3819 for (x=0; x < (ssize_t) smush_image->columns; x++)
3821 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3823 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3824 if ((p == (const Quantum *) NULL) ||
3825 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3826 ((top_image->rows-y-1) >= gap))
3829 i=(ssize_t) top_image->rows-y-1;
3830 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3832 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3834 if ((p == (const Quantum *) NULL) ||
3835 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3836 ((y+i) >= (ssize_t) gap))
3839 if ((y+i) < (ssize_t) gap)
3842 bottom_view=DestroyCacheView(bottom_view);
3843 top_view=DestroyCacheView(top_view);
3844 if (x < (ssize_t) smush_image->columns)
3846 return((ssize_t) gap-offset);
3849 MagickExport Image *SmushImages(const Image *images,
3850 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3852 #define SmushImageTag "Smush/Image"
3874 register const Image
3887 Compute maximum area of smushed area.
3889 assert(images != (Image *) NULL);
3890 assert(images->signature == MagickSignature);
3891 if (images->debug != MagickFalse)
3892 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3893 assert(exception != (ExceptionInfo *) NULL);
3894 assert(exception->signature == MagickSignature);
3898 width=image->columns;
3900 next=GetNextImageInList(image);
3901 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3903 if (next->matte != MagickFalse)
3906 if (stack != MagickFalse)
3908 if (next->columns > width)
3909 width=next->columns;
3911 if (next->previous != (Image *) NULL)
3915 width+=next->columns;
3916 if (next->previous != (Image *) NULL)
3918 if (next->rows > height)
3924 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3925 if (smush_image == (Image *) NULL)
3926 return((Image *) NULL);
3927 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3929 smush_image=DestroyImage(smush_image);
3930 return((Image *) NULL);
3932 smush_image->matte=matte;
3933 (void) SetImageBackgroundColor(smush_image);
3937 smush_view=AcquireCacheView(smush_image);
3938 for (n=0; n < (MagickOffsetType) number_images; n++)
3940 SetGeometry(smush_image,&geometry);
3941 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3942 if (stack != MagickFalse)
3944 x_offset-=geometry.x;
3945 y_offset-=SmushYGap(smush_image,image,offset,exception);
3949 x_offset-=SmushXGap(smush_image,image,offset,exception);
3950 y_offset-=geometry.y;
3952 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
3953 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3954 if (proceed == MagickFalse)
3956 if (stack == MagickFalse)
3958 x_offset+=(ssize_t) image->columns;
3964 y_offset+=(ssize_t) image->rows;
3966 image=GetNextImageInList(image);
3968 if (stack == MagickFalse)
3969 smush_image->columns=(size_t) x_offset;
3971 smush_image->rows=(size_t) y_offset;
3972 smush_view=DestroyCacheView(smush_view);
3973 if (status == MagickFalse)
3974 smush_image=DestroyImage(smush_image);
3975 return(smush_image);
3979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3983 % S t r i p I m a g e %
3987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3989 % StripImage() strips an image of all profiles and comments.
3991 % The format of the StripImage method is:
3993 % MagickBooleanType StripImage(Image *image)
3995 % A description of each parameter follows:
3997 % o image: the image.
4000 MagickExport MagickBooleanType StripImage(Image *image)
4002 assert(image != (Image *) NULL);
4003 if (image->debug != MagickFalse)
4004 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4005 DestroyImageProfiles(image);
4006 (void) DeleteImageProperty(image,"comment");
4007 (void) DeleteImageProperty(image,"date:create");
4008 (void) DeleteImageProperty(image,"date:modify");
4009 (void) SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4018 + S y n c I m a g e %
4022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4024 % SyncImage() initializes the red, green, and blue intensities of each pixel
4025 % as defined by the colormap index.
4027 % The format of the SyncImage method is:
4029 % MagickBooleanType SyncImage(Image *image)
4031 % A description of each parameter follows:
4033 % o image: the image.
4037 static inline Quantum PushColormapIndex(Image *image,
4038 const size_t index,MagickBooleanType *range_exception)
4040 if (index < image->colors)
4041 return((Quantum) index);
4042 *range_exception=MagickTrue;
4043 return((Quantum) 0);
4046 MagickExport MagickBooleanType SyncImage(Image *image)
4061 assert(image != (Image *) NULL);
4062 if (image->debug != MagickFalse)
4063 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4064 assert(image->signature == MagickSignature);
4065 if (image->storage_class == DirectClass)
4066 return(MagickFalse);
4067 range_exception=MagickFalse;
4069 exception=(&image->exception);
4070 image_view=AcquireCacheView(image);
4071 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4072 #pragma omp parallel for schedule(dynamic,4) shared(status)
4074 for (y=0; y < (ssize_t) image->rows; y++)
4085 if (status == MagickFalse)
4087 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4088 if (q == (Quantum *) NULL)
4093 for (x=0; x < (ssize_t) image->columns; x++)
4095 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4097 SetPixelPacket(image,image->colormap+(ssize_t) index,q);
4098 q+=GetPixelChannels(image);
4100 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4103 image_view=DestroyCacheView(image_view);
4104 if (range_exception != MagickFalse)
4105 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4106 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4115 % S y n c I m a g e S e t t i n g s %
4119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4121 % SyncImageSettings() sync the image info options to the image.
4123 % The format of the SyncImageSettings method is:
4125 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4127 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4130 % A description of each parameter follows:
4132 % o image_info: the image info.
4134 % o image: the image.
4138 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4144 assert(image_info != (const ImageInfo *) NULL);
4145 assert(image_info->signature == MagickSignature);
4146 assert(images != (Image *) NULL);
4147 assert(images->signature == MagickSignature);
4148 if (images->debug != MagickFalse)
4149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4151 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4152 (void) SyncImageSettings(image_info,image);
4153 (void) DeleteImageOption(image_info,"page");
4157 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4161 property[MaxTextExtent];
4179 assert(image_info != (const ImageInfo *) NULL);
4180 assert(image_info->signature == MagickSignature);
4181 assert(image != (Image *) NULL);
4182 assert(image->signature == MagickSignature);
4183 if (image->debug != MagickFalse)
4184 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4185 option=GetImageOption(image_info,"background");
4186 if (option != (const char *) NULL)
4187 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4189 option=GetImageOption(image_info,"bias");
4190 if (option != (const char *) NULL)
4191 image->bias=SiPrefixToDouble(option,QuantumRange);
4192 option=GetImageOption(image_info,"black-point-compensation");
4193 if (option != (const char *) NULL)
4194 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4195 MagickBooleanOptions,MagickFalse,option);
4196 option=GetImageOption(image_info,"blue-primary");
4197 if (option != (const char *) NULL)
4199 flags=ParseGeometry(option,&geometry_info);
4200 image->chromaticity.blue_primary.x=geometry_info.rho;
4201 image->chromaticity.blue_primary.y=geometry_info.sigma;
4202 if ((flags & SigmaValue) == 0)
4203 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4205 option=GetImageOption(image_info,"bordercolor");
4206 if (option != (const char *) NULL)
4207 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4209 option=GetImageOption(image_info,"colors");
4210 if (option != (const char *) NULL)
4211 image->colors=StringToUnsignedLong(option);
4212 option=GetImageOption(image_info,"compose");
4213 if (option != (const char *) NULL)
4214 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4215 MagickFalse,option);
4216 option=GetImageOption(image_info,"compress");
4217 if (option != (const char *) NULL)
4218 image->compression=(CompressionType) ParseCommandOption(
4219 MagickCompressOptions,MagickFalse,option);
4220 option=GetImageOption(image_info,"debug");
4221 if (option != (const char *) NULL)
4222 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4223 MagickFalse,option);
4224 option=GetImageOption(image_info,"density");
4225 if (option != (const char *) NULL)
4233 flags=ParseGeometry(option,&geometry_info);
4234 image->x_resolution=geometry_info.rho;
4235 image->y_resolution=geometry_info.sigma;
4236 if ((flags & SigmaValue) == 0)
4237 image->y_resolution=image->x_resolution;
4239 option=GetImageOption(image_info,"depth");
4240 if (option != (const char *) NULL)
4241 image->depth=StringToUnsignedLong(option);
4242 option=GetImageOption(image_info,"endian");
4243 if (option != (const char *) NULL)
4244 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4245 MagickFalse,option);
4246 option=GetImageOption(image_info,"filter");
4247 if (option != (const char *) NULL)
4248 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4249 MagickFalse,option);
4250 option=GetImageOption(image_info,"fuzz");
4251 if (option != (const char *) NULL)
4252 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4253 option=GetImageOption(image_info,"gravity");
4254 if (option != (const char *) NULL)
4255 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4256 MagickFalse,option);
4257 option=GetImageOption(image_info,"green-primary");
4258 if (option != (const char *) NULL)
4260 flags=ParseGeometry(option,&geometry_info);
4261 image->chromaticity.green_primary.x=geometry_info.rho;
4262 image->chromaticity.green_primary.y=geometry_info.sigma;
4263 if ((flags & SigmaValue) == 0)
4264 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4266 option=GetImageOption(image_info,"intent");
4267 if (option != (const char *) NULL)
4268 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4269 MagickIntentOptions,MagickFalse,option);
4270 option=GetImageOption(image_info,"interlace");
4271 if (option != (const char *) NULL)
4272 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4273 MagickFalse,option);
4274 option=GetImageOption(image_info,"interpolate");
4275 if (option != (const char *) NULL)
4276 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4277 MagickInterpolateOptions,MagickFalse,option);
4278 option=GetImageOption(image_info,"loop");
4279 if (option != (const char *) NULL)
4280 image->iterations=StringToUnsignedLong(option);
4281 option=GetImageOption(image_info,"mattecolor");
4282 if (option != (const char *) NULL)
4283 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4285 option=GetImageOption(image_info,"orient");
4286 if (option != (const char *) NULL)
4287 image->orientation=(OrientationType) ParseCommandOption(
4288 MagickOrientationOptions,MagickFalse,option);
4289 option=GetImageOption(image_info,"page");
4290 if (option != (const char *) NULL)
4295 geometry=GetPageGeometry(option);
4296 flags=ParseAbsoluteGeometry(geometry,&image->page);
4297 geometry=DestroyString(geometry);
4299 option=GetImageOption(image_info,"quality");
4300 if (option != (const char *) NULL)
4301 image->quality=StringToUnsignedLong(option);
4302 option=GetImageOption(image_info,"red-primary");
4303 if (option != (const char *) NULL)
4305 flags=ParseGeometry(option,&geometry_info);
4306 image->chromaticity.red_primary.x=geometry_info.rho;
4307 image->chromaticity.red_primary.y=geometry_info.sigma;
4308 if ((flags & SigmaValue) == 0)
4309 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4311 if (image_info->quality != UndefinedCompressionQuality)
4312 image->quality=image_info->quality;
4313 option=GetImageOption(image_info,"scene");
4314 if (option != (const char *) NULL)
4315 image->scene=StringToUnsignedLong(option);
4316 option=GetImageOption(image_info,"taint");
4317 if (option != (const char *) NULL)
4318 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4319 MagickFalse,option);
4320 option=GetImageOption(image_info,"tile-offset");
4321 if (option != (const char *) NULL)
4326 geometry=GetPageGeometry(option);
4327 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4328 geometry=DestroyString(geometry);
4330 option=GetImageOption(image_info,"transparent-color");
4331 if (option != (const char *) NULL)
4332 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4334 option=GetImageOption(image_info,"type");
4335 if (option != (const char *) NULL)
4336 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4338 option=GetImageOption(image_info,"units");
4339 if (option != (const char *) NULL)
4340 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4341 MagickFalse,option);
4343 units = image_info->units;
4344 if (units != UndefinedResolution)
4346 if (image->units != units)
4347 switch (image->units)
4349 case PixelsPerInchResolution:
4351 if (units == PixelsPerCentimeterResolution)
4353 image->x_resolution/=2.54;
4354 image->y_resolution/=2.54;
4358 case PixelsPerCentimeterResolution:
4360 if (units == PixelsPerInchResolution)
4362 image->x_resolution=(double) ((size_t) (100.0*2.54*
4363 image->x_resolution+0.5))/100.0;
4364 image->y_resolution=(double) ((size_t) (100.0*2.54*
4365 image->y_resolution+0.5))/100.0;
4374 option=GetImageOption(image_info,"white-point");
4375 if (option != (const char *) NULL)
4377 flags=ParseGeometry(option,&geometry_info);
4378 image->chromaticity.white_point.x=geometry_info.rho;
4379 image->chromaticity.white_point.y=geometry_info.sigma;
4380 if ((flags & SigmaValue) == 0)
4381 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4383 ResetImageOptionIterator(image_info);
4384 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4386 value=GetImageOption(image_info,option);
4387 if (value != (const char *) NULL)
4389 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4390 (void) SetImageArtifact(image,property,value);
4392 option=GetNextImageOption(image_info);