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->resolution.x=DefaultResolution;
189 image->resolution.y=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->resolution.x=geometry_info.rho;
246 image->resolution.y=geometry_info.sigma;
247 if ((flags & SigmaValue) == 0)
248 image->resolution.y=image->resolution.x;
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->channel_mask=image->channel_mask;
830 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
831 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
833 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
834 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
835 clone_image->progress_monitor=image->progress_monitor;
836 clone_image->client_data=image->client_data;
837 clone_image->reference_count=1;
838 clone_image->next=image->next;
839 clone_image->previous=image->previous;
840 clone_image->list=NewImageList();
841 clone_image->clip_mask=NewImageList();
842 clone_image->mask=NewImageList();
843 if (detach == MagickFalse)
844 clone_image->blob=ReferenceBlob(image->blob);
847 clone_image->next=NewImageList();
848 clone_image->previous=NewImageList();
849 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
851 clone_image->ping=image->ping;
852 clone_image->debug=IsEventLogging();
853 clone_image->semaphore=AllocateSemaphoreInfo();
854 if ((columns == 0) && (rows == 0))
856 if (image->montage != (char *) NULL)
857 (void) CloneString(&clone_image->montage,image->montage);
858 if (image->directory != (char *) NULL)
859 (void) CloneString(&clone_image->directory,image->directory);
860 if (image->clip_mask != (Image *) NULL)
861 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
863 if (image->mask != (Image *) NULL)
864 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
865 clone_image->cache=ReferencePixelCache(image->cache);
868 if ((columns == image->columns) && (rows == image->rows))
870 if (image->clip_mask != (Image *) NULL)
871 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
873 if (image->mask != (Image *) NULL)
874 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
876 scale=(MagickRealType) columns/(MagickRealType) image->columns;
877 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
878 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
879 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
880 scale=(MagickRealType) rows/(MagickRealType) image->rows;
881 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
882 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
883 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
884 clone_image->columns=columns;
885 clone_image->rows=rows;
886 clone_image->cache=ClonePixelCache(image->cache);
891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895 % C l o n e I m a g e I n f o %
899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
901 % CloneImageInfo() makes a copy of the given image info structure. If
902 % NULL is specified, a new image info structure is created initialized to
905 % The format of the CloneImageInfo method is:
907 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
909 % A description of each parameter follows:
911 % o image_info: the image info.
914 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
919 clone_info=AcquireImageInfo();
920 if (image_info == (ImageInfo *) NULL)
922 clone_info->compression=image_info->compression;
923 clone_info->temporary=image_info->temporary;
924 clone_info->adjoin=image_info->adjoin;
925 clone_info->antialias=image_info->antialias;
926 clone_info->scene=image_info->scene;
927 clone_info->number_scenes=image_info->number_scenes;
928 clone_info->depth=image_info->depth;
929 if (image_info->size != (char *) NULL)
930 (void) CloneString(&clone_info->size,image_info->size);
931 if (image_info->extract != (char *) NULL)
932 (void) CloneString(&clone_info->extract,image_info->extract);
933 if (image_info->scenes != (char *) NULL)
934 (void) CloneString(&clone_info->scenes,image_info->scenes);
935 if (image_info->page != (char *) NULL)
936 (void) CloneString(&clone_info->page,image_info->page);
937 clone_info->interlace=image_info->interlace;
938 clone_info->endian=image_info->endian;
939 clone_info->units=image_info->units;
940 clone_info->quality=image_info->quality;
941 if (image_info->sampling_factor != (char *) NULL)
942 (void) CloneString(&clone_info->sampling_factor,
943 image_info->sampling_factor);
944 if (image_info->server_name != (char *) NULL)
945 (void) CloneString(&clone_info->server_name,image_info->server_name);
946 if (image_info->font != (char *) NULL)
947 (void) CloneString(&clone_info->font,image_info->font);
948 if (image_info->texture != (char *) NULL)
949 (void) CloneString(&clone_info->texture,image_info->texture);
950 if (image_info->density != (char *) NULL)
951 (void) CloneString(&clone_info->density,image_info->density);
952 clone_info->pointsize=image_info->pointsize;
953 clone_info->fuzz=image_info->fuzz;
954 clone_info->background_color=image_info->background_color;
955 clone_info->border_color=image_info->border_color;
956 clone_info->matte_color=image_info->matte_color;
957 clone_info->transparent_color=image_info->transparent_color;
958 clone_info->dither=image_info->dither;
959 clone_info->monochrome=image_info->monochrome;
960 clone_info->colorspace=image_info->colorspace;
961 clone_info->type=image_info->type;
962 clone_info->orientation=image_info->orientation;
963 clone_info->preview_type=image_info->preview_type;
964 clone_info->group=image_info->group;
965 clone_info->ping=image_info->ping;
966 clone_info->verbose=image_info->verbose;
967 if (image_info->view != (char *) NULL)
968 (void) CloneString(&clone_info->view,image_info->view);
969 clone_info->progress_monitor=image_info->progress_monitor;
970 clone_info->client_data=image_info->client_data;
971 clone_info->cache=image_info->cache;
972 if (image_info->cache != (void *) NULL)
973 clone_info->cache=ReferencePixelCache(image_info->cache);
974 if (image_info->profile != (void *) NULL)
975 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
976 image_info->profile);
977 SetImageInfoFile(clone_info,image_info->file);
978 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
979 clone_info->stream=image_info->stream;
980 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
981 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
982 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
983 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
984 (void) CopyMagickString(clone_info->filename,image_info->filename,
986 clone_info->channel=image_info->channel;
988 (void) CloneImageOptions(clone_info,image_info);
989 clone_info->debug=IsEventLogging();
990 clone_info->signature=image_info->signature;
995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
999 % C o m b i n e I m a g e s %
1003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1005 % CombineImages() combines one or more images into a single image. The
1006 % grayscale value of the pixels of each image in the sequence is assigned in
1007 % order to the specified channels of the combined image. The typical
1008 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
1010 % The format of the CombineImages method is:
1012 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
1014 % A description of each parameter follows:
1016 % o image: the image.
1018 % o exception: return any errors or warnings in this structure.
1022 static inline size_t MagickMin(const size_t x,const size_t y)
1029 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1031 #define CombineImageTag "Combine/Image"
1049 Ensure the image are the same size.
1051 assert(image != (const Image *) NULL);
1052 assert(image->signature == MagickSignature);
1053 if (image->debug != MagickFalse)
1054 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1055 assert(exception != (ExceptionInfo *) NULL);
1056 assert(exception->signature == MagickSignature);
1057 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1058 if (combine_image == (Image *) NULL)
1059 return((Image *) NULL);
1060 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1062 combine_image=DestroyImage(combine_image);
1063 return((Image *) NULL);
1065 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1066 combine_image->matte=MagickTrue;
1072 combine_view=AcquireCacheView(combine_image);
1073 for (y=0; y < (ssize_t) combine_image->rows; y++)
1084 register const Quantum
1093 if (status == MagickFalse)
1095 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1097 if (pixels == (Quantum *) NULL)
1103 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1115 if (next == (Image *) NULL)
1117 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1118 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1119 combine_traits=GetPixelChannelMapTraits(combine_image,channel);
1120 if ((traits == UndefinedPixelTrait) ||
1121 (combine_traits == UndefinedPixelTrait))
1123 image_view=AcquireCacheView(next);
1124 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1125 if (p == (const Quantum *) NULL)
1128 for (x=0; x < (ssize_t) combine_image->columns; x++)
1130 if (x < (ssize_t) image->columns)
1133 p+=GetPixelChannels(image);
1135 q+=GetPixelChannels(combine_image);
1137 image_view=DestroyCacheView(image_view);
1138 next=GetNextImageInList(next);
1139 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1141 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1146 proceed=SetImageProgress(image,CombineImageTag,progress++,
1147 combine_image->rows);
1148 if (proceed == MagickFalse)
1153 combine_view=DestroyCacheView(combine_view);
1154 if (status == MagickFalse)
1155 combine_image=DestroyImage(combine_image);
1156 return(combine_image);
1160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1164 % D e s t r o y I m a g e %
1168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1170 % DestroyImage() dereferences an image, deallocating memory associated with
1171 % the image if the reference count becomes zero.
1173 % The format of the DestroyImage method is:
1175 % Image *DestroyImage(Image *image)
1177 % A description of each parameter follows:
1179 % o image: the image.
1182 MagickExport Image *DestroyImage(Image *image)
1190 assert(image != (Image *) NULL);
1191 assert(image->signature == MagickSignature);
1192 if (image->debug != MagickFalse)
1193 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1194 destroy=MagickFalse;
1195 LockSemaphoreInfo(image->semaphore);
1196 image->reference_count--;
1197 if (image->reference_count == 0)
1199 UnlockSemaphoreInfo(image->semaphore);
1200 if (destroy == MagickFalse)
1201 return((Image *) NULL);
1205 DestroyImagePixels(image);
1206 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1207 if (image->clip_mask != (Image *) NULL)
1208 image->clip_mask=DestroyImage(image->clip_mask);
1209 if (image->mask != (Image *) NULL)
1210 image->mask=DestroyImage(image->mask);
1211 if (image->montage != (char *) NULL)
1212 image->montage=DestroyString(image->montage);
1213 if (image->directory != (char *) NULL)
1214 image->directory=DestroyString(image->directory);
1215 if (image->colormap != (PixelInfo *) NULL)
1216 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1217 if (image->geometry != (char *) NULL)
1218 image->geometry=DestroyString(image->geometry);
1219 DestroyImageProfiles(image);
1220 DestroyImageProperties(image);
1221 DestroyImageArtifacts(image);
1222 if (image->ascii85 != (Ascii85Info*) NULL)
1223 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1225 if (image->semaphore != (SemaphoreInfo *) NULL)
1226 DestroySemaphoreInfo(&image->semaphore);
1227 image->signature=(~MagickSignature);
1228 image=(Image *) RelinquishMagickMemory(image);
1233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1237 % D e s t r o y I m a g e I n f o %
1241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1243 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1246 % The format of the DestroyImageInfo method is:
1248 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1250 % A description of each parameter follows:
1252 % o image_info: the image info.
1255 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1257 assert(image_info != (ImageInfo *) NULL);
1258 assert(image_info->signature == MagickSignature);
1259 if (image_info->debug != MagickFalse)
1260 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1261 image_info->filename);
1262 if (image_info->size != (char *) NULL)
1263 image_info->size=DestroyString(image_info->size);
1264 if (image_info->extract != (char *) NULL)
1265 image_info->extract=DestroyString(image_info->extract);
1266 if (image_info->scenes != (char *) NULL)
1267 image_info->scenes=DestroyString(image_info->scenes);
1268 if (image_info->page != (char *) NULL)
1269 image_info->page=DestroyString(image_info->page);
1270 if (image_info->sampling_factor != (char *) NULL)
1271 image_info->sampling_factor=DestroyString(
1272 image_info->sampling_factor);
1273 if (image_info->server_name != (char *) NULL)
1274 image_info->server_name=DestroyString(
1275 image_info->server_name);
1276 if (image_info->font != (char *) NULL)
1277 image_info->font=DestroyString(image_info->font);
1278 if (image_info->texture != (char *) NULL)
1279 image_info->texture=DestroyString(image_info->texture);
1280 if (image_info->density != (char *) NULL)
1281 image_info->density=DestroyString(image_info->density);
1282 if (image_info->view != (char *) NULL)
1283 image_info->view=DestroyString(image_info->view);
1284 if (image_info->cache != (void *) NULL)
1285 image_info->cache=DestroyPixelCache(image_info->cache);
1286 if (image_info->profile != (StringInfo *) NULL)
1287 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1288 image_info->profile);
1289 DestroyImageOptions(image_info);
1290 image_info->signature=(~MagickSignature);
1291 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1300 + D i s a s s o c i a t e I m a g e S t r e a m %
1304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1306 % DisassociateImageStream() disassociates the image stream.
1308 % The format of the DisassociateImageStream method is:
1310 % MagickBooleanType DisassociateImageStream(const Image *image)
1312 % A description of each parameter follows:
1314 % o image: the image.
1317 MagickExport void DisassociateImageStream(Image *image)
1319 assert(image != (const Image *) NULL);
1320 assert(image->signature == MagickSignature);
1321 if (image->debug != MagickFalse)
1322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1323 (void) DetachBlob(image->blob);
1327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1331 % G e t I m a g e A l p h a C h a n n e l %
1335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1338 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1341 % The format of the GetImageAlphaChannel method is:
1343 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1345 % A description of each parameter follows:
1347 % o image: the image.
1350 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1352 assert(image != (const Image *) NULL);
1353 if (image->debug != MagickFalse)
1354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1355 assert(image->signature == MagickSignature);
1356 return(image->matte);
1360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1364 % G e t I m a g e C l i p M a s k %
1368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1370 % GetImageClipMask() returns the clip path associated with the image.
1372 % The format of the GetImageClipMask method is:
1374 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1376 % A description of each parameter follows:
1378 % o image: the image.
1381 MagickExport Image *GetImageClipMask(const Image *image,
1382 ExceptionInfo *exception)
1384 assert(image != (const Image *) NULL);
1385 if (image->debug != MagickFalse)
1386 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1387 assert(image->signature == MagickSignature);
1388 if (image->clip_mask == (Image *) NULL)
1389 return((Image *) NULL);
1390 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1398 % G e t I m a g e I n f o %
1402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1404 % GetImageInfo() initializes image_info to default values.
1406 % The format of the GetImageInfo method is:
1408 % void GetImageInfo(ImageInfo *image_info)
1410 % A description of each parameter follows:
1412 % o image_info: the image info.
1415 MagickExport void GetImageInfo(ImageInfo *image_info)
1424 File and image dimension members.
1426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1427 assert(image_info != (ImageInfo *) NULL);
1428 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1429 image_info->adjoin=MagickTrue;
1430 image_info->interlace=NoInterlace;
1431 image_info->channel=DefaultChannels;
1432 image_info->quality=UndefinedCompressionQuality;
1433 image_info->antialias=MagickTrue;
1434 image_info->dither=MagickTrue;
1435 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1436 if (synchronize != (const char *) NULL)
1437 image_info->synchronize=IsMagickTrue(synchronize);
1438 exception=AcquireExceptionInfo();
1439 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1440 &image_info->background_color,exception);
1441 (void) QueryColorCompliance(BorderColor,AllCompliance,
1442 &image_info->border_color,exception);
1443 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1445 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1446 &image_info->transparent_color,exception);
1447 exception=DestroyExceptionInfo(exception);
1448 image_info->debug=IsEventLogging();
1449 image_info->signature=MagickSignature;
1453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1457 % G e t I m a g e I n f o F i l e %
1461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1463 % GetImageInfoFile() returns the image info file member.
1465 % The format of the GetImageInfoFile method is:
1467 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1469 % A description of each parameter follows:
1471 % o image_info: the image info.
1474 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1476 return(image_info->file);
1480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1484 % G e t I m a g e M a s k %
1488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1490 % GetImageMask() returns the mask associated with the image.
1492 % The format of the GetImageMask method is:
1494 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1496 % A description of each parameter follows:
1498 % o image: the image.
1501 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1503 assert(image != (const Image *) NULL);
1504 if (image->debug != MagickFalse)
1505 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1506 assert(image->signature == MagickSignature);
1507 if (image->mask == (Image *) NULL)
1508 return((Image *) NULL);
1509 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1517 + G e t I m a g e R e f e r e n c e C o u n t %
1521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1523 % GetImageReferenceCount() returns the image reference count.
1525 % The format of the GetReferenceCount method is:
1527 % ssize_t GetImageReferenceCount(Image *image)
1529 % A description of each parameter follows:
1531 % o image: the image.
1534 MagickExport ssize_t GetImageReferenceCount(Image *image)
1539 assert(image != (Image *) NULL);
1540 assert(image->signature == MagickSignature);
1541 if (image->debug != MagickFalse)
1542 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1543 LockSemaphoreInfo(image->semaphore);
1544 reference_count=image->reference_count;
1545 UnlockSemaphoreInfo(image->semaphore);
1546 return(reference_count);
1550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1554 % 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 %
1558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1560 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1561 % image. A virtual pixel is any pixel access that is outside the boundaries
1562 % of the image cache.
1564 % The format of the GetImageVirtualPixelMethod() method is:
1566 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1568 % A description of each parameter follows:
1570 % o image: the image.
1573 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1575 assert(image != (Image *) NULL);
1576 assert(image->signature == MagickSignature);
1577 if (image->debug != MagickFalse)
1578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1579 return(GetPixelCacheVirtualMethod(image));
1583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1587 % I n t e r p r e t I m a g e F i l e n a m e %
1591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1593 % InterpretImageFilename() interprets embedded characters in an image filename.
1594 % The filename length is returned.
1596 % The format of the InterpretImageFilename method is:
1598 % size_t InterpretImageFilename(const ImageInfo *image_info,
1599 % Image *image,const char *format,int value,char *filename,
1600 % ExceptionInfo *exception)
1602 % A description of each parameter follows.
1604 % o image_info: the image info..
1606 % o image: the image.
1608 % o format: A filename describing the format to use to write the numeric
1609 % argument. Only the first numeric format identifier is replaced.
1611 % o value: Numeric value to substitute into format filename.
1613 % o filename: return the formatted filename in this character buffer.
1615 % o exception: return any errors or warnings in this structure.
1618 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1619 Image *image,const char *format,int value,char *filename,
1620 ExceptionInfo *exception)
1637 canonical=MagickFalse;
1639 (void) CopyMagickString(filename,format,MaxTextExtent);
1640 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1653 value=(ssize_t) strtol(q,&q,10);
1665 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1666 (p-format)),p,value);
1668 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1669 canonical=MagickTrue;
1678 pattern[MaxTextExtent];
1695 if (strchr(p,']') == (char *) NULL)
1699 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1710 if (LocaleNCompare(pattern,"filename:",9) != 0)
1712 value=(const char *) NULL;
1713 if ((image_info != (const ImageInfo *) NULL) &&
1714 (image != (const Image *) NULL))
1715 value=GetMagickProperty(image_info,image,pattern,exception);
1717 if (image != (Image *) NULL)
1718 value=GetImageProperty(image,pattern,exception);
1720 if (image_info != (ImageInfo *) NULL)
1721 value=GetImageOption(image_info,pattern);
1722 if (value == (const char *) NULL)
1727 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1728 (MaxTextExtent-(p-format-length)));
1729 length+=strlen(pattern)-1;
1731 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1732 canonical=MagickTrue;
1742 for (q=filename; *q != '\0'; q++)
1743 if ((*q == '%') && (*(q+1) == '%'))
1745 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1746 canonical=MagickTrue;
1748 if (canonical == MagickFalse)
1749 (void) CopyMagickString(filename,format,MaxTextExtent);
1750 return(strlen(filename));
1754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1758 % I s H i g h D y n a m i c R a n g e I m a g e %
1762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1764 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1765 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1768 % The format of the IsHighDynamicRangeImage method is:
1770 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1771 % ExceptionInfo *exception)
1773 % A description of each parameter follows:
1775 % o image: the image.
1777 % o exception: return any errors or warnings in this structure.
1780 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1781 ExceptionInfo *exception)
1783 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1786 return(MagickFalse);
1797 assert(image != (Image *) NULL);
1798 assert(image->signature == MagickSignature);
1799 if (image->debug != MagickFalse)
1800 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1802 image_view=AcquireCacheView(image);
1803 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1804 #pragma omp parallel for schedule(dynamic,4) shared(status)
1806 for (y=0; y < (ssize_t) image->rows; y++)
1811 register const Quantum
1817 if (status == MagickFalse)
1819 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1820 if (p == (const Quantum *) NULL)
1826 for (x=0; x < (ssize_t) image->columns; x++)
1834 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1839 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1840 if (traits == UndefinedPixelTrait)
1842 pixel=(MagickRealType) p[i];
1843 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1844 (pixel != (QuantumAny) pixel))
1847 p+=GetPixelChannels(image);
1848 if (i < (ssize_t) GetPixelChannels(image))
1851 if (x < (ssize_t) image->columns)
1854 image_view=DestroyCacheView(image_view);
1855 return(status != MagickFalse ? MagickFalse : MagickTrue);
1860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 % I s I m a g e O b j e c t %
1868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1870 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1871 % set of image objects.
1873 % The format of the IsImageObject method is:
1875 % MagickBooleanType IsImageObject(const Image *image)
1877 % A description of each parameter follows:
1879 % o image: the image.
1882 MagickExport MagickBooleanType IsImageObject(const Image *image)
1884 register const Image
1887 assert(image != (Image *) NULL);
1888 if (image->debug != MagickFalse)
1889 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1890 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1891 if (p->signature != MagickSignature)
1892 return(MagickFalse);
1897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1901 % I s T a i n t I m a g e %
1905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1907 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1908 % since it was first constituted.
1910 % The format of the IsTaintImage method is:
1912 % MagickBooleanType IsTaintImage(const Image *image)
1914 % A description of each parameter follows:
1916 % o image: the image.
1919 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1922 magick[MaxTextExtent],
1923 filename[MaxTextExtent];
1925 register const Image
1928 assert(image != (Image *) NULL);
1929 if (image->debug != MagickFalse)
1930 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1931 assert(image->signature == MagickSignature);
1932 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1933 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1934 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1936 if (p->taint != MagickFalse)
1938 if (LocaleCompare(p->magick,magick) != 0)
1940 if (LocaleCompare(p->filename,filename) != 0)
1943 return(MagickFalse);
1947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1951 % M o d i f y I m a g e %
1955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1957 % ModifyImage() ensures that there is only a single reference to the image
1958 % to be modified, updating the provided image pointer to point to a clone of
1959 % the original image if necessary.
1961 % The format of the ModifyImage method is:
1963 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1965 % A description of each parameter follows:
1967 % o image: the image.
1969 % o exception: return any errors or warnings in this structure.
1972 MagickExport MagickBooleanType ModifyImage(Image **image,
1973 ExceptionInfo *exception)
1978 assert(image != (Image **) NULL);
1979 assert(*image != (Image *) NULL);
1980 assert((*image)->signature == MagickSignature);
1981 if ((*image)->debug != MagickFalse)
1982 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1983 if (GetImageReferenceCount(*image) <= 1)
1985 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1986 LockSemaphoreInfo((*image)->semaphore);
1987 (*image)->reference_count--;
1988 UnlockSemaphoreInfo((*image)->semaphore);
1994 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1998 % N e w M a g i c k I m a g e %
2002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2004 % NewMagickImage() creates a blank image canvas of the specified size and
2007 % The format of the NewMagickImage method is:
2009 % Image *NewMagickImage(const ImageInfo *image_info,
2010 % const size_t width,const size_t height,const PixelInfo *background,
2011 % ExceptionInfo *exception)
2013 % A description of each parameter follows:
2015 % o image: the image.
2017 % o width: the image width.
2019 % o height: the image height.
2021 % o background: the image color.
2023 % o exception: return any errors or warnings in this structure.
2026 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2027 const size_t width,const size_t height,const PixelInfo *background,
2028 ExceptionInfo *exception)
2042 assert(image_info != (const ImageInfo *) NULL);
2043 if (image_info->debug != MagickFalse)
2044 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2045 assert(image_info->signature == MagickSignature);
2046 assert(background != (const PixelInfo *) NULL);
2047 image=AcquireImage(image_info,exception);
2048 image->columns=width;
2050 image->colorspace=background->colorspace;
2051 image->matte=background->matte;
2052 image->fuzz=background->fuzz;
2053 image->depth=background->depth;
2055 image_view=AcquireCacheView(image);
2056 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2057 #pragma omp parallel for schedule(dynamic,4) shared(status)
2059 for (y=0; y < (ssize_t) image->rows; y++)
2067 if (status == MagickFalse)
2069 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2070 if (q == (Quantum *) NULL)
2075 for (x=0; x < (ssize_t) image->columns; x++)
2077 SetPixelPixelInfo(image,background,q);
2078 q+=GetPixelChannels(image);
2080 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2083 image_view=DestroyCacheView(image_view);
2084 if (status == MagickFalse)
2085 image=DestroyImage(image);
2090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2094 % R e f e r e n c e I m a g e %
2098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2100 % ReferenceImage() increments the reference count associated with an image
2101 % returning a pointer to the image.
2103 % The format of the ReferenceImage method is:
2105 % Image *ReferenceImage(Image *image)
2107 % A description of each parameter follows:
2109 % o image: the image.
2112 MagickExport Image *ReferenceImage(Image *image)
2114 assert(image != (Image *) NULL);
2115 if (image->debug != MagickFalse)
2116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2117 assert(image->signature == MagickSignature);
2118 LockSemaphoreInfo(image->semaphore);
2119 image->reference_count++;
2120 UnlockSemaphoreInfo(image->semaphore);
2125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2129 % R e s e t I m a g e P a g e %
2133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2135 % ResetImagePage() resets the image page canvas and position.
2137 % The format of the ResetImagePage method is:
2139 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2141 % A description of each parameter follows:
2143 % o image: the image.
2145 % o page: the relative page specification.
2148 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2156 assert(image != (Image *) NULL);
2157 assert(image->signature == MagickSignature);
2158 if (image->debug != MagickFalse)
2159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2160 flags=ParseAbsoluteGeometry(page,&geometry);
2161 if ((flags & WidthValue) != 0)
2163 if ((flags & HeightValue) == 0)
2164 geometry.height=geometry.width;
2165 image->page.width=geometry.width;
2166 image->page.height=geometry.height;
2168 if ((flags & AspectValue) != 0)
2170 if ((flags & XValue) != 0)
2171 image->page.x+=geometry.x;
2172 if ((flags & YValue) != 0)
2173 image->page.y+=geometry.y;
2177 if ((flags & XValue) != 0)
2179 image->page.x=geometry.x;
2180 if ((image->page.width == 0) && (geometry.x > 0))
2181 image->page.width=image->columns+geometry.x;
2183 if ((flags & YValue) != 0)
2185 image->page.y=geometry.y;
2186 if ((image->page.height == 0) && (geometry.y > 0))
2187 image->page.height=image->rows+geometry.y;
2194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2198 % S e p a r a t e I m a g e C h a n n e l %
2202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2204 % SeparateImage() separates a channel from the image and returns it as
2205 % a grayscale image. A channel is a particular color component of each pixel
2208 % The format of the SeparateImage method is:
2210 % MagickBooleanType SeparateImage(Image *image,ExceptionInfo *exception)
2212 % A description of each parameter follows:
2214 % o image: the image.
2216 % o exception: return any errors or warnings in this structure.
2219 MagickExport MagickBooleanType SeparateImage(Image *image,
2220 ExceptionInfo *exception)
2222 #define SeparateImageTag "Separate/Image"
2236 assert(image != (Image *) NULL);
2237 assert(image->signature == MagickSignature);
2238 if (image->debug != MagickFalse)
2239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2240 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2241 return(MagickFalse);
2243 Separate image channels.
2247 image_view=AcquireCacheView(image);
2248 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2249 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2251 for (y=0; y < (ssize_t) image->rows; y++)
2259 if (status == MagickFalse)
2261 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2262 if (q == (Quantum *) NULL)
2267 for (x=0; x < (ssize_t) image->columns; x++)
2272 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2280 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2281 if (traits == UndefinedPixelTrait)
2283 if ((traits & UpdatePixelTrait) != 0)
2284 for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
2287 q+=GetPixelChannels(image);
2289 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2291 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2296 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2297 #pragma omp critical (MagickCore_SeparateImage)
2299 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2300 if (proceed == MagickFalse)
2304 image_view=DestroyCacheView(image_view);
2305 (void) SetImageColorspace(image,RGBColorspace,exception);
2310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2314 % S e p a r a t e I m a g e s %
2318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2320 % SeparateImages() returns a separate grayscale image for each channel
2323 % The format of the SeparateImages method is:
2325 % MagickBooleanType SeparateImages(const Image *image,
2326 % ExceptionInfo *exception)
2328 % A description of each parameter follows:
2330 % o image: the image.
2332 % o exception: return any errors or warnings in this structure.
2335 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2347 assert(image != (Image *) NULL);
2348 assert(image->signature == MagickSignature);
2349 if (image->debug != MagickFalse)
2350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2351 images=NewImageList();
2352 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2357 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2358 if (traits == UndefinedPixelTrait)
2360 if ((traits & UpdatePixelTrait) != 0)
2362 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2363 if (separate_image != (Image *) NULL)
2365 channel_mask=SetPixelChannelMask(separate_image,
2366 (ChannelType) (1 << i));
2367 (void) SeparateImage(separate_image,exception);
2368 (void) SetPixelChannelMap(separate_image,channel_mask);
2369 AppendImageToList(&images,separate_image);
2377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2381 % S e t I m a g e A l p h a C h a n n e l %
2385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2387 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2390 % The format of the SetImageAlphaChannel method is:
2392 % MagickBooleanType SetImageAlphaChannel(Image *image,
2393 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2395 % A description of each parameter follows:
2397 % o image: the image.
2399 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2400 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2401 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2402 % TransparentAlphaChannel.
2404 % o exception: return any errors or warnings in this structure.
2407 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2408 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2416 assert(image != (Image *) NULL);
2417 if (image->debug != MagickFalse)
2418 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2419 assert(image->signature == MagickSignature);
2423 case ActivateAlphaChannel:
2425 image->matte=MagickTrue;
2428 case BackgroundAlphaChannel:
2440 Set transparent pixels to background color.
2442 if (image->matte == MagickFalse)
2444 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2446 background=image->background_color;
2447 image_view=AcquireCacheView(image);
2448 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2449 #pragma omp parallel for schedule(dynamic,4) shared(status)
2451 for (y=0; y < (ssize_t) image->rows; y++)
2459 if (status == MagickFalse)
2461 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2463 if (q == (Quantum *) NULL)
2468 for (x=0; x < (ssize_t) image->columns; x++)
2470 if (GetPixelAlpha(image,q) == TransparentAlpha)
2471 SetPixelPixelInfo(image,&background,q);
2472 q+=GetPixelChannels(image);
2474 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2477 image_view=DestroyCacheView(image_view);
2480 case DeactivateAlphaChannel:
2482 image->matte=MagickFalse;
2485 case ShapeAlphaChannel:
2486 case CopyAlphaChannel:
2489 Special usage case for SeparateImage(): copy grayscale color to
2492 channel_mask=SetPixelChannelMask(image,GrayChannel);
2493 status=SeparateImage(image,exception);
2494 (void) SetPixelChannelMask(image,channel_mask);
2495 image->matte=MagickTrue; /* make sure transparency is now on! */
2496 if (alpha_type == ShapeAlphaChannel)
2502 Reset all color channels to background color.
2504 background=image->background_color;
2505 (void) LevelImageColors(image,&background,&background,MagickTrue,
2510 case ExtractAlphaChannel:
2512 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2513 status=SeparateImage(image,exception);
2514 (void) SetPixelChannelMask(image,channel_mask);
2515 image->matte=MagickFalse;
2518 case OpaqueAlphaChannel:
2520 status=SetImageAlpha(image,OpaqueAlpha,exception);
2521 image->matte=MagickTrue;
2524 case TransparentAlphaChannel:
2526 status=SetImageAlpha(image,TransparentAlpha,exception);
2527 image->matte=MagickTrue;
2530 case SetAlphaChannel:
2532 if (image->matte == MagickFalse)
2534 status=SetImageAlpha(image,OpaqueAlpha,exception);
2535 image->matte=MagickTrue;
2539 case UndefinedAlphaChannel:
2542 if (status == MagickFalse)
2544 return(SyncImagePixelCache(image,exception));
2548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2552 % S e t I m a g e B a c k g r o u n d C o l o r %
2556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2558 % SetImageBackgroundColor() initializes the image pixels to the image
2559 % background color. The background color is defined by the background_color
2560 % member of the image structure.
2562 % The format of the SetImage method is:
2564 % MagickBooleanType SetImageBackgroundColor(Image *image,
2565 % ExceptionInfo *exception)
2567 % A description of each parameter follows:
2569 % o image: the image.
2571 % o exception: return any errors or warnings in this structure.
2574 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2575 ExceptionInfo *exception)
2592 assert(image != (Image *) NULL);
2593 if (image->debug != MagickFalse)
2594 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2595 assert(image->signature == MagickSignature);
2596 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2597 return(MagickFalse);
2598 if (image->background_color.alpha != OpaqueAlpha)
2599 image->matte=MagickTrue;
2600 background=image->background_color;
2601 SetPacketPixelInfo(image,&background,&pixel);
2603 Set image background color.
2607 image_view=AcquireCacheView(image);
2608 for (y=0; y < (ssize_t) image->rows; y++)
2616 if (status == MagickFalse)
2618 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2619 if (q == (Quantum *) NULL)
2624 for (x=0; x < (ssize_t) image->columns; x++)
2626 SetPixelPixelInfo(image,&background,q);
2627 q+=GetPixelChannels(image);
2629 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2632 image_view=DestroyCacheView(image_view);
2637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2641 % S e t I m a g e C o l o r %
2645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2647 % SetImageColor() set the entire image canvas to the specified color.
2649 % The format of the SetImageColor method is:
2651 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2652 % ExeptionInfo *exception)
2654 % A description of each parameter follows:
2656 % o image: the image.
2658 % o background: the image color.
2660 % o exception: return any errors or warnings in this structure.
2663 MagickExport MagickBooleanType SetImageColor(Image *image,
2664 const PixelInfo *color,ExceptionInfo *exception)
2675 assert(image != (Image *) NULL);
2676 if (image->debug != MagickFalse)
2677 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2678 assert(image->signature == MagickSignature);
2679 assert(color != (const PixelInfo *) NULL);
2680 image->colorspace=color->colorspace;
2681 image->matte=color->matte;
2682 image->fuzz=color->fuzz;
2683 image->depth=color->depth;
2685 image_view=AcquireCacheView(image);
2686 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2687 #pragma omp parallel for schedule(dynamic,4) shared(status)
2689 for (y=0; y < (ssize_t) image->rows; y++)
2697 if (status == MagickFalse)
2699 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2700 if (q == (Quantum *) NULL)
2705 for (x=0; x < (ssize_t) image->columns; x++)
2707 SetPixelPixelInfo(image,color,q);
2708 q+=GetPixelChannels(image);
2710 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2713 image_view=DestroyCacheView(image_view);
2718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2722 % S e t I m a g e S t o r a g e C l a s s %
2726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2728 % SetImageStorageClass() sets the image class: DirectClass for true color
2729 % images or PseudoClass for colormapped images.
2731 % The format of the SetImageStorageClass method is:
2733 % MagickBooleanType SetImageStorageClass(Image *image,
2734 % const ClassType storage_class,ExceptionInfo *exception)
2736 % A description of each parameter follows:
2738 % o image: the image.
2740 % o storage_class: The image class.
2742 % o exception: return any errors or warnings in this structure.
2745 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2746 const ClassType storage_class,ExceptionInfo *exception)
2748 image->storage_class=storage_class;
2749 return(SyncImagePixelCache(image,exception));
2753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2757 % S e t I m a g e C l i p M a s k %
2761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2763 % SetImageClipMask() associates a clip path with the image. The clip path
2764 % must be the same dimensions as the image. Set any pixel component of
2765 % the clip path to TransparentAlpha to prevent that corresponding image
2766 % pixel component from being updated when SyncAuthenticPixels() is applied.
2768 % The format of the SetImageClipMask method is:
2770 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2771 % ExceptionInfo *exception)
2773 % A description of each parameter follows:
2775 % o image: the image.
2777 % o clip_mask: the image clip path.
2779 % o exception: return any errors or warnings in this structure.
2782 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2783 const Image *clip_mask,ExceptionInfo *exception)
2785 assert(image != (Image *) NULL);
2786 if (image->debug != MagickFalse)
2787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2788 assert(image->signature == MagickSignature);
2789 if (clip_mask != (const Image *) NULL)
2790 if ((clip_mask->columns != image->columns) ||
2791 (clip_mask->rows != image->rows))
2792 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2793 if (image->clip_mask != (Image *) NULL)
2794 image->clip_mask=DestroyImage(image->clip_mask);
2795 image->clip_mask=NewImageList();
2796 if (clip_mask == (Image *) NULL)
2798 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2799 return(MagickFalse);
2800 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,exception);
2801 if (image->clip_mask == (Image *) NULL)
2802 return(MagickFalse);
2807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2811 % S e t I m a g e E x t e n t %
2815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2817 % SetImageExtent() sets the image size (i.e. columns & rows).
2819 % The format of the SetImageExtent method is:
2821 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2822 % const size_t rows,ExceptionInfo *exception)
2824 % A description of each parameter follows:
2826 % o image: the image.
2828 % o columns: The image width in pixels.
2830 % o rows: The image height in pixels.
2832 % o exception: return any errors or warnings in this structure.
2835 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2836 const size_t rows,ExceptionInfo *exception)
2838 if ((columns == 0) || (rows == 0))
2839 return(MagickFalse);
2840 image->columns=columns;
2842 return(SyncImagePixelCache(image,exception));
2846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2850 + S e t I m a g e I n f o %
2854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2856 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2857 % It is set to a type of image format based on the prefix or suffix of the
2858 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2859 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2860 % precendence over the suffix. Use an optional index enclosed in brackets
2861 % after a file name to specify a desired scene of a multi-resolution image
2862 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2863 % indicates success.
2865 % The format of the SetImageInfo method is:
2867 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2868 % const unsigned int frames,ExceptionInfo *exception)
2870 % A description of each parameter follows:
2872 % o image_info: the image info.
2874 % o frames: the number of images you intend to write.
2876 % o exception: return any errors or warnings in this structure.
2879 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2880 const unsigned int frames,ExceptionInfo *exception)
2883 extension[MaxTextExtent],
2884 filename[MaxTextExtent],
2885 magic[MaxTextExtent],
2887 subimage[MaxTextExtent];
2911 magick[2*MaxTextExtent];
2914 Look for 'image.format' in filename.
2916 assert(image_info != (ImageInfo *) NULL);
2917 assert(image_info->signature == MagickSignature);
2918 if (image_info->debug != MagickFalse)
2919 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2920 image_info->filename);
2924 GetPathComponent(image_info->filename,SubimagePath,subimage);
2925 if (*subimage != '\0')
2928 Look for scene specification (e.g. img0001.pcd[4]).
2930 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2932 if (IsGeometry(subimage) != MagickFalse)
2933 (void) CloneString(&image_info->extract,subimage);
2941 (void) CloneString(&image_info->scenes,subimage);
2942 image_info->scene=StringToUnsignedLong(image_info->scenes);
2943 image_info->number_scenes=image_info->scene;
2944 p=image_info->scenes;
2945 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2947 while ((isspace((int) ((unsigned char) *p)) != 0) ||
2950 first=(size_t) strtol(p,&q,10);
2952 while (isspace((int) ((unsigned char) *q)) != 0)
2955 last=(size_t) strtol(q+1,&q,10);
2958 if (first < image_info->scene)
2959 image_info->scene=first;
2960 if (last > image_info->number_scenes)
2961 image_info->number_scenes=last;
2964 image_info->number_scenes-=image_info->scene-1;
2969 GetPathComponent(image_info->filename,ExtensionPath,extension);
2970 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2971 if (*extension != '\0')
2972 if ((LocaleCompare(extension,"gz") == 0) ||
2973 (LocaleCompare(extension,"Z") == 0) ||
2974 (LocaleCompare(extension,"wmz") == 0))
2977 path[MaxTextExtent];
2979 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2980 path[strlen(path)-strlen(extension)-1]='\0';
2981 GetPathComponent(path,ExtensionPath,extension);
2984 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2985 if (*extension != '\0')
2986 if (LocaleCompare(extension,"bz2") == 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 image_info->affirm=MagickFalse;
2997 sans_exception=AcquireExceptionInfo();
2998 if (*extension != '\0')
3007 *format_type_formats[] =
3030 User specified image format.
3032 (void) CopyMagickString(magic,extension,MaxTextExtent);
3035 Look for explicit image formats.
3037 format_type=UndefinedFormatType;
3039 while ((format_type == UndefinedFormatType) &&
3040 (format_type_formats[i] != (char *) NULL))
3042 if ((*magic == *format_type_formats[i]) &&
3043 (LocaleCompare(magic,format_type_formats[i]) == 0))
3044 format_type=ExplicitFormatType;
3047 magick_info=GetMagickInfo(magic,sans_exception);
3048 if ((magick_info != (const MagickInfo *) NULL) &&
3049 (magick_info->format_type != UndefinedFormatType))
3050 format_type=magick_info->format_type;
3051 if (format_type == UndefinedFormatType)
3052 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3054 if (format_type == ExplicitFormatType)
3056 image_info->affirm=MagickTrue;
3057 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3059 if (LocaleCompare(magic,"RGB") == 0)
3060 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3063 Look for explicit 'format:image' in filename.
3066 GetPathComponent(image_info->filename,MagickPath,magic);
3068 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3072 User specified image format.
3075 if (IsMagickConflict(magic) == MagickFalse)
3077 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3078 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3079 image_info->affirm=MagickTrue;
3081 image_info->temporary=MagickTrue;
3084 magick_info=GetMagickInfo(magic,sans_exception);
3085 sans_exception=DestroyExceptionInfo(sans_exception);
3086 if ((magick_info == (const MagickInfo *) NULL) ||
3087 (GetMagickEndianSupport(magick_info) == MagickFalse))
3088 image_info->endian=UndefinedEndian;
3089 GetPathComponent(image_info->filename,CanonicalPath,filename);
3090 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3091 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3094 Test for multiple image support (e.g. image%02d.png).
3096 (void) InterpretImageFilename(image_info,(Image *) NULL,
3097 image_info->filename,(int) image_info->scene,filename,exception);
3098 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3099 (strchr(filename,'%') == (char *) NULL))
3100 image_info->adjoin=MagickFalse;
3102 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3105 Some image formats do not support multiple frames per file.
3107 magick_info=GetMagickInfo(magic,exception);
3108 if (magick_info != (const MagickInfo *) NULL)
3109 if (GetMagickAdjoin(magick_info) == MagickFalse)
3110 image_info->adjoin=MagickFalse;
3112 if (image_info->affirm != MagickFalse)
3117 Determine the image format from the first few bytes of the file.
3119 image=AcquireImage(image_info,exception);
3120 (void) CopyMagickString(image->filename,image_info->filename,
3122 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3123 if (status == MagickFalse)
3125 image=DestroyImage(image);
3126 return(MagickFalse);
3128 if ((IsBlobSeekable(image) == MagickFalse) ||
3129 (IsBlobExempt(image) != MagickFalse))
3132 Copy standard input or pipe to temporary file.
3135 status=ImageToFile(image,filename,exception);
3136 (void) CloseBlob(image);
3137 if (status == MagickFalse)
3139 image=DestroyImage(image);
3140 return(MagickFalse);
3142 SetImageInfoFile(image_info,(FILE *) NULL);
3143 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3144 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3145 if (status == MagickFalse)
3147 image=DestroyImage(image);
3148 return(MagickFalse);
3150 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3151 image_info->temporary=MagickTrue;
3153 (void) ResetMagickMemory(magick,0,sizeof(magick));
3154 count=ReadBlob(image,2*MaxTextExtent,magick);
3155 (void) CloseBlob(image);
3156 image=DestroyImage(image);
3158 Check magic.xml configuration file.
3160 sans_exception=AcquireExceptionInfo();
3161 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3162 if ((magic_info != (const MagicInfo *) NULL) &&
3163 (GetMagicName(magic_info) != (char *) NULL))
3165 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3167 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3168 if ((magick_info == (const MagickInfo *) NULL) ||
3169 (GetMagickEndianSupport(magick_info) == MagickFalse))
3170 image_info->endian=UndefinedEndian;
3171 sans_exception=DestroyExceptionInfo(sans_exception);
3174 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3175 if ((magick_info == (const MagickInfo *) NULL) ||
3176 (GetMagickEndianSupport(magick_info) == MagickFalse))
3177 image_info->endian=UndefinedEndian;
3178 sans_exception=DestroyExceptionInfo(sans_exception);
3184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3188 % S e t I m a g e I n f o B l o b %
3192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3194 % SetImageInfoBlob() sets the image info blob member.
3196 % The format of the SetImageInfoBlob method is:
3198 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3199 % const size_t length)
3201 % A description of each parameter follows:
3203 % o image_info: the image info.
3207 % o length: the blob length.
3210 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3211 const size_t length)
3213 assert(image_info != (ImageInfo *) NULL);
3214 assert(image_info->signature == MagickSignature);
3215 if (image_info->debug != MagickFalse)
3216 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3217 image_info->filename);
3218 image_info->blob=(void *) blob;
3219 image_info->length=length;
3223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3227 % S e t I m a g e I n f o F i l e %
3231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3233 % SetImageInfoFile() sets the image info file member.
3235 % The format of the SetImageInfoFile method is:
3237 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3239 % A description of each parameter follows:
3241 % o image_info: the image info.
3246 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3248 assert(image_info != (ImageInfo *) NULL);
3249 assert(image_info->signature == MagickSignature);
3250 if (image_info->debug != MagickFalse)
3251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3252 image_info->filename);
3253 image_info->file=file;
3257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3261 % S e t I m a g e M a s k %
3265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3267 % SetImageMask() associates a mask with the image. The mask must be the same
3268 % dimensions as the image.
3270 % The format of the SetImageMask method is:
3272 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3273 % ExceptionInfo *exception)
3275 % A description of each parameter follows:
3277 % o image: the image.
3279 % o mask: the image mask.
3281 % o exception: return any errors or warnings in this structure.
3284 MagickExport MagickBooleanType SetImageMask(Image *image,
3285 const Image *mask,ExceptionInfo *exception)
3287 assert(image != (Image *) NULL);
3288 if (image->debug != MagickFalse)
3289 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3290 assert(image->signature == MagickSignature);
3291 if (mask != (const Image *) NULL)
3292 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3293 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3294 if (image->mask != (Image *) NULL)
3295 image->mask=DestroyImage(image->mask);
3296 image->mask=NewImageList();
3297 if (mask == (Image *) NULL)
3299 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3300 return(MagickFalse);
3301 image->mask=CloneImage(mask,0,0,MagickTrue,exception);
3302 if (image->mask == (Image *) NULL)
3303 return(MagickFalse);
3308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3312 % S e t I m a g e A l p h a %
3316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3318 % SetImageAlpha() sets the alpha levels of the image.
3320 % The format of the SetImageAlpha method is:
3322 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3323 % ExceptionInfo *exception)
3325 % A description of each parameter follows:
3327 % o image: the image.
3329 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3330 % fully transparent.
3333 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3334 ExceptionInfo *exception)
3345 assert(image != (Image *) NULL);
3346 if (image->debug != MagickFalse)
3347 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3348 assert(image->signature == MagickSignature);
3349 image->matte=alpha != OpaqueAlpha ? MagickTrue : MagickFalse;
3351 image_view=AcquireCacheView(image);
3352 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3353 #pragma omp parallel for schedule(dynamic,4) shared(status)
3355 for (y=0; y < (ssize_t) image->rows; y++)
3363 if (status == MagickFalse)
3365 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3366 if (q == (Quantum *) NULL)
3371 for (x=0; x < (ssize_t) image->columns; x++)
3373 SetPixelAlpha(image,alpha,q);
3374 q+=GetPixelChannels(image);
3376 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3379 image_view=DestroyCacheView(image_view);
3384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3388 % S e t I m a g e T y p e %
3392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3394 % SetImageType() sets the type of image. Choose from these types:
3396 % Bilevel Grayscale GrayscaleMatte
3397 % Palette PaletteMatte TrueColor
3398 % TrueColorMatte ColorSeparation ColorSeparationMatte
3401 % The format of the SetImageType method is:
3403 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3404 % ExceptionInfo *exception)
3406 % A description of each parameter follows:
3408 % o image: the image.
3410 % o type: Image type.
3412 % o exception: return any errors or warnings in this structure.
3415 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3416 ExceptionInfo *exception)
3430 assert(image != (Image *) NULL);
3431 if (image->debug != MagickFalse)
3432 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3433 assert(image->signature == MagickSignature);
3435 image_info=AcquireImageInfo();
3436 image_info->dither=image->dither;
3437 artifact=GetImageArtifact(image,"dither");
3438 if (artifact != (const char *) NULL)
3439 (void) SetImageOption(image_info,"dither",artifact);
3444 if (IsImageGray(image,exception) == MagickFalse)
3445 status=TransformImageColorspace(image,GRAYColorspace,exception);
3446 if (IsImageMonochrome(image,exception) == MagickFalse)
3448 quantize_info=AcquireQuantizeInfo(image_info);
3449 quantize_info->number_colors=2;
3450 quantize_info->colorspace=GRAYColorspace;
3451 status=QuantizeImage(quantize_info,image,exception);
3452 quantize_info=DestroyQuantizeInfo(quantize_info);
3454 image->matte=MagickFalse;
3459 if (IsImageGray(image,exception) == MagickFalse)
3460 status=TransformImageColorspace(image,GRAYColorspace,exception);
3461 image->matte=MagickFalse;
3464 case GrayscaleMatteType:
3466 if (IsImageGray(image,exception) == MagickFalse)
3467 status=TransformImageColorspace(image,GRAYColorspace,exception);
3468 if (image->matte == MagickFalse)
3469 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3474 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3475 status=TransformImageColorspace(image,RGBColorspace,exception);
3476 if ((image->storage_class == DirectClass) || (image->colors > 256))
3478 quantize_info=AcquireQuantizeInfo(image_info);
3479 quantize_info->number_colors=256;
3480 status=QuantizeImage(quantize_info,image,exception);
3481 quantize_info=DestroyQuantizeInfo(quantize_info);
3483 image->matte=MagickFalse;
3486 case PaletteBilevelMatteType:
3491 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3492 status=TransformImageColorspace(image,RGBColorspace,exception);
3493 if (image->matte == MagickFalse)
3494 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3495 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3496 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
3497 (void) SetPixelChannelMask(image,channel_mask);
3498 quantize_info=AcquireQuantizeInfo(image_info);
3499 status=QuantizeImage(quantize_info,image,exception);
3500 quantize_info=DestroyQuantizeInfo(quantize_info);
3503 case PaletteMatteType:
3505 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3506 status=TransformImageColorspace(image,RGBColorspace,exception);
3507 if (image->matte == MagickFalse)
3508 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3509 quantize_info=AcquireQuantizeInfo(image_info);
3510 quantize_info->colorspace=TransparentColorspace;
3511 status=QuantizeImage(quantize_info,image,exception);
3512 quantize_info=DestroyQuantizeInfo(quantize_info);
3517 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3518 status=TransformImageColorspace(image,RGBColorspace,exception);
3519 if (image->storage_class != DirectClass)
3520 status=SetImageStorageClass(image,DirectClass,exception);
3521 image->matte=MagickFalse;
3524 case TrueColorMatteType:
3526 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3527 status=TransformImageColorspace(image,RGBColorspace,exception);
3528 if (image->storage_class != DirectClass)
3529 status=SetImageStorageClass(image,DirectClass,exception);
3530 if (image->matte == MagickFalse)
3531 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3534 case ColorSeparationType:
3536 if (image->colorspace != CMYKColorspace)
3538 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3539 status=TransformImageColorspace(image,RGBColorspace,exception);
3540 status=TransformImageColorspace(image,CMYKColorspace,exception);
3542 if (image->storage_class != DirectClass)
3543 status=SetImageStorageClass(image,DirectClass,exception);
3544 image->matte=MagickFalse;
3547 case ColorSeparationMatteType:
3549 if (image->colorspace != CMYKColorspace)
3551 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3552 status=TransformImageColorspace(image,RGBColorspace,exception);
3553 status=TransformImageColorspace(image,CMYKColorspace,exception);
3555 if (image->storage_class != DirectClass)
3556 status=SetImageStorageClass(image,DirectClass,exception);
3557 if (image->matte == MagickFalse)
3558 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3566 image_info=DestroyImageInfo(image_info);
3571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3575 % 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 %
3579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3581 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3582 % image and returns the previous setting. A virtual pixel is any pixel access
3583 % that is outside the boundaries of the image cache.
3585 % The format of the SetImageVirtualPixelMethod() method is:
3587 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3588 % const VirtualPixelMethod virtual_pixel_method)
3590 % A description of each parameter follows:
3592 % o image: the image.
3594 % o virtual_pixel_method: choose the type of virtual pixel.
3597 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3598 const VirtualPixelMethod virtual_pixel_method)
3600 assert(image != (const Image *) NULL);
3601 assert(image->signature == MagickSignature);
3602 if (image->debug != MagickFalse)
3603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3604 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3612 % S m u s h I m a g e s %
3616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3618 % SmushImages() takes all images from the current image pointer to the end
3619 % of the image list and smushes them to each other top-to-bottom if the
3620 % stack parameter is true, otherwise left-to-right.
3622 % The current gravity setting now effects how the image is justified in the
3625 % The format of the SmushImages method is:
3627 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3628 % ExceptionInfo *exception)
3630 % A description of each parameter follows:
3632 % o images: the image sequence.
3634 % o stack: A value other than 0 stacks the images top-to-bottom.
3636 % o offset: minimum distance in pixels between images.
3638 % o exception: return any errors or warnings in this structure.
3642 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3643 const ssize_t offset,ExceptionInfo *exception)
3657 register const Quantum
3670 if (images->previous == (Image *) NULL)
3673 SetGeometry(smush_image,&right_geometry);
3674 GravityAdjustGeometry(right_image->columns,right_image->rows,
3675 right_image->gravity,&right_geometry);
3676 left_image=images->previous;
3677 SetGeometry(smush_image,&left_geometry);
3678 GravityAdjustGeometry(left_image->columns,left_image->rows,
3679 left_image->gravity,&left_geometry);
3680 gap=right_image->columns;
3681 left_view=AcquireCacheView(left_image);
3682 right_view=AcquireCacheView(right_image);
3683 for (y=0; y < (ssize_t) smush_image->rows; y++)
3685 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3687 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3688 if ((p == (const Quantum *) NULL) ||
3689 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3690 ((left_image->columns-x-1) >= gap))
3693 i=(ssize_t) left_image->columns-x-1;
3694 for (x=0; x < (ssize_t) right_image->columns; x++)
3696 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3698 if ((p == (const Quantum *) NULL) ||
3699 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3700 ((x+i) >= (ssize_t) gap))
3703 if ((x+i) < (ssize_t) gap)
3706 right_view=DestroyCacheView(right_view);
3707 left_view=DestroyCacheView(left_view);
3708 if (y < (ssize_t) smush_image->rows)
3710 return((ssize_t) gap-offset);
3713 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3714 const ssize_t offset,ExceptionInfo *exception)
3728 register const Quantum
3741 if (images->previous == (Image *) NULL)
3743 bottom_image=images;
3744 SetGeometry(smush_image,&bottom_geometry);
3745 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3746 bottom_image->gravity,&bottom_geometry);
3747 top_image=images->previous;
3748 SetGeometry(smush_image,&top_geometry);
3749 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3751 gap=bottom_image->rows;
3752 top_view=AcquireCacheView(top_image);
3753 bottom_view=AcquireCacheView(bottom_image);
3754 for (x=0; x < (ssize_t) smush_image->columns; x++)
3756 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3758 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3759 if ((p == (const Quantum *) NULL) ||
3760 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3761 ((top_image->rows-y-1) >= gap))
3764 i=(ssize_t) top_image->rows-y-1;
3765 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3767 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3769 if ((p == (const Quantum *) NULL) ||
3770 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3771 ((y+i) >= (ssize_t) gap))
3774 if ((y+i) < (ssize_t) gap)
3777 bottom_view=DestroyCacheView(bottom_view);
3778 top_view=DestroyCacheView(top_view);
3779 if (x < (ssize_t) smush_image->columns)
3781 return((ssize_t) gap-offset);
3784 MagickExport Image *SmushImages(const Image *images,
3785 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3787 #define SmushImageTag "Smush/Image"
3809 register const Image
3822 Compute maximum area of smushed area.
3824 assert(images != (Image *) NULL);
3825 assert(images->signature == MagickSignature);
3826 if (images->debug != MagickFalse)
3827 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3828 assert(exception != (ExceptionInfo *) NULL);
3829 assert(exception->signature == MagickSignature);
3833 width=image->columns;
3835 next=GetNextImageInList(image);
3836 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3838 if (next->matte != MagickFalse)
3841 if (stack != MagickFalse)
3843 if (next->columns > width)
3844 width=next->columns;
3846 if (next->previous != (Image *) NULL)
3850 width+=next->columns;
3851 if (next->previous != (Image *) NULL)
3853 if (next->rows > height)
3859 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3860 if (smush_image == (Image *) NULL)
3861 return((Image *) NULL);
3862 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3864 smush_image=DestroyImage(smush_image);
3865 return((Image *) NULL);
3867 smush_image->matte=matte;
3868 (void) SetImageBackgroundColor(smush_image,exception);
3872 smush_view=AcquireCacheView(smush_image);
3873 for (n=0; n < (MagickOffsetType) number_images; n++)
3875 SetGeometry(smush_image,&geometry);
3876 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3877 if (stack != MagickFalse)
3879 x_offset-=geometry.x;
3880 y_offset-=SmushYGap(smush_image,image,offset,exception);
3884 x_offset-=SmushXGap(smush_image,image,offset,exception);
3885 y_offset-=geometry.y;
3887 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
3889 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3890 if (proceed == MagickFalse)
3892 if (stack == MagickFalse)
3894 x_offset+=(ssize_t) image->columns;
3900 y_offset+=(ssize_t) image->rows;
3902 image=GetNextImageInList(image);
3904 if (stack == MagickFalse)
3905 smush_image->columns=(size_t) x_offset;
3907 smush_image->rows=(size_t) y_offset;
3908 smush_view=DestroyCacheView(smush_view);
3909 if (status == MagickFalse)
3910 smush_image=DestroyImage(smush_image);
3911 return(smush_image);
3915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3919 % S t r i p I m a g e %
3923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3925 % StripImage() strips an image of all profiles and comments.
3927 % The format of the StripImage method is:
3929 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3931 % A description of each parameter follows:
3933 % o image: the image.
3935 % o exception: return any errors or warnings in this structure.
3938 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3943 assert(image != (Image *) NULL);
3944 if (image->debug != MagickFalse)
3945 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3947 DestroyImageProfiles(image);
3948 (void) DeleteImageProperty(image,"comment");
3949 (void) DeleteImageProperty(image,"date:create");
3950 (void) DeleteImageProperty(image,"date:modify");
3951 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
3956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3960 + S y n c I m a g e %
3964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3966 % SyncImage() initializes the red, green, and blue intensities of each pixel
3967 % as defined by the colormap index.
3969 % The format of the SyncImage method is:
3971 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3973 % A description of each parameter follows:
3975 % o image: the image.
3977 % o exception: return any errors or warnings in this structure.
3981 static inline Quantum PushColormapIndex(Image *image,
3982 const size_t index,MagickBooleanType *range_exception)
3984 if (index < image->colors)
3985 return((Quantum) index);
3986 *range_exception=MagickTrue;
3987 return((Quantum) 0);
3990 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4002 assert(image != (Image *) NULL);
4003 if (image->debug != MagickFalse)
4004 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4005 assert(image->signature == MagickSignature);
4006 if (image->storage_class == DirectClass)
4007 return(MagickFalse);
4008 range_exception=MagickFalse;
4010 image_view=AcquireCacheView(image);
4011 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4012 #pragma omp parallel for schedule(dynamic,4) shared(status)
4014 for (y=0; y < (ssize_t) image->rows; y++)
4025 if (status == MagickFalse)
4027 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4028 if (q == (Quantum *) NULL)
4033 for (x=0; x < (ssize_t) image->columns; x++)
4035 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4037 SetPixelPixelInfo(image,image->colormap+(ssize_t) index,q);
4038 q+=GetPixelChannels(image);
4040 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4043 image_view=DestroyCacheView(image_view);
4044 if (range_exception != MagickFalse)
4045 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
4046 "InvalidColormapIndex","`%s'",image->filename);
4051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4055 % S y n c I m a g e S e t t i n g s %
4059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4061 % SyncImageSettings() sync the image info options to the image.
4063 % The format of the SyncImageSettings method is:
4065 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4066 % Image *image,ExceptionInfo *exception)
4067 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4068 % Image *image,ExceptionInfo *exception)
4070 % A description of each parameter follows:
4072 % o image_info: the image info.
4074 % o image: the image.
4076 % o exception: return any errors or warnings in this structure.
4080 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4081 Image *images,ExceptionInfo *exception)
4086 assert(image_info != (const ImageInfo *) NULL);
4087 assert(image_info->signature == MagickSignature);
4088 assert(images != (Image *) NULL);
4089 assert(images->signature == MagickSignature);
4090 if (images->debug != MagickFalse)
4091 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4093 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4094 (void) SyncImageSettings(image_info,image,exception);
4095 (void) DeleteImageOption(image_info,"page");
4099 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4100 Image *image,ExceptionInfo *exception)
4103 property[MaxTextExtent];
4121 assert(image_info != (const ImageInfo *) NULL);
4122 assert(image_info->signature == MagickSignature);
4123 assert(image != (Image *) NULL);
4124 assert(image->signature == MagickSignature);
4125 if (image->debug != MagickFalse)
4126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4127 option=GetImageOption(image_info,"background");
4128 if (option != (const char *) NULL)
4129 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4131 option=GetImageOption(image_info,"bias");
4132 if (option != (const char *) NULL)
4133 image->bias=InterpretLocaleInterval(option,QuantumRange);
4134 option=GetImageOption(image_info,"black-point-compensation");
4135 if (option != (const char *) NULL)
4136 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4137 MagickBooleanOptions,MagickFalse,option);
4138 option=GetImageOption(image_info,"blue-primary");
4139 if (option != (const char *) NULL)
4141 flags=ParseGeometry(option,&geometry_info);
4142 image->chromaticity.blue_primary.x=geometry_info.rho;
4143 image->chromaticity.blue_primary.y=geometry_info.sigma;
4144 if ((flags & SigmaValue) == 0)
4145 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4147 option=GetImageOption(image_info,"bordercolor");
4148 if (option != (const char *) NULL)
4149 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4151 option=GetImageOption(image_info,"compose");
4152 if (option != (const char *) NULL)
4153 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4154 MagickFalse,option);
4155 option=GetImageOption(image_info,"compress");
4156 if (option != (const char *) NULL)
4157 image->compression=(CompressionType) ParseCommandOption(
4158 MagickCompressOptions,MagickFalse,option);
4159 option=GetImageOption(image_info,"debug");
4160 if (option != (const char *) NULL)
4161 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4162 MagickFalse,option);
4163 option=GetImageOption(image_info,"density");
4164 if (option != (const char *) NULL)
4169 flags=ParseGeometry(option,&geometry_info);
4170 image->resolution.x=geometry_info.rho;
4171 image->resolution.y=geometry_info.sigma;
4172 if ((flags & SigmaValue) == 0)
4173 image->resolution.y=image->resolution.x;
4175 option=GetImageOption(image_info,"depth");
4176 if (option != (const char *) NULL)
4177 image->depth=StringToUnsignedLong(option);
4178 option=GetImageOption(image_info,"endian");
4179 if (option != (const char *) NULL)
4180 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4181 MagickFalse,option);
4182 option=GetImageOption(image_info,"filter");
4183 if (option != (const char *) NULL)
4184 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4185 MagickFalse,option);
4186 option=GetImageOption(image_info,"fuzz");
4187 if (option != (const char *) NULL)
4188 image->fuzz=InterpretLocaleInterval(option,(double) QuantumRange+1.0);
4189 option=GetImageOption(image_info,"gravity");
4190 if (option != (const char *) NULL)
4191 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4192 MagickFalse,option);
4193 option=GetImageOption(image_info,"green-primary");
4194 if (option != (const char *) NULL)
4196 flags=ParseGeometry(option,&geometry_info);
4197 image->chromaticity.green_primary.x=geometry_info.rho;
4198 image->chromaticity.green_primary.y=geometry_info.sigma;
4199 if ((flags & SigmaValue) == 0)
4200 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4202 option=GetImageOption(image_info,"intent");
4203 if (option != (const char *) NULL)
4204 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4205 MagickIntentOptions,MagickFalse,option);
4206 option=GetImageOption(image_info,"interlace");
4207 if (option != (const char *) NULL)
4208 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4209 MagickFalse,option);
4210 option=GetImageOption(image_info,"interpolate");
4211 if (option != (const char *) NULL)
4212 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4213 MagickInterpolateOptions,MagickFalse,option);
4214 option=GetImageOption(image_info,"loop");
4215 if (option != (const char *) NULL)
4216 image->iterations=StringToUnsignedLong(option);
4217 option=GetImageOption(image_info,"mattecolor");
4218 if (option != (const char *) NULL)
4219 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4221 option=GetImageOption(image_info,"orient");
4222 if (option != (const char *) NULL)
4223 image->orientation=(OrientationType) ParseCommandOption(
4224 MagickOrientationOptions,MagickFalse,option);
4225 option=GetImageOption(image_info,"page");
4226 if (option != (const char *) NULL)
4231 geometry=GetPageGeometry(option);
4232 flags=ParseAbsoluteGeometry(geometry,&image->page);
4233 geometry=DestroyString(geometry);
4235 option=GetImageOption(image_info,"quality");
4236 if (option != (const char *) NULL)
4237 image->quality=StringToUnsignedLong(option);
4238 option=GetImageOption(image_info,"red-primary");
4239 if (option != (const char *) NULL)
4241 flags=ParseGeometry(option,&geometry_info);
4242 image->chromaticity.red_primary.x=geometry_info.rho;
4243 image->chromaticity.red_primary.y=geometry_info.sigma;
4244 if ((flags & SigmaValue) == 0)
4245 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4247 if (image_info->quality != UndefinedCompressionQuality)
4248 image->quality=image_info->quality;
4249 option=GetImageOption(image_info,"scene");
4250 if (option != (const char *) NULL)
4251 image->scene=StringToUnsignedLong(option);
4252 option=GetImageOption(image_info,"taint");
4253 if (option != (const char *) NULL)
4254 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4255 MagickFalse,option);
4256 option=GetImageOption(image_info,"tile-offset");
4257 if (option != (const char *) NULL)
4262 geometry=GetPageGeometry(option);
4263 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4264 geometry=DestroyString(geometry);
4266 option=GetImageOption(image_info,"transparent-color");
4267 if (option != (const char *) NULL)
4268 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4270 option=GetImageOption(image_info,"type");
4271 if (option != (const char *) NULL)
4272 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4274 option=GetImageOption(image_info,"units");
4275 if (option != (const char *) NULL)
4276 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4277 MagickFalse,option);
4279 units = image_info->units;
4280 if (units != UndefinedResolution)
4282 if (image->units != units)
4283 switch (image->units)
4285 case PixelsPerInchResolution:
4287 if (units == PixelsPerCentimeterResolution)
4289 image->resolution.x/=2.54;
4290 image->resolution.y/=2.54;
4294 case PixelsPerCentimeterResolution:
4296 if (units == PixelsPerInchResolution)
4298 image->resolution.x=(double) ((size_t) (100.0*2.54*
4299 image->resolution.x+0.5))/100.0;
4300 image->resolution.y=(double) ((size_t) (100.0*2.54*
4301 image->resolution.y+0.5))/100.0;
4310 option=GetImageOption(image_info,"white-point");
4311 if (option != (const char *) NULL)
4313 flags=ParseGeometry(option,&geometry_info);
4314 image->chromaticity.white_point.x=geometry_info.rho;
4315 image->chromaticity.white_point.y=geometry_info.sigma;
4316 if ((flags & SigmaValue) == 0)
4317 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4319 ResetImageOptionIterator(image_info);
4320 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4322 value=GetImageOption(image_info,option);
4323 if (value != (const char *) NULL)
4325 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4326 (void) SetImageArtifact(image,property,value);
4328 option=GetNextImageOption(image_info);