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 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
181 &image->background_color,exception);
182 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
184 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
186 (void) QueryColorCompliance(TransparentColor,AllCompliance,
187 &image->transparent_color,exception);
188 image->x_resolution=DefaultResolution;
189 image->y_resolution=DefaultResolution;
190 image->units=PixelsPerInchResolution;
191 GetTimerInfo(&image->timer);
192 image->ping=MagickFalse;
193 image->cache=AcquirePixelCache(0);
194 image->channel_mask=DefaultChannels;
195 image->channel_map=AcquirePixelChannelMap();
196 image->blob=CloneBlobInfo((BlobInfo *) NULL);
197 image->debug=IsEventLogging();
198 image->reference_count=1;
199 image->semaphore=AllocateSemaphoreInfo();
200 image->signature=MagickSignature;
201 if (image_info == (ImageInfo *) NULL)
206 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
208 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
209 (void) CopyMagickString(image->magick_filename,image_info->filename,
211 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
212 if (image_info->size != (char *) NULL)
214 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
215 image->columns=image->extract_info.width;
216 image->rows=image->extract_info.height;
217 image->offset=image->extract_info.x;
218 image->extract_info.x=0;
219 image->extract_info.y=0;
221 if (image_info->extract != (char *) NULL)
226 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
227 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
229 image->extract_info=geometry;
230 Swap(image->columns,image->extract_info.width);
231 Swap(image->rows,image->extract_info.height);
234 image->compression=image_info->compression;
235 image->quality=image_info->quality;
236 image->endian=image_info->endian;
237 image->interlace=image_info->interlace;
238 image->units=image_info->units;
239 if (image_info->density != (char *) NULL)
244 flags=ParseGeometry(image_info->density,&geometry_info);
245 image->x_resolution=geometry_info.rho;
246 image->y_resolution=geometry_info.sigma;
247 if ((flags & SigmaValue) == 0)
248 image->y_resolution=image->x_resolution;
250 if (image_info->page != (char *) NULL)
255 image->page=image->extract_info;
256 geometry=GetPageGeometry(image_info->page);
257 (void) ParseAbsoluteGeometry(geometry,&image->page);
258 geometry=DestroyString(geometry);
260 if (image_info->depth != 0)
261 image->depth=image_info->depth;
262 image->dither=image_info->dither;
263 image->background_color=image_info->background_color;
264 image->border_color=image_info->border_color;
265 image->matte_color=image_info->matte_color;
266 image->transparent_color=image_info->transparent_color;
267 image->ping=image_info->ping;
268 image->progress_monitor=image_info->progress_monitor;
269 image->client_data=image_info->client_data;
270 if (image_info->cache != (void *) NULL)
271 ClonePixelCacheMethods(image->cache,image_info->cache);
272 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
273 (void) SyncImageSettings(image_info,image,exception);
274 option=GetImageOption(image_info,"delay");
275 if (option != (const char *) NULL)
280 flags=ParseGeometry(option,&geometry_info);
281 if ((flags & GreaterValue) != 0)
283 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
284 image->delay=(size_t) floor(geometry_info.rho+0.5);
287 if ((flags & LessValue) != 0)
289 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
290 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
293 image->delay=(size_t) floor(geometry_info.rho+0.5);
294 if ((flags & SigmaValue) != 0)
295 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
297 option=GetImageOption(image_info,"dispose");
298 if (option != (const char *) NULL)
299 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % A c q u i r e I m a g e I n f o %
313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 % AcquireImageInfo() allocates the ImageInfo structure.
317 % The format of the AcquireImageInfo method is:
319 % ImageInfo *AcquireImageInfo(void)
322 MagickExport ImageInfo *AcquireImageInfo(void)
327 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
328 if (image_info == (ImageInfo *) NULL)
329 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
330 GetImageInfo(image_info);
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 % A c q u i r e N e x t I m a g e %
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 % AcquireNextImage() initializes the next image in a sequence to
346 % default values. The next member of image points to the newly allocated
347 % image. If there is a memory shortage, next is assigned NULL.
349 % The format of the AcquireNextImage method is:
351 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
352 % ExceptionInfo *exception)
354 % A description of each parameter follows:
356 % o image_info: Many of the image default values are set from this
357 % structure. For example, filename, compression, depth, background color,
360 % o image: the image.
362 % o exception: return any errors or warnings in this structure.
365 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
366 ExceptionInfo *exception)
369 Allocate image structure.
371 assert(image != (Image *) NULL);
372 assert(image->signature == MagickSignature);
373 if (image->debug != MagickFalse)
374 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
375 image->next=AcquireImage(image_info,exception);
376 if (GetNextImageInList(image) == (Image *) NULL)
378 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
380 if (image_info != (ImageInfo *) NULL)
381 (void) CopyMagickString(GetNextImageInList(image)->filename,
382 image_info->filename,MaxTextExtent);
383 DestroyBlob(GetNextImageInList(image));
384 image->next->blob=ReferenceBlob(image->blob);
385 image->next->endian=image->endian;
386 image->next->scene=image->scene+1;
387 image->next->previous=image;
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 % A p p e n d I m a g e s %
399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 % AppendImages() takes all images from the current image pointer to the end
402 % of the image list and appends them to each other top-to-bottom if the
403 % stack parameter is true, otherwise left-to-right.
405 % The current gravity setting now effects how the image is justified in the
408 % The format of the AppendImages method is:
410 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
411 % ExceptionInfo *exception)
413 % A description of each parameter follows:
415 % o images: the image sequence.
417 % o stack: A value other than 0 stacks the images top-to-bottom.
419 % o exception: return any errors or warnings in this structure.
422 MagickExport Image *AppendImages(const Image *images,
423 const MagickBooleanType stack,ExceptionInfo *exception)
425 #define AppendImageTag "Append/Image"
462 Compute maximum area of appended area.
464 assert(images != (Image *) NULL);
465 assert(images->signature == MagickSignature);
466 if (images->debug != MagickFalse)
467 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
468 assert(exception != (ExceptionInfo *) NULL);
469 assert(exception->signature == MagickSignature);
473 width=image->columns;
475 next=GetNextImageInList(image);
476 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
478 if (next->matte != MagickFalse)
481 if (stack != MagickFalse)
483 if (next->columns > width)
488 width+=next->columns;
489 if (next->rows > height)
495 append_image=CloneImage(image,width,height,MagickTrue,exception);
496 if (append_image == (Image *) NULL)
497 return((Image *) NULL);
498 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
500 append_image=DestroyImage(append_image);
501 return((Image *) NULL);
503 append_image->matte=matte;
504 (void) SetImageBackgroundColor(append_image,exception);
508 append_view=AcquireCacheView(append_image);
509 for (n=0; n < (MagickOffsetType) number_images; n++)
511 SetGeometry(append_image,&geometry);
512 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
513 if (stack != MagickFalse)
514 x_offset-=geometry.x;
516 y_offset-=geometry.y;
517 image_view=AcquireCacheView(image);
518 #if defined(MAGICKCORE_OPENMP_SUPPORT)
519 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
521 for (y=0; y < (ssize_t) image->rows; y++)
526 register const Quantum
535 if (status == MagickFalse)
537 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
538 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
539 image->columns,1,exception);
540 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
545 for (x=0; x < (ssize_t) image->columns; x++)
550 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
559 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
560 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
561 append_traits=GetPixelChannelMapTraits(append_image,channel);
562 if ((traits == UndefinedPixelTrait) ||
563 (append_traits == UndefinedPixelTrait))
565 SetPixelChannel(append_image,channel,p[i],q);
567 p+=GetPixelChannels(image);
568 q+=GetPixelChannels(append_image);
570 sync=SyncCacheViewAuthenticPixels(append_view,exception);
571 if (sync == MagickFalse)
574 image_view=DestroyCacheView(image_view);
575 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
576 if (proceed == MagickFalse)
578 if (stack == MagickFalse)
580 x_offset+=(ssize_t) image->columns;
586 y_offset+=(ssize_t) image->rows;
588 image=GetNextImageInList(image);
590 append_view=DestroyCacheView(append_view);
591 if (status == MagickFalse)
592 append_image=DestroyImage(append_image);
593 return(append_image);
597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 % C a t c h I m a g e E x c e p t i o n %
605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607 % CatchImageException() returns if no exceptions are found in the image
608 % sequence, otherwise it determines the most severe exception and reports
609 % it as a warning or error depending on the severity.
611 % The format of the CatchImageException method is:
613 % ExceptionType CatchImageException(Image *image)
615 % A description of each parameter follows:
617 % o image: An image sequence.
620 MagickExport ExceptionType CatchImageException(Image *image)
628 assert(image != (const Image *) NULL);
629 assert(image->signature == MagickSignature);
630 if (image->debug != MagickFalse)
631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
632 exception=AcquireExceptionInfo();
633 CatchException(exception);
634 severity=exception->severity;
635 exception=DestroyExceptionInfo(exception);
640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
644 % C l i p I m a g e P a t h %
648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650 % ClipImagePath() sets the image clip mask based any clipping path information
653 % The format of the ClipImagePath method is:
655 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
656 % const MagickBooleanType inside,ExceptionInfo *exception)
658 % A description of each parameter follows:
660 % o image: the image.
662 % o pathname: name of clipping path resource. If name is preceded by #, use
663 % clipping path numbered by name.
665 % o inside: if non-zero, later operations take effect inside clipping path.
666 % Otherwise later operations take effect outside clipping path.
668 % o exception: return any errors or warnings in this structure.
672 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
674 return(ClipImagePath(image,"#1",MagickTrue,exception));
677 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
678 const MagickBooleanType inside,ExceptionInfo *exception)
680 #define ClipImagePathTag "ClipPath/Image"
694 assert(image != (const Image *) NULL);
695 assert(image->signature == MagickSignature);
696 if (image->debug != MagickFalse)
697 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
698 assert(pathname != NULL);
699 property=AcquireString(pathname);
700 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
702 value=GetImageProperty(image,property,exception);
703 property=DestroyString(property);
704 if (value == (const char *) NULL)
706 ThrowFileException(exception,OptionError,"NoClipPathDefined",
710 image_info=AcquireImageInfo();
711 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
712 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
713 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
714 image_info=DestroyImageInfo(image_info);
715 if (clip_mask == (Image *) NULL)
717 if (clip_mask->storage_class == PseudoClass)
719 (void) SyncImage(clip_mask,exception);
720 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
723 if (inside == MagickFalse)
724 (void) NegateImage(clip_mask,MagickFalse,exception);
725 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
726 "8BIM:1999,2998:%s\nPS",pathname);
727 (void) SetImageClipMask(image,clip_mask,exception);
728 clip_mask=DestroyImage(clip_mask);
733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
737 % C l o n e I m a g e %
741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
743 % CloneImage() copies an image and returns the copy as a new image object.
745 % If the specified columns and rows is 0, an exact copy of the image is
746 % returned, otherwise the pixel data is undefined and must be initialized
747 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
748 % failure, a NULL image is returned and exception describes the reason for the
751 % The format of the CloneImage method is:
753 % Image *CloneImage(const Image *image,const size_t columns,
754 % const size_t rows,const MagickBooleanType orphan,
755 % ExceptionInfo *exception)
757 % A description of each parameter follows:
759 % o image: the image.
761 % o columns: the number of columns in the cloned image.
763 % o rows: the number of rows in the cloned image.
765 % o detach: With a value other than 0, the cloned image is detached from
766 % its parent I/O stream.
768 % o exception: return any errors or warnings in this structure.
771 MagickExport Image *CloneImage(const Image *image,const size_t columns,
772 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
786 assert(image != (const Image *) NULL);
787 assert(image->signature == MagickSignature);
788 if (image->debug != MagickFalse)
789 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
790 assert(exception != (ExceptionInfo *) NULL);
791 assert(exception->signature == MagickSignature);
792 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
793 if (clone_image == (Image *) NULL)
794 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
795 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
796 clone_image->signature=MagickSignature;
797 clone_image->storage_class=image->storage_class;
798 clone_image->number_channels=image->number_channels;
799 clone_image->number_meta_channels=image->number_meta_channels;
800 clone_image->metacontent_extent=image->metacontent_extent;
801 clone_image->colorspace=image->colorspace;
802 clone_image->matte=image->matte;
803 clone_image->columns=image->columns;
804 clone_image->rows=image->rows;
805 clone_image->dither=image->dither;
806 if (image->colormap != (PixelInfo *) NULL)
809 Allocate and copy the image colormap.
811 clone_image->colors=image->colors;
812 length=(size_t) image->colors;
813 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
814 sizeof(*clone_image->colormap));
815 if (clone_image->colormap == (PixelInfo *) NULL)
816 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
817 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
818 sizeof(*clone_image->colormap));
820 (void) CloneImageProfiles(clone_image,image);
821 (void) CloneImageProperties(clone_image,image);
822 (void) CloneImageArtifacts(clone_image,image);
823 GetTimerInfo(&clone_image->timer);
824 if (image->ascii85 != (void *) NULL)
825 Ascii85Initialize(clone_image);
826 clone_image->magick_columns=image->magick_columns;
827 clone_image->magick_rows=image->magick_rows;
828 clone_image->type=image->type;
829 clone_image->sync=image->sync;
830 clone_image->channel_mask=image->channel_mask;
831 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
832 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
834 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
835 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
836 clone_image->progress_monitor=image->progress_monitor;
837 clone_image->client_data=image->client_data;
838 clone_image->reference_count=1;
839 clone_image->next=image->next;
840 clone_image->previous=image->previous;
841 clone_image->list=NewImageList();
842 clone_image->clip_mask=NewImageList();
843 clone_image->mask=NewImageList();
844 if (detach == MagickFalse)
845 clone_image->blob=ReferenceBlob(image->blob);
848 clone_image->next=NewImageList();
849 clone_image->previous=NewImageList();
850 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
852 clone_image->ping=image->ping;
853 clone_image->debug=IsEventLogging();
854 clone_image->semaphore=AllocateSemaphoreInfo();
855 if ((columns == 0) && (rows == 0))
857 if (image->montage != (char *) NULL)
858 (void) CloneString(&clone_image->montage,image->montage);
859 if (image->directory != (char *) NULL)
860 (void) CloneString(&clone_image->directory,image->directory);
861 if (image->clip_mask != (Image *) NULL)
862 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
864 if (image->mask != (Image *) NULL)
865 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
866 clone_image->cache=ReferencePixelCache(image->cache);
869 if ((columns == image->columns) && (rows == image->rows))
871 if (image->clip_mask != (Image *) NULL)
872 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
874 if (image->mask != (Image *) NULL)
875 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
877 scale=(MagickRealType) columns/(MagickRealType) image->columns;
878 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
879 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
880 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
881 scale=(MagickRealType) rows/(MagickRealType) image->rows;
882 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
883 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
884 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
885 clone_image->columns=columns;
886 clone_image->rows=rows;
887 clone_image->cache=ClonePixelCache(image->cache);
892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896 % C l o n e I m a g e I n f o %
900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
902 % CloneImageInfo() makes a copy of the given image info structure. If
903 % NULL is specified, a new image info structure is created initialized to
906 % The format of the CloneImageInfo method is:
908 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
910 % A description of each parameter follows:
912 % o image_info: the image info.
915 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
920 clone_info=AcquireImageInfo();
921 if (image_info == (ImageInfo *) NULL)
923 clone_info->compression=image_info->compression;
924 clone_info->temporary=image_info->temporary;
925 clone_info->adjoin=image_info->adjoin;
926 clone_info->antialias=image_info->antialias;
927 clone_info->scene=image_info->scene;
928 clone_info->number_scenes=image_info->number_scenes;
929 clone_info->depth=image_info->depth;
930 if (image_info->size != (char *) NULL)
931 (void) CloneString(&clone_info->size,image_info->size);
932 if (image_info->extract != (char *) NULL)
933 (void) CloneString(&clone_info->extract,image_info->extract);
934 if (image_info->scenes != (char *) NULL)
935 (void) CloneString(&clone_info->scenes,image_info->scenes);
936 if (image_info->page != (char *) NULL)
937 (void) CloneString(&clone_info->page,image_info->page);
938 clone_info->interlace=image_info->interlace;
939 clone_info->endian=image_info->endian;
940 clone_info->units=image_info->units;
941 clone_info->quality=image_info->quality;
942 if (image_info->sampling_factor != (char *) NULL)
943 (void) CloneString(&clone_info->sampling_factor,
944 image_info->sampling_factor);
945 if (image_info->server_name != (char *) NULL)
946 (void) CloneString(&clone_info->server_name,image_info->server_name);
947 if (image_info->font != (char *) NULL)
948 (void) CloneString(&clone_info->font,image_info->font);
949 if (image_info->texture != (char *) NULL)
950 (void) CloneString(&clone_info->texture,image_info->texture);
951 if (image_info->density != (char *) NULL)
952 (void) CloneString(&clone_info->density,image_info->density);
953 clone_info->pointsize=image_info->pointsize;
954 clone_info->fuzz=image_info->fuzz;
955 clone_info->background_color=image_info->background_color;
956 clone_info->border_color=image_info->border_color;
957 clone_info->matte_color=image_info->matte_color;
958 clone_info->transparent_color=image_info->transparent_color;
959 clone_info->dither=image_info->dither;
960 clone_info->monochrome=image_info->monochrome;
961 clone_info->colorspace=image_info->colorspace;
962 clone_info->type=image_info->type;
963 clone_info->orientation=image_info->orientation;
964 clone_info->preview_type=image_info->preview_type;
965 clone_info->group=image_info->group;
966 clone_info->ping=image_info->ping;
967 clone_info->verbose=image_info->verbose;
968 if (image_info->view != (char *) NULL)
969 (void) CloneString(&clone_info->view,image_info->view);
970 clone_info->progress_monitor=image_info->progress_monitor;
971 clone_info->client_data=image_info->client_data;
972 clone_info->cache=image_info->cache;
973 if (image_info->cache != (void *) NULL)
974 clone_info->cache=ReferencePixelCache(image_info->cache);
975 if (image_info->profile != (void *) NULL)
976 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
977 image_info->profile);
978 SetImageInfoFile(clone_info,image_info->file);
979 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
980 clone_info->stream=image_info->stream;
981 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
982 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
983 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
984 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
985 (void) CopyMagickString(clone_info->filename,image_info->filename,
987 clone_info->channel=image_info->channel;
989 (void) CloneImageOptions(clone_info,image_info);
990 clone_info->debug=IsEventLogging();
991 clone_info->signature=image_info->signature;
996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000 % C o m b i n e I m a g e s %
1004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1006 % CombineImages() combines one or more images into a single image. The
1007 % grayscale value of the pixels of each image in the sequence is assigned in
1008 % order to the specified channels of the combined image. The typical
1009 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
1011 % The format of the CombineImages method is:
1013 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
1015 % A description of each parameter follows:
1017 % o image: the image.
1019 % o exception: return any errors or warnings in this structure.
1023 static inline size_t MagickMin(const size_t x,const size_t y)
1030 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1032 #define CombineImageTag "Combine/Image"
1050 Ensure the image are the same size.
1052 assert(image != (const Image *) NULL);
1053 assert(image->signature == MagickSignature);
1054 if (image->debug != MagickFalse)
1055 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1056 assert(exception != (ExceptionInfo *) NULL);
1057 assert(exception->signature == MagickSignature);
1058 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1059 if (combine_image == (Image *) NULL)
1060 return((Image *) NULL);
1061 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1063 combine_image=DestroyImage(combine_image);
1064 return((Image *) NULL);
1066 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1067 combine_image->matte=MagickTrue;
1073 combine_view=AcquireCacheView(combine_image);
1074 for (y=0; y < (ssize_t) combine_image->rows; y++)
1085 register const Quantum
1094 if (status == MagickFalse)
1096 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1098 if (pixels == (Quantum *) NULL)
1104 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1116 if (next == (Image *) NULL)
1118 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1119 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1120 combine_traits=GetPixelChannelMapTraits(combine_image,channel);
1121 if ((traits == UndefinedPixelTrait) ||
1122 (combine_traits == UndefinedPixelTrait))
1124 image_view=AcquireCacheView(next);
1125 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1126 if (p == (const Quantum *) NULL)
1129 for (x=0; x < (ssize_t) combine_image->columns; x++)
1131 if (x < (ssize_t) image->columns)
1134 p+=GetPixelChannels(image);
1136 q+=GetPixelChannels(combine_image);
1138 image_view=DestroyCacheView(image_view);
1139 next=GetNextImageInList(next);
1140 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1142 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1147 proceed=SetImageProgress(image,CombineImageTag,progress++,
1148 combine_image->rows);
1149 if (proceed == MagickFalse)
1154 combine_view=DestroyCacheView(combine_view);
1155 if (status == MagickFalse)
1156 combine_image=DestroyImage(combine_image);
1157 return(combine_image);
1161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1165 % D e s t r o y I m a g e %
1169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1171 % DestroyImage() dereferences an image, deallocating memory associated with
1172 % the image if the reference count becomes zero.
1174 % The format of the DestroyImage method is:
1176 % Image *DestroyImage(Image *image)
1178 % A description of each parameter follows:
1180 % o image: the image.
1183 MagickExport Image *DestroyImage(Image *image)
1191 assert(image != (Image *) NULL);
1192 assert(image->signature == MagickSignature);
1193 if (image->debug != MagickFalse)
1194 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1195 destroy=MagickFalse;
1196 LockSemaphoreInfo(image->semaphore);
1197 image->reference_count--;
1198 if (image->reference_count == 0)
1200 UnlockSemaphoreInfo(image->semaphore);
1201 if (destroy == MagickFalse)
1202 return((Image *) NULL);
1206 DestroyImagePixels(image);
1207 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1208 if (image->clip_mask != (Image *) NULL)
1209 image->clip_mask=DestroyImage(image->clip_mask);
1210 if (image->mask != (Image *) NULL)
1211 image->mask=DestroyImage(image->mask);
1212 if (image->montage != (char *) NULL)
1213 image->montage=DestroyString(image->montage);
1214 if (image->directory != (char *) NULL)
1215 image->directory=DestroyString(image->directory);
1216 if (image->colormap != (PixelInfo *) NULL)
1217 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1218 if (image->geometry != (char *) NULL)
1219 image->geometry=DestroyString(image->geometry);
1220 DestroyImageProfiles(image);
1221 DestroyImageProperties(image);
1222 DestroyImageArtifacts(image);
1223 if (image->ascii85 != (Ascii85Info*) NULL)
1224 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1226 if (image->semaphore != (SemaphoreInfo *) NULL)
1227 DestroySemaphoreInfo(&image->semaphore);
1228 image->signature=(~MagickSignature);
1229 image=(Image *) RelinquishMagickMemory(image);
1234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1238 % D e s t r o y I m a g e I n f o %
1242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1244 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1247 % The format of the DestroyImageInfo method is:
1249 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1251 % A description of each parameter follows:
1253 % o image_info: the image info.
1256 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1258 assert(image_info != (ImageInfo *) NULL);
1259 assert(image_info->signature == MagickSignature);
1260 if (image_info->debug != MagickFalse)
1261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1262 image_info->filename);
1263 if (image_info->size != (char *) NULL)
1264 image_info->size=DestroyString(image_info->size);
1265 if (image_info->extract != (char *) NULL)
1266 image_info->extract=DestroyString(image_info->extract);
1267 if (image_info->scenes != (char *) NULL)
1268 image_info->scenes=DestroyString(image_info->scenes);
1269 if (image_info->page != (char *) NULL)
1270 image_info->page=DestroyString(image_info->page);
1271 if (image_info->sampling_factor != (char *) NULL)
1272 image_info->sampling_factor=DestroyString(
1273 image_info->sampling_factor);
1274 if (image_info->server_name != (char *) NULL)
1275 image_info->server_name=DestroyString(
1276 image_info->server_name);
1277 if (image_info->font != (char *) NULL)
1278 image_info->font=DestroyString(image_info->font);
1279 if (image_info->texture != (char *) NULL)
1280 image_info->texture=DestroyString(image_info->texture);
1281 if (image_info->density != (char *) NULL)
1282 image_info->density=DestroyString(image_info->density);
1283 if (image_info->view != (char *) NULL)
1284 image_info->view=DestroyString(image_info->view);
1285 if (image_info->cache != (void *) NULL)
1286 image_info->cache=DestroyPixelCache(image_info->cache);
1287 if (image_info->profile != (StringInfo *) NULL)
1288 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1289 image_info->profile);
1290 DestroyImageOptions(image_info);
1291 image_info->signature=(~MagickSignature);
1292 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1301 + D i s a s s o c i a t e I m a g e S t r e a m %
1305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1307 % DisassociateImageStream() disassociates the image stream.
1309 % The format of the DisassociateImageStream method is:
1311 % MagickBooleanType DisassociateImageStream(const Image *image)
1313 % A description of each parameter follows:
1315 % o image: the image.
1318 MagickExport void DisassociateImageStream(Image *image)
1320 assert(image != (const Image *) NULL);
1321 assert(image->signature == MagickSignature);
1322 if (image->debug != MagickFalse)
1323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1324 (void) DetachBlob(image->blob);
1328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1332 % G e t I m a g e A l p h a C h a n n e l %
1336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1338 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1339 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1342 % The format of the GetImageAlphaChannel method is:
1344 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1346 % A description of each parameter follows:
1348 % o image: the image.
1351 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1353 assert(image != (const Image *) NULL);
1354 if (image->debug != MagickFalse)
1355 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1356 assert(image->signature == MagickSignature);
1357 return(image->matte);
1361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1365 % G e t I m a g e C l i p M a s k %
1369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1371 % GetImageClipMask() returns the clip path associated with the image.
1373 % The format of the GetImageClipMask method is:
1375 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1377 % A description of each parameter follows:
1379 % o image: the image.
1382 MagickExport Image *GetImageClipMask(const Image *image,
1383 ExceptionInfo *exception)
1385 assert(image != (const Image *) NULL);
1386 if (image->debug != MagickFalse)
1387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1388 assert(image->signature == MagickSignature);
1389 if (image->clip_mask == (Image *) NULL)
1390 return((Image *) NULL);
1391 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1399 % G e t I m a g e I n f o %
1403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405 % GetImageInfo() initializes image_info to default values.
1407 % The format of the GetImageInfo method is:
1409 % void GetImageInfo(ImageInfo *image_info)
1411 % A description of each parameter follows:
1413 % o image_info: the image info.
1416 MagickExport void GetImageInfo(ImageInfo *image_info)
1425 File and image dimension members.
1427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1428 assert(image_info != (ImageInfo *) NULL);
1429 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1430 image_info->adjoin=MagickTrue;
1431 image_info->interlace=NoInterlace;
1432 image_info->channel=DefaultChannels;
1433 image_info->quality=UndefinedCompressionQuality;
1434 image_info->antialias=MagickTrue;
1435 image_info->dither=MagickTrue;
1436 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1437 if (synchronize != (const char *) NULL)
1438 image_info->synchronize=IsMagickTrue(synchronize);
1439 exception=AcquireExceptionInfo();
1440 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1441 &image_info->background_color,exception);
1442 (void) QueryColorCompliance(BorderColor,AllCompliance,
1443 &image_info->border_color,exception);
1444 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1446 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1447 &image_info->transparent_color,exception);
1448 exception=DestroyExceptionInfo(exception);
1449 image_info->debug=IsEventLogging();
1450 image_info->signature=MagickSignature;
1454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1458 % G e t I m a g e I n f o F i l e %
1462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1464 % GetImageInfoFile() returns the image info file member.
1466 % The format of the GetImageInfoFile method is:
1468 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1470 % A description of each parameter follows:
1472 % o image_info: the image info.
1475 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1477 return(image_info->file);
1481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1485 % G e t I m a g e M a s k %
1489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1491 % GetImageMask() returns the mask associated with the image.
1493 % The format of the GetImageMask method is:
1495 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1497 % A description of each parameter follows:
1499 % o image: the image.
1502 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1504 assert(image != (const Image *) NULL);
1505 if (image->debug != MagickFalse)
1506 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1507 assert(image->signature == MagickSignature);
1508 if (image->mask == (Image *) NULL)
1509 return((Image *) NULL);
1510 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1518 + G e t I m a g e R e f e r e n c e C o u n t %
1522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1524 % GetImageReferenceCount() returns the image reference count.
1526 % The format of the GetReferenceCount method is:
1528 % ssize_t GetImageReferenceCount(Image *image)
1530 % A description of each parameter follows:
1532 % o image: the image.
1535 MagickExport ssize_t GetImageReferenceCount(Image *image)
1540 assert(image != (Image *) NULL);
1541 assert(image->signature == MagickSignature);
1542 if (image->debug != MagickFalse)
1543 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1544 LockSemaphoreInfo(image->semaphore);
1545 reference_count=image->reference_count;
1546 UnlockSemaphoreInfo(image->semaphore);
1547 return(reference_count);
1551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1555 % 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 %
1559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1561 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1562 % image. A virtual pixel is any pixel access that is outside the boundaries
1563 % of the image cache.
1565 % The format of the GetImageVirtualPixelMethod() method is:
1567 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1569 % A description of each parameter follows:
1571 % o image: the image.
1574 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1576 assert(image != (Image *) NULL);
1577 assert(image->signature == MagickSignature);
1578 if (image->debug != MagickFalse)
1579 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1580 return(GetPixelCacheVirtualMethod(image));
1584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1588 % I n t e r p r e t I m a g e F i l e n a m e %
1592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1594 % InterpretImageFilename() interprets embedded characters in an image filename.
1595 % The filename length is returned.
1597 % The format of the InterpretImageFilename method is:
1599 % size_t InterpretImageFilename(const ImageInfo *image_info,
1600 % Image *image,const char *format,int value,char *filename,
1601 % ExceptionInfo *exception)
1603 % A description of each parameter follows.
1605 % o image_info: the image info..
1607 % o image: the image.
1609 % o format: A filename describing the format to use to write the numeric
1610 % argument. Only the first numeric format identifier is replaced.
1612 % o value: Numeric value to substitute into format filename.
1614 % o filename: return the formatted filename in this character buffer.
1616 % o exception: return any errors or warnings in this structure.
1619 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1620 Image *image,const char *format,int value,char *filename,
1621 ExceptionInfo *exception)
1638 canonical=MagickFalse;
1640 (void) CopyMagickString(filename,format,MaxTextExtent);
1641 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1654 value=(ssize_t) strtol(q,&q,10);
1666 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1667 (p-format)),p,value);
1669 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1670 canonical=MagickTrue;
1679 pattern[MaxTextExtent];
1696 if (strchr(p,']') == (char *) NULL)
1700 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1711 if (LocaleNCompare(pattern,"filename:",9) != 0)
1713 value=(const char *) NULL;
1714 if ((image_info != (const ImageInfo *) NULL) &&
1715 (image != (const Image *) NULL))
1716 value=GetMagickProperty(image_info,image,pattern,exception);
1718 if (image != (Image *) NULL)
1719 value=GetImageProperty(image,pattern,exception);
1721 if (image_info != (ImageInfo *) NULL)
1722 value=GetImageOption(image_info,pattern);
1723 if (value == (const char *) NULL)
1728 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1729 (MaxTextExtent-(p-format-length)));
1730 length+=strlen(pattern)-1;
1732 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1733 canonical=MagickTrue;
1743 for (q=filename; *q != '\0'; q++)
1744 if ((*q == '%') && (*(q+1) == '%'))
1746 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1747 canonical=MagickTrue;
1749 if (canonical == MagickFalse)
1750 (void) CopyMagickString(filename,format,MaxTextExtent);
1751 return(strlen(filename));
1755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1759 % I s H i g h D y n a m i c R a n g e I m a g e %
1763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1765 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1766 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1769 % The format of the IsHighDynamicRangeImage method is:
1771 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1772 % ExceptionInfo *exception)
1774 % A description of each parameter follows:
1776 % o image: the image.
1778 % o exception: return any errors or warnings in this structure.
1781 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1782 ExceptionInfo *exception)
1784 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1787 return(MagickFalse);
1798 assert(image != (Image *) NULL);
1799 assert(image->signature == MagickSignature);
1800 if (image->debug != MagickFalse)
1801 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1803 image_view=AcquireCacheView(image);
1804 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1805 #pragma omp parallel for schedule(dynamic,4) shared(status)
1807 for (y=0; y < (ssize_t) image->rows; y++)
1812 register const Quantum
1818 if (status == MagickFalse)
1820 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1821 if (p == (const Quantum *) NULL)
1827 for (x=0; x < (ssize_t) image->columns; x++)
1835 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1840 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1841 if (traits == UndefinedPixelTrait)
1843 pixel=(MagickRealType) p[i];
1844 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1845 (pixel != (QuantumAny) pixel))
1848 p+=GetPixelChannels(image);
1849 if (i < (ssize_t) GetPixelChannels(image))
1852 if (x < (ssize_t) image->columns)
1855 image_view=DestroyCacheView(image_view);
1856 return(status != MagickFalse ? MagickFalse : MagickTrue);
1861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1865 % I s I m a g e O b j e c t %
1869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1871 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1872 % set of image objects.
1874 % The format of the IsImageObject method is:
1876 % MagickBooleanType IsImageObject(const Image *image)
1878 % A description of each parameter follows:
1880 % o image: the image.
1883 MagickExport MagickBooleanType IsImageObject(const Image *image)
1885 register const Image
1888 assert(image != (Image *) NULL);
1889 if (image->debug != MagickFalse)
1890 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1891 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1892 if (p->signature != MagickSignature)
1893 return(MagickFalse);
1898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1902 % I s T a i n t I m a g e %
1906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1908 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1909 % since it was first constituted.
1911 % The format of the IsTaintImage method is:
1913 % MagickBooleanType IsTaintImage(const Image *image)
1915 % A description of each parameter follows:
1917 % o image: the image.
1920 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1923 magick[MaxTextExtent],
1924 filename[MaxTextExtent];
1926 register const Image
1929 assert(image != (Image *) NULL);
1930 if (image->debug != MagickFalse)
1931 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1932 assert(image->signature == MagickSignature);
1933 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1934 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1935 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1937 if (p->taint != MagickFalse)
1939 if (LocaleCompare(p->magick,magick) != 0)
1941 if (LocaleCompare(p->filename,filename) != 0)
1944 return(MagickFalse);
1948 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1952 % M o d i f y I m a g e %
1956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1958 % ModifyImage() ensures that there is only a single reference to the image
1959 % to be modified, updating the provided image pointer to point to a clone of
1960 % the original image if necessary.
1962 % The format of the ModifyImage method is:
1964 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1966 % A description of each parameter follows:
1968 % o image: the image.
1970 % o exception: return any errors or warnings in this structure.
1973 MagickExport MagickBooleanType ModifyImage(Image **image,
1974 ExceptionInfo *exception)
1979 assert(image != (Image **) NULL);
1980 assert(*image != (Image *) NULL);
1981 assert((*image)->signature == MagickSignature);
1982 if ((*image)->debug != MagickFalse)
1983 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1984 if (GetImageReferenceCount(*image) <= 1)
1986 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1987 LockSemaphoreInfo((*image)->semaphore);
1988 (*image)->reference_count--;
1989 UnlockSemaphoreInfo((*image)->semaphore);
1995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999 % N e w M a g i c k I m a g e %
2003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2005 % NewMagickImage() creates a blank image canvas of the specified size and
2008 % The format of the NewMagickImage method is:
2010 % Image *NewMagickImage(const ImageInfo *image_info,
2011 % const size_t width,const size_t height,const PixelInfo *background,
2012 % ExceptionInfo *exception)
2014 % A description of each parameter follows:
2016 % o image: the image.
2018 % o width: the image width.
2020 % o height: the image height.
2022 % o background: the image color.
2024 % o exception: return any errors or warnings in this structure.
2027 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2028 const size_t width,const size_t height,const PixelInfo *background,
2029 ExceptionInfo *exception)
2043 assert(image_info != (const ImageInfo *) NULL);
2044 if (image_info->debug != MagickFalse)
2045 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2046 assert(image_info->signature == MagickSignature);
2047 assert(background != (const PixelInfo *) NULL);
2048 image=AcquireImage(image_info,exception);
2049 image->columns=width;
2051 image->colorspace=background->colorspace;
2052 image->matte=background->matte;
2053 image->fuzz=background->fuzz;
2054 image->depth=background->depth;
2056 image_view=AcquireCacheView(image);
2057 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2058 #pragma omp parallel for schedule(dynamic,4) shared(status)
2060 for (y=0; y < (ssize_t) image->rows; y++)
2068 if (status == MagickFalse)
2070 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2071 if (q == (Quantum *) NULL)
2076 for (x=0; x < (ssize_t) image->columns; x++)
2078 SetPixelPixelInfo(image,background,q);
2079 q+=GetPixelChannels(image);
2081 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2084 image_view=DestroyCacheView(image_view);
2085 if (status == MagickFalse)
2086 image=DestroyImage(image);
2091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2095 % R e f e r e n c e I m a g e %
2099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2101 % ReferenceImage() increments the reference count associated with an image
2102 % returning a pointer to the image.
2104 % The format of the ReferenceImage method is:
2106 % Image *ReferenceImage(Image *image)
2108 % A description of each parameter follows:
2110 % o image: the image.
2113 MagickExport Image *ReferenceImage(Image *image)
2115 assert(image != (Image *) NULL);
2116 if (image->debug != MagickFalse)
2117 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2118 assert(image->signature == MagickSignature);
2119 LockSemaphoreInfo(image->semaphore);
2120 image->reference_count++;
2121 UnlockSemaphoreInfo(image->semaphore);
2126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2130 % R e s e t I m a g e P a g e %
2134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2136 % ResetImagePage() resets the image page canvas and position.
2138 % The format of the ResetImagePage method is:
2140 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2142 % A description of each parameter follows:
2144 % o image: the image.
2146 % o page: the relative page specification.
2149 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2157 assert(image != (Image *) NULL);
2158 assert(image->signature == MagickSignature);
2159 if (image->debug != MagickFalse)
2160 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2161 flags=ParseAbsoluteGeometry(page,&geometry);
2162 if ((flags & WidthValue) != 0)
2164 if ((flags & HeightValue) == 0)
2165 geometry.height=geometry.width;
2166 image->page.width=geometry.width;
2167 image->page.height=geometry.height;
2169 if ((flags & AspectValue) != 0)
2171 if ((flags & XValue) != 0)
2172 image->page.x+=geometry.x;
2173 if ((flags & YValue) != 0)
2174 image->page.y+=geometry.y;
2178 if ((flags & XValue) != 0)
2180 image->page.x=geometry.x;
2181 if ((image->page.width == 0) && (geometry.x > 0))
2182 image->page.width=image->columns+geometry.x;
2184 if ((flags & YValue) != 0)
2186 image->page.y=geometry.y;
2187 if ((image->page.height == 0) && (geometry.y > 0))
2188 image->page.height=image->rows+geometry.y;
2195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2199 % S e p a r a t e I m a g e C h a n n e l %
2203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2205 % SeparateImage() separates a channel from the image and returns it as
2206 % a grayscale image. A channel is a particular color component of each pixel
2209 % The format of the SeparateImage method is:
2211 % MagickBooleanType SeparateImage(Image *image,ExceptionInfo *exception)
2213 % A description of each parameter follows:
2215 % o image: the image.
2217 % o exception: return any errors or warnings in this structure.
2220 MagickExport MagickBooleanType SeparateImage(Image *image,
2221 ExceptionInfo *exception)
2223 #define SeparateImageTag "Separate/Image"
2237 assert(image != (Image *) NULL);
2238 assert(image->signature == MagickSignature);
2239 if (image->debug != MagickFalse)
2240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2241 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2242 return(MagickFalse);
2244 Separate image channels.
2248 image_view=AcquireCacheView(image);
2249 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2250 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2252 for (y=0; y < (ssize_t) image->rows; y++)
2260 if (status == MagickFalse)
2262 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2263 if (q == (Quantum *) NULL)
2268 for (x=0; x < (ssize_t) image->columns; x++)
2273 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2281 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2282 if (traits == UndefinedPixelTrait)
2284 if ((traits & UpdatePixelTrait) != 0)
2285 for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
2288 q+=GetPixelChannels(image);
2290 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2292 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2297 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2298 #pragma omp critical (MagickCore_SeparateImage)
2300 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2301 if (proceed == MagickFalse)
2305 image_view=DestroyCacheView(image_view);
2306 (void) SetImageColorspace(image,RGBColorspace,exception);
2311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2315 % S e p a r a t e I m a g e s %
2319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2321 % SeparateImages() returns a separate grayscale image for each channel
2324 % The format of the SeparateImages method is:
2326 % MagickBooleanType SeparateImages(const Image *image,
2327 % ExceptionInfo *exception)
2329 % A description of each parameter follows:
2331 % o image: the image.
2333 % o exception: return any errors or warnings in this structure.
2336 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2348 assert(image != (Image *) NULL);
2349 assert(image->signature == MagickSignature);
2350 if (image->debug != MagickFalse)
2351 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2352 images=NewImageList();
2353 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2358 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2359 if (traits == UndefinedPixelTrait)
2361 if ((traits & UpdatePixelTrait) != 0)
2363 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2364 if (separate_image != (Image *) NULL)
2366 channel_mask=SetPixelChannelMask(separate_image,
2367 (ChannelType) (1 << i));
2368 (void) SeparateImage(separate_image,exception);
2369 (void) SetPixelChannelMap(separate_image,channel_mask);
2370 AppendImageToList(&images,separate_image);
2378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2382 % S e t I m a g e A l p h a C h a n n e l %
2386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2388 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2391 % The format of the SetImageAlphaChannel method is:
2393 % MagickBooleanType SetImageAlphaChannel(Image *image,
2394 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2396 % A description of each parameter follows:
2398 % o image: the image.
2400 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2401 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2402 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2403 % TransparentAlphaChannel.
2405 % o exception: return any errors or warnings in this structure.
2408 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2409 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2417 assert(image != (Image *) NULL);
2418 if (image->debug != MagickFalse)
2419 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2420 assert(image->signature == MagickSignature);
2424 case ActivateAlphaChannel:
2426 image->matte=MagickTrue;
2429 case BackgroundAlphaChannel:
2444 Set transparent pixels to background color.
2446 if (image->matte == MagickFalse)
2448 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2450 GetPixelInfo(image,&background);
2451 SetPixelInfoPacket(image,&image->background_color,&background);
2452 if (image->colorspace == CMYKColorspace)
2453 ConvertRGBToCMYK(&background);
2454 SetPacketPixelInfo(image,&background,&pixel);
2455 image_view=AcquireCacheView(image);
2456 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2457 #pragma omp parallel for schedule(dynamic,4) shared(status)
2459 for (y=0; y < (ssize_t) image->rows; y++)
2467 if (status == MagickFalse)
2469 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2471 if (q == (Quantum *) NULL)
2476 for (x=0; x < (ssize_t) image->columns; x++)
2478 if (GetPixelAlpha(image,q) == TransparentAlpha)
2479 SetPixelPixelInfo(image,&background,q);
2480 q+=GetPixelChannels(image);
2482 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2485 image_view=DestroyCacheView(image_view);
2488 case DeactivateAlphaChannel:
2490 image->matte=MagickFalse;
2493 case ShapeAlphaChannel:
2494 case CopyAlphaChannel:
2497 Special usage case for SeparateImage(): copy grayscale color to
2500 channel_mask=SetPixelChannelMask(image,GrayChannel);
2501 status=SeparateImage(image,exception);
2502 (void) SetPixelChannelMask(image,channel_mask);
2503 image->matte=MagickTrue; /* make sure transparency is now on! */
2504 if (alpha_type == ShapeAlphaChannel)
2510 Reset all color channels to background color.
2512 GetPixelInfo(image,&background);
2513 SetPixelInfoPacket(image,&(image->background_color),&background);
2514 (void) LevelImageColors(image,&background,&background,MagickTrue,
2519 case ExtractAlphaChannel:
2521 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2522 status=SeparateImage(image,exception);
2523 (void) SetPixelChannelMask(image,channel_mask);
2524 image->matte=MagickFalse;
2527 case OpaqueAlphaChannel:
2529 status=SetImageAlpha(image,OpaqueAlpha,exception);
2530 image->matte=MagickTrue;
2533 case TransparentAlphaChannel:
2535 status=SetImageAlpha(image,TransparentAlpha,exception);
2536 image->matte=MagickTrue;
2539 case SetAlphaChannel:
2541 if (image->matte == MagickFalse)
2543 status=SetImageAlpha(image,OpaqueAlpha,exception);
2544 image->matte=MagickTrue;
2548 case UndefinedAlphaChannel:
2551 if (status == MagickFalse)
2553 return(SyncImagePixelCache(image,exception));
2557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2561 % S e t I m a g e B a c k g r o u n d C o l o r %
2565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2567 % SetImageBackgroundColor() initializes the image pixels to the image
2568 % background color. The background color is defined by the background_color
2569 % member of the image structure.
2571 % The format of the SetImage method is:
2573 % MagickBooleanType SetImageBackgroundColor(Image *image,
2574 % ExceptionInfo *exception)
2576 % A description of each parameter follows:
2578 % o image: the image.
2580 % o exception: return any errors or warnings in this structure.
2583 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2584 ExceptionInfo *exception)
2601 assert(image != (Image *) NULL);
2602 if (image->debug != MagickFalse)
2603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2604 assert(image->signature == MagickSignature);
2605 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2606 return(MagickFalse);
2607 if (image->background_color.alpha != OpaqueAlpha)
2608 image->matte=MagickTrue;
2609 GetPixelInfo(image,&background);
2610 SetPixelInfoPacket(image,&image->background_color,&background);
2611 if (image->colorspace == CMYKColorspace)
2612 ConvertRGBToCMYK(&background);
2613 SetPacketPixelInfo(image,&background,&pixel);
2615 Set image background color.
2619 image_view=AcquireCacheView(image);
2620 for (y=0; y < (ssize_t) image->rows; y++)
2628 if (status == MagickFalse)
2630 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2631 if (q == (Quantum *) NULL)
2636 for (x=0; x < (ssize_t) image->columns; x++)
2638 SetPixelPixelInfo(image,&background,q);
2639 q+=GetPixelChannels(image);
2641 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2644 image_view=DestroyCacheView(image_view);
2649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2653 % S e t I m a g e C o l o r %
2657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2659 % SetImageColor() set the entire image canvas to the specified color.
2661 % The format of the SetImageColor method is:
2663 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2664 % ExeptionInfo *exception)
2666 % A description of each parameter follows:
2668 % o image: the image.
2670 % o background: the image color.
2672 % o exception: return any errors or warnings in this structure.
2675 MagickExport MagickBooleanType SetImageColor(Image *image,
2676 const PixelInfo *color,ExceptionInfo *exception)
2687 assert(image != (Image *) NULL);
2688 if (image->debug != MagickFalse)
2689 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2690 assert(image->signature == MagickSignature);
2691 assert(color != (const PixelInfo *) NULL);
2692 image->colorspace=color->colorspace;
2693 image->matte=color->matte;
2694 image->fuzz=color->fuzz;
2695 image->depth=color->depth;
2697 image_view=AcquireCacheView(image);
2698 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2699 #pragma omp parallel for schedule(dynamic,4) shared(status)
2701 for (y=0; y < (ssize_t) image->rows; y++)
2709 if (status == MagickFalse)
2711 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2712 if (q == (Quantum *) NULL)
2717 for (x=0; x < (ssize_t) image->columns; x++)
2719 SetPixelPixelInfo(image,color,q);
2720 q+=GetPixelChannels(image);
2722 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2725 image_view=DestroyCacheView(image_view);
2730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2734 % S e t I m a g e S t o r a g e C l a s s %
2738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2740 % SetImageStorageClass() sets the image class: DirectClass for true color
2741 % images or PseudoClass for colormapped images.
2743 % The format of the SetImageStorageClass method is:
2745 % MagickBooleanType SetImageStorageClass(Image *image,
2746 % const ClassType storage_class,ExceptionInfo *exception)
2748 % A description of each parameter follows:
2750 % o image: the image.
2752 % o storage_class: The image class.
2754 % o exception: return any errors or warnings in this structure.
2757 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2758 const ClassType storage_class,ExceptionInfo *exception)
2760 image->storage_class=storage_class;
2761 return(SyncImagePixelCache(image,exception));
2765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2769 % S e t I m a g e C l i p M a s k %
2773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2775 % SetImageClipMask() associates a clip path with the image. The clip path
2776 % must be the same dimensions as the image. Set any pixel component of
2777 % the clip path to TransparentAlpha to prevent that corresponding image
2778 % pixel component from being updated when SyncAuthenticPixels() is applied.
2780 % The format of the SetImageClipMask method is:
2782 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2783 % ExceptionInfo *exception)
2785 % A description of each parameter follows:
2787 % o image: the image.
2789 % o clip_mask: the image clip path.
2791 % o exception: return any errors or warnings in this structure.
2794 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2795 const Image *clip_mask,ExceptionInfo *exception)
2797 assert(image != (Image *) NULL);
2798 if (image->debug != MagickFalse)
2799 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2800 assert(image->signature == MagickSignature);
2801 if (clip_mask != (const Image *) NULL)
2802 if ((clip_mask->columns != image->columns) ||
2803 (clip_mask->rows != image->rows))
2804 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2805 if (image->clip_mask != (Image *) NULL)
2806 image->clip_mask=DestroyImage(image->clip_mask);
2807 image->clip_mask=NewImageList();
2808 if (clip_mask == (Image *) NULL)
2810 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2811 return(MagickFalse);
2812 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,exception);
2813 if (image->clip_mask == (Image *) NULL)
2814 return(MagickFalse);
2819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2823 % S e t I m a g e E x t e n t %
2827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2829 % SetImageExtent() sets the image size (i.e. columns & rows).
2831 % The format of the SetImageExtent method is:
2833 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2834 % const size_t rows,ExceptionInfo *exception)
2836 % A description of each parameter follows:
2838 % o image: the image.
2840 % o columns: The image width in pixels.
2842 % o rows: The image height in pixels.
2844 % o exception: return any errors or warnings in this structure.
2847 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2848 const size_t rows,ExceptionInfo *exception)
2850 if ((columns == 0) || (rows == 0))
2851 return(MagickFalse);
2852 image->columns=columns;
2854 return(SyncImagePixelCache(image,exception));
2858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2862 + S e t I m a g e I n f o %
2866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2868 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2869 % It is set to a type of image format based on the prefix or suffix of the
2870 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2871 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2872 % precendence over the suffix. Use an optional index enclosed in brackets
2873 % after a file name to specify a desired scene of a multi-resolution image
2874 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2875 % indicates success.
2877 % The format of the SetImageInfo method is:
2879 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2880 % const unsigned int frames,ExceptionInfo *exception)
2882 % A description of each parameter follows:
2884 % o image_info: the image info.
2886 % o frames: the number of images you intend to write.
2888 % o exception: return any errors or warnings in this structure.
2891 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2892 const unsigned int frames,ExceptionInfo *exception)
2895 extension[MaxTextExtent],
2896 filename[MaxTextExtent],
2897 magic[MaxTextExtent],
2899 subimage[MaxTextExtent];
2923 magick[2*MaxTextExtent];
2926 Look for 'image.format' in filename.
2928 assert(image_info != (ImageInfo *) NULL);
2929 assert(image_info->signature == MagickSignature);
2930 if (image_info->debug != MagickFalse)
2931 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2932 image_info->filename);
2936 GetPathComponent(image_info->filename,SubimagePath,subimage);
2937 if (*subimage != '\0')
2940 Look for scene specification (e.g. img0001.pcd[4]).
2942 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2944 if (IsGeometry(subimage) != MagickFalse)
2945 (void) CloneString(&image_info->extract,subimage);
2953 (void) CloneString(&image_info->scenes,subimage);
2954 image_info->scene=StringToUnsignedLong(image_info->scenes);
2955 image_info->number_scenes=image_info->scene;
2956 p=image_info->scenes;
2957 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2959 while ((isspace((int) ((unsigned char) *p)) != 0) ||
2962 first=(size_t) strtol(p,&q,10);
2964 while (isspace((int) ((unsigned char) *q)) != 0)
2967 last=(size_t) strtol(q+1,&q,10);
2970 if (first < image_info->scene)
2971 image_info->scene=first;
2972 if (last > image_info->number_scenes)
2973 image_info->number_scenes=last;
2976 image_info->number_scenes-=image_info->scene-1;
2981 GetPathComponent(image_info->filename,ExtensionPath,extension);
2982 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2983 if (*extension != '\0')
2984 if ((LocaleCompare(extension,"gz") == 0) ||
2985 (LocaleCompare(extension,"Z") == 0) ||
2986 (LocaleCompare(extension,"wmz") == 0))
2989 path[MaxTextExtent];
2991 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2992 path[strlen(path)-strlen(extension)-1]='\0';
2993 GetPathComponent(path,ExtensionPath,extension);
2996 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2997 if (*extension != '\0')
2998 if (LocaleCompare(extension,"bz2") == 0)
3001 path[MaxTextExtent];
3003 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3004 path[strlen(path)-strlen(extension)-1]='\0';
3005 GetPathComponent(path,ExtensionPath,extension);
3008 image_info->affirm=MagickFalse;
3009 sans_exception=AcquireExceptionInfo();
3010 if (*extension != '\0')
3019 *format_type_formats[] =
3042 User specified image format.
3044 (void) CopyMagickString(magic,extension,MaxTextExtent);
3047 Look for explicit image formats.
3049 format_type=UndefinedFormatType;
3051 while ((format_type == UndefinedFormatType) &&
3052 (format_type_formats[i] != (char *) NULL))
3054 if ((*magic == *format_type_formats[i]) &&
3055 (LocaleCompare(magic,format_type_formats[i]) == 0))
3056 format_type=ExplicitFormatType;
3059 magick_info=GetMagickInfo(magic,sans_exception);
3060 if ((magick_info != (const MagickInfo *) NULL) &&
3061 (magick_info->format_type != UndefinedFormatType))
3062 format_type=magick_info->format_type;
3063 if (format_type == UndefinedFormatType)
3064 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3066 if (format_type == ExplicitFormatType)
3068 image_info->affirm=MagickTrue;
3069 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3071 if (LocaleCompare(magic,"RGB") == 0)
3072 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3075 Look for explicit 'format:image' in filename.
3078 GetPathComponent(image_info->filename,MagickPath,magic);
3080 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3084 User specified image format.
3087 if (IsMagickConflict(magic) == MagickFalse)
3089 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3090 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3091 image_info->affirm=MagickTrue;
3093 image_info->temporary=MagickTrue;
3096 magick_info=GetMagickInfo(magic,sans_exception);
3097 sans_exception=DestroyExceptionInfo(sans_exception);
3098 if ((magick_info == (const MagickInfo *) NULL) ||
3099 (GetMagickEndianSupport(magick_info) == MagickFalse))
3100 image_info->endian=UndefinedEndian;
3101 GetPathComponent(image_info->filename,CanonicalPath,filename);
3102 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3103 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3106 Test for multiple image support (e.g. image%02d.png).
3108 (void) InterpretImageFilename(image_info,(Image *) NULL,
3109 image_info->filename,(int) image_info->scene,filename,exception);
3110 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3111 (strchr(filename,'%') == (char *) NULL))
3112 image_info->adjoin=MagickFalse;
3114 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3117 Some image formats do not support multiple frames per file.
3119 magick_info=GetMagickInfo(magic,exception);
3120 if (magick_info != (const MagickInfo *) NULL)
3121 if (GetMagickAdjoin(magick_info) == MagickFalse)
3122 image_info->adjoin=MagickFalse;
3124 if (image_info->affirm != MagickFalse)
3129 Determine the image format from the first few bytes of the file.
3131 image=AcquireImage(image_info,exception);
3132 (void) CopyMagickString(image->filename,image_info->filename,
3134 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3135 if (status == MagickFalse)
3137 image=DestroyImage(image);
3138 return(MagickFalse);
3140 if ((IsBlobSeekable(image) == MagickFalse) ||
3141 (IsBlobExempt(image) != MagickFalse))
3144 Copy standard input or pipe to temporary file.
3147 status=ImageToFile(image,filename,exception);
3148 (void) CloseBlob(image);
3149 if (status == MagickFalse)
3151 image=DestroyImage(image);
3152 return(MagickFalse);
3154 SetImageInfoFile(image_info,(FILE *) NULL);
3155 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3156 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3157 if (status == MagickFalse)
3159 image=DestroyImage(image);
3160 return(MagickFalse);
3162 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3163 image_info->temporary=MagickTrue;
3165 (void) ResetMagickMemory(magick,0,sizeof(magick));
3166 count=ReadBlob(image,2*MaxTextExtent,magick);
3167 (void) CloseBlob(image);
3168 image=DestroyImage(image);
3170 Check magic.xml configuration file.
3172 sans_exception=AcquireExceptionInfo();
3173 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3174 if ((magic_info != (const MagicInfo *) NULL) &&
3175 (GetMagicName(magic_info) != (char *) NULL))
3177 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3179 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3180 if ((magick_info == (const MagickInfo *) NULL) ||
3181 (GetMagickEndianSupport(magick_info) == MagickFalse))
3182 image_info->endian=UndefinedEndian;
3183 sans_exception=DestroyExceptionInfo(sans_exception);
3186 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3187 if ((magick_info == (const MagickInfo *) NULL) ||
3188 (GetMagickEndianSupport(magick_info) == MagickFalse))
3189 image_info->endian=UndefinedEndian;
3190 sans_exception=DestroyExceptionInfo(sans_exception);
3196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3200 % S e t I m a g e I n f o B l o b %
3204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3206 % SetImageInfoBlob() sets the image info blob member.
3208 % The format of the SetImageInfoBlob method is:
3210 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3211 % const size_t length)
3213 % A description of each parameter follows:
3215 % o image_info: the image info.
3219 % o length: the blob length.
3222 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3223 const size_t length)
3225 assert(image_info != (ImageInfo *) NULL);
3226 assert(image_info->signature == MagickSignature);
3227 if (image_info->debug != MagickFalse)
3228 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3229 image_info->filename);
3230 image_info->blob=(void *) blob;
3231 image_info->length=length;
3235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3239 % S e t I m a g e I n f o F i l e %
3243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3245 % SetImageInfoFile() sets the image info file member.
3247 % The format of the SetImageInfoFile method is:
3249 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3251 % A description of each parameter follows:
3253 % o image_info: the image info.
3258 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3260 assert(image_info != (ImageInfo *) NULL);
3261 assert(image_info->signature == MagickSignature);
3262 if (image_info->debug != MagickFalse)
3263 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3264 image_info->filename);
3265 image_info->file=file;
3269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3273 % S e t I m a g e M a s k %
3277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3279 % SetImageMask() associates a mask with the image. The mask must be the same
3280 % dimensions as the image.
3282 % The format of the SetImageMask method is:
3284 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3285 % ExceptionInfo *exception)
3287 % A description of each parameter follows:
3289 % o image: the image.
3291 % o mask: the image mask.
3293 % o exception: return any errors or warnings in this structure.
3296 MagickExport MagickBooleanType SetImageMask(Image *image,
3297 const Image *mask,ExceptionInfo *exception)
3299 assert(image != (Image *) NULL);
3300 if (image->debug != MagickFalse)
3301 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3302 assert(image->signature == MagickSignature);
3303 if (mask != (const Image *) NULL)
3304 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3305 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3306 if (image->mask != (Image *) NULL)
3307 image->mask=DestroyImage(image->mask);
3308 image->mask=NewImageList();
3309 if (mask == (Image *) NULL)
3311 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3312 return(MagickFalse);
3313 image->mask=CloneImage(mask,0,0,MagickTrue,exception);
3314 if (image->mask == (Image *) NULL)
3315 return(MagickFalse);
3320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3324 % S e t I m a g e A l p h a %
3328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3330 % SetImageAlpha() sets the alpha levels of the image.
3332 % The format of the SetImageAlpha method is:
3334 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3335 % ExceptionInfo *exception)
3337 % A description of each parameter follows:
3339 % o image: the image.
3341 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3342 % fully transparent.
3345 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3346 ExceptionInfo *exception)
3357 assert(image != (Image *) NULL);
3358 if (image->debug != MagickFalse)
3359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3360 assert(image->signature == MagickSignature);
3361 image->matte=alpha != OpaqueAlpha ? MagickTrue : MagickFalse;
3363 image_view=AcquireCacheView(image);
3364 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3365 #pragma omp parallel for schedule(dynamic,4) shared(status)
3367 for (y=0; y < (ssize_t) image->rows; y++)
3375 if (status == MagickFalse)
3377 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3378 if (q == (Quantum *) NULL)
3383 for (x=0; x < (ssize_t) image->columns; x++)
3385 SetPixelAlpha(image,alpha,q);
3386 q+=GetPixelChannels(image);
3388 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3391 image_view=DestroyCacheView(image_view);
3396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3400 % S e t I m a g e T y p e %
3404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3406 % SetImageType() sets the type of image. Choose from these types:
3408 % Bilevel Grayscale GrayscaleMatte
3409 % Palette PaletteMatte TrueColor
3410 % TrueColorMatte ColorSeparation ColorSeparationMatte
3413 % The format of the SetImageType method is:
3415 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3416 % ExceptionInfo *exception)
3418 % A description of each parameter follows:
3420 % o image: the image.
3422 % o type: Image type.
3424 % o exception: return any errors or warnings in this structure.
3427 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3428 ExceptionInfo *exception)
3442 assert(image != (Image *) NULL);
3443 if (image->debug != MagickFalse)
3444 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3445 assert(image->signature == MagickSignature);
3447 image_info=AcquireImageInfo();
3448 image_info->dither=image->dither;
3449 artifact=GetImageArtifact(image,"dither");
3450 if (artifact != (const char *) NULL)
3451 (void) SetImageOption(image_info,"dither",artifact);
3456 if (IsImageGray(image,exception) == MagickFalse)
3457 status=TransformImageColorspace(image,GRAYColorspace,exception);
3458 if (IsImageMonochrome(image,exception) == MagickFalse)
3460 quantize_info=AcquireQuantizeInfo(image_info);
3461 quantize_info->number_colors=2;
3462 quantize_info->colorspace=GRAYColorspace;
3463 status=QuantizeImage(quantize_info,image,exception);
3464 quantize_info=DestroyQuantizeInfo(quantize_info);
3466 image->matte=MagickFalse;
3471 if (IsImageGray(image,exception) == MagickFalse)
3472 status=TransformImageColorspace(image,GRAYColorspace,exception);
3473 image->matte=MagickFalse;
3476 case GrayscaleMatteType:
3478 if (IsImageGray(image,exception) == MagickFalse)
3479 status=TransformImageColorspace(image,GRAYColorspace,exception);
3480 if (image->matte == MagickFalse)
3481 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3486 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3487 status=TransformImageColorspace(image,RGBColorspace,exception);
3488 if ((image->storage_class == DirectClass) || (image->colors > 256))
3490 quantize_info=AcquireQuantizeInfo(image_info);
3491 quantize_info->number_colors=256;
3492 status=QuantizeImage(quantize_info,image,exception);
3493 quantize_info=DestroyQuantizeInfo(quantize_info);
3495 image->matte=MagickFalse;
3498 case PaletteBilevelMatteType:
3503 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3504 status=TransformImageColorspace(image,RGBColorspace,exception);
3505 if (image->matte == MagickFalse)
3506 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3507 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3508 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
3509 (void) SetPixelChannelMask(image,channel_mask);
3510 quantize_info=AcquireQuantizeInfo(image_info);
3511 status=QuantizeImage(quantize_info,image,exception);
3512 quantize_info=DestroyQuantizeInfo(quantize_info);
3515 case PaletteMatteType:
3517 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3518 status=TransformImageColorspace(image,RGBColorspace,exception);
3519 if (image->matte == MagickFalse)
3520 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3521 quantize_info=AcquireQuantizeInfo(image_info);
3522 quantize_info->colorspace=TransparentColorspace;
3523 status=QuantizeImage(quantize_info,image,exception);
3524 quantize_info=DestroyQuantizeInfo(quantize_info);
3529 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3530 status=TransformImageColorspace(image,RGBColorspace,exception);
3531 if (image->storage_class != DirectClass)
3532 status=SetImageStorageClass(image,DirectClass,exception);
3533 image->matte=MagickFalse;
3536 case TrueColorMatteType:
3538 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3539 status=TransformImageColorspace(image,RGBColorspace,exception);
3540 if (image->storage_class != DirectClass)
3541 status=SetImageStorageClass(image,DirectClass,exception);
3542 if (image->matte == MagickFalse)
3543 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3546 case ColorSeparationType:
3548 if (image->colorspace != CMYKColorspace)
3550 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3551 status=TransformImageColorspace(image,RGBColorspace,exception);
3552 status=TransformImageColorspace(image,CMYKColorspace,exception);
3554 if (image->storage_class != DirectClass)
3555 status=SetImageStorageClass(image,DirectClass,exception);
3556 image->matte=MagickFalse;
3559 case ColorSeparationMatteType:
3561 if (image->colorspace != CMYKColorspace)
3563 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3564 status=TransformImageColorspace(image,RGBColorspace,exception);
3565 status=TransformImageColorspace(image,CMYKColorspace,exception);
3567 if (image->storage_class != DirectClass)
3568 status=SetImageStorageClass(image,DirectClass,exception);
3569 if (image->matte == MagickFalse)
3570 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3578 image_info=DestroyImageInfo(image_info);
3583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3587 % 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 %
3591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3593 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3594 % image and returns the previous setting. A virtual pixel is any pixel access
3595 % that is outside the boundaries of the image cache.
3597 % The format of the SetImageVirtualPixelMethod() method is:
3599 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3600 % const VirtualPixelMethod virtual_pixel_method)
3602 % A description of each parameter follows:
3604 % o image: the image.
3606 % o virtual_pixel_method: choose the type of virtual pixel.
3609 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3610 const VirtualPixelMethod virtual_pixel_method)
3612 assert(image != (const Image *) NULL);
3613 assert(image->signature == MagickSignature);
3614 if (image->debug != MagickFalse)
3615 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3616 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3624 % S m u s h I m a g e s %
3628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3630 % SmushImages() takes all images from the current image pointer to the end
3631 % of the image list and smushes them to each other top-to-bottom if the
3632 % stack parameter is true, otherwise left-to-right.
3634 % The current gravity setting now effects how the image is justified in the
3637 % The format of the SmushImages method is:
3639 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3640 % ExceptionInfo *exception)
3642 % A description of each parameter follows:
3644 % o images: the image sequence.
3646 % o stack: A value other than 0 stacks the images top-to-bottom.
3648 % o offset: minimum distance in pixels between images.
3650 % o exception: return any errors or warnings in this structure.
3654 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3655 const ssize_t offset,ExceptionInfo *exception)
3669 register const Quantum
3682 if (images->previous == (Image *) NULL)
3685 SetGeometry(smush_image,&right_geometry);
3686 GravityAdjustGeometry(right_image->columns,right_image->rows,
3687 right_image->gravity,&right_geometry);
3688 left_image=images->previous;
3689 SetGeometry(smush_image,&left_geometry);
3690 GravityAdjustGeometry(left_image->columns,left_image->rows,
3691 left_image->gravity,&left_geometry);
3692 gap=right_image->columns;
3693 left_view=AcquireCacheView(left_image);
3694 right_view=AcquireCacheView(right_image);
3695 for (y=0; y < (ssize_t) smush_image->rows; y++)
3697 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3699 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3700 if ((p == (const Quantum *) NULL) ||
3701 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3702 ((left_image->columns-x-1) >= gap))
3705 i=(ssize_t) left_image->columns-x-1;
3706 for (x=0; x < (ssize_t) right_image->columns; x++)
3708 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3710 if ((p == (const Quantum *) NULL) ||
3711 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3712 ((x+i) >= (ssize_t) gap))
3715 if ((x+i) < (ssize_t) gap)
3718 right_view=DestroyCacheView(right_view);
3719 left_view=DestroyCacheView(left_view);
3720 if (y < (ssize_t) smush_image->rows)
3722 return((ssize_t) gap-offset);
3725 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3726 const ssize_t offset,ExceptionInfo *exception)
3740 register const Quantum
3753 if (images->previous == (Image *) NULL)
3755 bottom_image=images;
3756 SetGeometry(smush_image,&bottom_geometry);
3757 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3758 bottom_image->gravity,&bottom_geometry);
3759 top_image=images->previous;
3760 SetGeometry(smush_image,&top_geometry);
3761 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3763 gap=bottom_image->rows;
3764 top_view=AcquireCacheView(top_image);
3765 bottom_view=AcquireCacheView(bottom_image);
3766 for (x=0; x < (ssize_t) smush_image->columns; x++)
3768 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3770 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3771 if ((p == (const Quantum *) NULL) ||
3772 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3773 ((top_image->rows-y-1) >= gap))
3776 i=(ssize_t) top_image->rows-y-1;
3777 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3779 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3781 if ((p == (const Quantum *) NULL) ||
3782 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3783 ((y+i) >= (ssize_t) gap))
3786 if ((y+i) < (ssize_t) gap)
3789 bottom_view=DestroyCacheView(bottom_view);
3790 top_view=DestroyCacheView(top_view);
3791 if (x < (ssize_t) smush_image->columns)
3793 return((ssize_t) gap-offset);
3796 MagickExport Image *SmushImages(const Image *images,
3797 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3799 #define SmushImageTag "Smush/Image"
3821 register const Image
3834 Compute maximum area of smushed area.
3836 assert(images != (Image *) NULL);
3837 assert(images->signature == MagickSignature);
3838 if (images->debug != MagickFalse)
3839 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3840 assert(exception != (ExceptionInfo *) NULL);
3841 assert(exception->signature == MagickSignature);
3845 width=image->columns;
3847 next=GetNextImageInList(image);
3848 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3850 if (next->matte != MagickFalse)
3853 if (stack != MagickFalse)
3855 if (next->columns > width)
3856 width=next->columns;
3858 if (next->previous != (Image *) NULL)
3862 width+=next->columns;
3863 if (next->previous != (Image *) NULL)
3865 if (next->rows > height)
3871 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3872 if (smush_image == (Image *) NULL)
3873 return((Image *) NULL);
3874 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3876 smush_image=DestroyImage(smush_image);
3877 return((Image *) NULL);
3879 smush_image->matte=matte;
3880 (void) SetImageBackgroundColor(smush_image,exception);
3884 smush_view=AcquireCacheView(smush_image);
3885 for (n=0; n < (MagickOffsetType) number_images; n++)
3887 SetGeometry(smush_image,&geometry);
3888 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3889 if (stack != MagickFalse)
3891 x_offset-=geometry.x;
3892 y_offset-=SmushYGap(smush_image,image,offset,exception);
3896 x_offset-=SmushXGap(smush_image,image,offset,exception);
3897 y_offset-=geometry.y;
3899 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
3901 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3902 if (proceed == MagickFalse)
3904 if (stack == MagickFalse)
3906 x_offset+=(ssize_t) image->columns;
3912 y_offset+=(ssize_t) image->rows;
3914 image=GetNextImageInList(image);
3916 if (stack == MagickFalse)
3917 smush_image->columns=(size_t) x_offset;
3919 smush_image->rows=(size_t) y_offset;
3920 smush_view=DestroyCacheView(smush_view);
3921 if (status == MagickFalse)
3922 smush_image=DestroyImage(smush_image);
3923 return(smush_image);
3927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3931 % S t r i p I m a g e %
3935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3937 % StripImage() strips an image of all profiles and comments.
3939 % The format of the StripImage method is:
3941 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3943 % A description of each parameter follows:
3945 % o image: the image.
3947 % o exception: return any errors or warnings in this structure.
3950 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3955 assert(image != (Image *) NULL);
3956 if (image->debug != MagickFalse)
3957 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3959 DestroyImageProfiles(image);
3960 (void) DeleteImageProperty(image,"comment");
3961 (void) DeleteImageProperty(image,"date:create");
3962 (void) DeleteImageProperty(image,"date:modify");
3963 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
3968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3972 + S y n c I m a g e %
3976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3978 % SyncImage() initializes the red, green, and blue intensities of each pixel
3979 % as defined by the colormap index.
3981 % The format of the SyncImage method is:
3983 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3985 % A description of each parameter follows:
3987 % o image: the image.
3989 % o exception: return any errors or warnings in this structure.
3993 static inline Quantum PushColormapIndex(Image *image,
3994 const size_t index,MagickBooleanType *range_exception)
3996 if (index < image->colors)
3997 return((Quantum) index);
3998 *range_exception=MagickTrue;
3999 return((Quantum) 0);
4002 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4014 assert(image != (Image *) NULL);
4015 if (image->debug != MagickFalse)
4016 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4017 assert(image->signature == MagickSignature);
4018 if (image->storage_class == DirectClass)
4019 return(MagickFalse);
4020 range_exception=MagickFalse;
4022 image_view=AcquireCacheView(image);
4023 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4024 #pragma omp parallel for schedule(dynamic,4) shared(status)
4026 for (y=0; y < (ssize_t) image->rows; y++)
4037 if (status == MagickFalse)
4039 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4040 if (q == (Quantum *) NULL)
4045 for (x=0; x < (ssize_t) image->columns; x++)
4047 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4049 SetPixelPixelInfo(image,image->colormap+(ssize_t) index,q);
4050 q+=GetPixelChannels(image);
4052 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4055 image_view=DestroyCacheView(image_view);
4056 if (range_exception != MagickFalse)
4057 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
4058 "InvalidColormapIndex","`%s'",image->filename);
4063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4067 % S y n c I m a g e S e t t i n g s %
4071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4073 % SyncImageSettings() sync the image info options to the image.
4075 % The format of the SyncImageSettings method is:
4077 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4078 % Image *image,ExceptionInfo *exception)
4079 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4080 % Image *image,ExceptionInfo *exception)
4082 % A description of each parameter follows:
4084 % o image_info: the image info.
4086 % o image: the image.
4088 % o exception: return any errors or warnings in this structure.
4092 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4093 Image *images,ExceptionInfo *exception)
4098 assert(image_info != (const ImageInfo *) NULL);
4099 assert(image_info->signature == MagickSignature);
4100 assert(images != (Image *) NULL);
4101 assert(images->signature == MagickSignature);
4102 if (images->debug != MagickFalse)
4103 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4105 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4106 (void) SyncImageSettings(image_info,image,exception);
4107 (void) DeleteImageOption(image_info,"page");
4111 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4112 Image *image,ExceptionInfo *exception)
4115 property[MaxTextExtent];
4133 assert(image_info != (const ImageInfo *) NULL);
4134 assert(image_info->signature == MagickSignature);
4135 assert(image != (Image *) NULL);
4136 assert(image->signature == MagickSignature);
4137 if (image->debug != MagickFalse)
4138 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4139 option=GetImageOption(image_info,"background");
4140 if (option != (const char *) NULL)
4141 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4143 option=GetImageOption(image_info,"bias");
4144 if (option != (const char *) NULL)
4145 image->bias=SiPrefixToDouble(option,QuantumRange);
4146 option=GetImageOption(image_info,"black-point-compensation");
4147 if (option != (const char *) NULL)
4148 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4149 MagickBooleanOptions,MagickFalse,option);
4150 option=GetImageOption(image_info,"blue-primary");
4151 if (option != (const char *) NULL)
4153 flags=ParseGeometry(option,&geometry_info);
4154 image->chromaticity.blue_primary.x=geometry_info.rho;
4155 image->chromaticity.blue_primary.y=geometry_info.sigma;
4156 if ((flags & SigmaValue) == 0)
4157 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4159 option=GetImageOption(image_info,"bordercolor");
4160 if (option != (const char *) NULL)
4161 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4163 option=GetImageOption(image_info,"compose");
4164 if (option != (const char *) NULL)
4165 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4166 MagickFalse,option);
4167 option=GetImageOption(image_info,"compress");
4168 if (option != (const char *) NULL)
4169 image->compression=(CompressionType) ParseCommandOption(
4170 MagickCompressOptions,MagickFalse,option);
4171 option=GetImageOption(image_info,"debug");
4172 if (option != (const char *) NULL)
4173 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4174 MagickFalse,option);
4175 option=GetImageOption(image_info,"density");
4176 if (option != (const char *) NULL)
4181 flags=ParseGeometry(option,&geometry_info);
4182 image->x_resolution=geometry_info.rho;
4183 image->y_resolution=geometry_info.sigma;
4184 if ((flags & SigmaValue) == 0)
4185 image->y_resolution=image->x_resolution;
4187 option=GetImageOption(image_info,"depth");
4188 if (option != (const char *) NULL)
4189 image->depth=StringToUnsignedLong(option);
4190 option=GetImageOption(image_info,"endian");
4191 if (option != (const char *) NULL)
4192 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4193 MagickFalse,option);
4194 option=GetImageOption(image_info,"filter");
4195 if (option != (const char *) NULL)
4196 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4197 MagickFalse,option);
4198 option=GetImageOption(image_info,"fuzz");
4199 if (option != (const char *) NULL)
4200 image->fuzz=SiPrefixToDouble(option,(double) QuantumRange+1.0);
4201 option=GetImageOption(image_info,"gravity");
4202 if (option != (const char *) NULL)
4203 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4204 MagickFalse,option);
4205 option=GetImageOption(image_info,"green-primary");
4206 if (option != (const char *) NULL)
4208 flags=ParseGeometry(option,&geometry_info);
4209 image->chromaticity.green_primary.x=geometry_info.rho;
4210 image->chromaticity.green_primary.y=geometry_info.sigma;
4211 if ((flags & SigmaValue) == 0)
4212 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4214 option=GetImageOption(image_info,"intent");
4215 if (option != (const char *) NULL)
4216 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4217 MagickIntentOptions,MagickFalse,option);
4218 option=GetImageOption(image_info,"interlace");
4219 if (option != (const char *) NULL)
4220 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4221 MagickFalse,option);
4222 option=GetImageOption(image_info,"interpolate");
4223 if (option != (const char *) NULL)
4224 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4225 MagickInterpolateOptions,MagickFalse,option);
4226 option=GetImageOption(image_info,"loop");
4227 if (option != (const char *) NULL)
4228 image->iterations=StringToUnsignedLong(option);
4229 option=GetImageOption(image_info,"mattecolor");
4230 if (option != (const char *) NULL)
4231 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4233 option=GetImageOption(image_info,"orient");
4234 if (option != (const char *) NULL)
4235 image->orientation=(OrientationType) ParseCommandOption(
4236 MagickOrientationOptions,MagickFalse,option);
4237 option=GetImageOption(image_info,"page");
4238 if (option != (const char *) NULL)
4243 geometry=GetPageGeometry(option);
4244 flags=ParseAbsoluteGeometry(geometry,&image->page);
4245 geometry=DestroyString(geometry);
4247 option=GetImageOption(image_info,"quality");
4248 if (option != (const char *) NULL)
4249 image->quality=StringToUnsignedLong(option);
4250 option=GetImageOption(image_info,"red-primary");
4251 if (option != (const char *) NULL)
4253 flags=ParseGeometry(option,&geometry_info);
4254 image->chromaticity.red_primary.x=geometry_info.rho;
4255 image->chromaticity.red_primary.y=geometry_info.sigma;
4256 if ((flags & SigmaValue) == 0)
4257 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4259 if (image_info->quality != UndefinedCompressionQuality)
4260 image->quality=image_info->quality;
4261 option=GetImageOption(image_info,"scene");
4262 if (option != (const char *) NULL)
4263 image->scene=StringToUnsignedLong(option);
4264 option=GetImageOption(image_info,"taint");
4265 if (option != (const char *) NULL)
4266 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4267 MagickFalse,option);
4268 option=GetImageOption(image_info,"tile-offset");
4269 if (option != (const char *) NULL)
4274 geometry=GetPageGeometry(option);
4275 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4276 geometry=DestroyString(geometry);
4278 option=GetImageOption(image_info,"transparent-color");
4279 if (option != (const char *) NULL)
4280 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4282 option=GetImageOption(image_info,"type");
4283 if (option != (const char *) NULL)
4284 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4286 option=GetImageOption(image_info,"units");
4287 if (option != (const char *) NULL)
4288 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4289 MagickFalse,option);
4291 units = image_info->units;
4292 if (units != UndefinedResolution)
4294 if (image->units != units)
4295 switch (image->units)
4297 case PixelsPerInchResolution:
4299 if (units == PixelsPerCentimeterResolution)
4301 image->x_resolution/=2.54;
4302 image->y_resolution/=2.54;
4306 case PixelsPerCentimeterResolution:
4308 if (units == PixelsPerInchResolution)
4310 image->x_resolution=(double) ((size_t) (100.0*2.54*
4311 image->x_resolution+0.5))/100.0;
4312 image->y_resolution=(double) ((size_t) (100.0*2.54*
4313 image->y_resolution+0.5))/100.0;
4322 option=GetImageOption(image_info,"white-point");
4323 if (option != (const char *) NULL)
4325 flags=ParseGeometry(option,&geometry_info);
4326 image->chromaticity.white_point.x=geometry_info.rho;
4327 image->chromaticity.white_point.y=geometry_info.sigma;
4328 if ((flags & SigmaValue) == 0)
4329 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4331 ResetImageOptionIterator(image_info);
4332 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4334 value=GetImageOption(image_info,option);
4335 if (value != (const char *) NULL)
4337 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4338 (void) SetImageArtifact(image,property,value);
4340 option=GetNextImageOption(image_info);