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-2012 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(static,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 channel=GetPixelChannelMapChannel(image,i);
560 traits=GetPixelChannelMapTraits(image,channel);
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;
987 (void) CloneImageOptions(clone_info,image_info);
988 clone_info->debug=IsEventLogging();
989 clone_info->signature=image_info->signature;
994 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
998 % C o m b i n e I m a g e s %
1002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1004 % CombineImages() combines one or more images into a single image. The
1005 % grayscale value of the pixels of each image in the sequence is assigned in
1006 % order to the specified channels of the combined image. The typical
1007 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
1009 % The format of the CombineImages method is:
1011 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
1013 % A description of each parameter follows:
1015 % o image: the image.
1017 % o exception: return any errors or warnings in this structure.
1021 static inline size_t MagickMin(const size_t x,const size_t y)
1028 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1030 #define CombineImageTag "Combine/Image"
1048 Ensure the image are the same size.
1050 assert(image != (const Image *) NULL);
1051 assert(image->signature == MagickSignature);
1052 if (image->debug != MagickFalse)
1053 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1054 assert(exception != (ExceptionInfo *) NULL);
1055 assert(exception->signature == MagickSignature);
1056 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1057 if (combine_image == (Image *) NULL)
1058 return((Image *) NULL);
1059 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1061 combine_image=DestroyImage(combine_image);
1062 return((Image *) NULL);
1064 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1065 combine_image->matte=MagickTrue;
1071 combine_view=AcquireCacheView(combine_image);
1072 for (y=0; y < (ssize_t) combine_image->rows; y++)
1083 register const Quantum
1092 if (status == MagickFalse)
1094 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1096 if (pixels == (Quantum *) NULL)
1102 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1114 if (next == (Image *) NULL)
1116 channel=GetPixelChannelMapChannel(image,i);
1117 traits=GetPixelChannelMapTraits(image,channel);
1118 combine_traits=GetPixelChannelMapTraits(combine_image,channel);
1119 if ((traits == UndefinedPixelTrait) ||
1120 (combine_traits == UndefinedPixelTrait))
1122 image_view=AcquireCacheView(next);
1123 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1124 if (p == (const Quantum *) NULL)
1127 for (x=0; x < (ssize_t) combine_image->columns; x++)
1129 if (x < (ssize_t) image->columns)
1132 p+=GetPixelChannels(image);
1134 q+=GetPixelChannels(combine_image);
1136 image_view=DestroyCacheView(image_view);
1137 next=GetNextImageInList(next);
1138 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1140 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1145 proceed=SetImageProgress(image,CombineImageTag,progress++,
1146 combine_image->rows);
1147 if (proceed == MagickFalse)
1152 combine_view=DestroyCacheView(combine_view);
1153 if (status == MagickFalse)
1154 combine_image=DestroyImage(combine_image);
1155 return(combine_image);
1159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1163 % D e s t r o y I m a g e %
1167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1169 % DestroyImage() dereferences an image, deallocating memory associated with
1170 % the image if the reference count becomes zero.
1172 % The format of the DestroyImage method is:
1174 % Image *DestroyImage(Image *image)
1176 % A description of each parameter follows:
1178 % o image: the image.
1181 MagickExport Image *DestroyImage(Image *image)
1189 assert(image != (Image *) NULL);
1190 assert(image->signature == MagickSignature);
1191 if (image->debug != MagickFalse)
1192 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1193 destroy=MagickFalse;
1194 LockSemaphoreInfo(image->semaphore);
1195 image->reference_count--;
1196 if (image->reference_count == 0)
1198 UnlockSemaphoreInfo(image->semaphore);
1199 if (destroy == MagickFalse)
1200 return((Image *) NULL);
1204 DestroyImagePixels(image);
1205 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1206 if (image->clip_mask != (Image *) NULL)
1207 image->clip_mask=DestroyImage(image->clip_mask);
1208 if (image->mask != (Image *) NULL)
1209 image->mask=DestroyImage(image->mask);
1210 if (image->montage != (char *) NULL)
1211 image->montage=DestroyString(image->montage);
1212 if (image->directory != (char *) NULL)
1213 image->directory=DestroyString(image->directory);
1214 if (image->colormap != (PixelInfo *) NULL)
1215 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1216 if (image->geometry != (char *) NULL)
1217 image->geometry=DestroyString(image->geometry);
1218 DestroyImageProfiles(image);
1219 DestroyImageProperties(image);
1220 DestroyImageArtifacts(image);
1221 if (image->ascii85 != (Ascii85Info*) NULL)
1222 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1224 if (image->semaphore != (SemaphoreInfo *) NULL)
1225 DestroySemaphoreInfo(&image->semaphore);
1226 image->signature=(~MagickSignature);
1227 image=(Image *) RelinquishMagickMemory(image);
1232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1236 % D e s t r o y I m a g e I n f o %
1240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1242 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1245 % The format of the DestroyImageInfo method is:
1247 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1249 % A description of each parameter follows:
1251 % o image_info: the image info.
1254 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1256 assert(image_info != (ImageInfo *) NULL);
1257 assert(image_info->signature == MagickSignature);
1258 if (image_info->debug != MagickFalse)
1259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1260 image_info->filename);
1261 if (image_info->size != (char *) NULL)
1262 image_info->size=DestroyString(image_info->size);
1263 if (image_info->extract != (char *) NULL)
1264 image_info->extract=DestroyString(image_info->extract);
1265 if (image_info->scenes != (char *) NULL)
1266 image_info->scenes=DestroyString(image_info->scenes);
1267 if (image_info->page != (char *) NULL)
1268 image_info->page=DestroyString(image_info->page);
1269 if (image_info->sampling_factor != (char *) NULL)
1270 image_info->sampling_factor=DestroyString(
1271 image_info->sampling_factor);
1272 if (image_info->server_name != (char *) NULL)
1273 image_info->server_name=DestroyString(
1274 image_info->server_name);
1275 if (image_info->font != (char *) NULL)
1276 image_info->font=DestroyString(image_info->font);
1277 if (image_info->texture != (char *) NULL)
1278 image_info->texture=DestroyString(image_info->texture);
1279 if (image_info->density != (char *) NULL)
1280 image_info->density=DestroyString(image_info->density);
1281 if (image_info->view != (char *) NULL)
1282 image_info->view=DestroyString(image_info->view);
1283 if (image_info->cache != (void *) NULL)
1284 image_info->cache=DestroyPixelCache(image_info->cache);
1285 if (image_info->profile != (StringInfo *) NULL)
1286 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1287 image_info->profile);
1288 DestroyImageOptions(image_info);
1289 image_info->signature=(~MagickSignature);
1290 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1299 + D i s a s s o c i a t e I m a g e S t r e a m %
1303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1305 % DisassociateImageStream() disassociates the image stream.
1307 % The format of the DisassociateImageStream method is:
1309 % MagickBooleanType DisassociateImageStream(const Image *image)
1311 % A description of each parameter follows:
1313 % o image: the image.
1316 MagickExport void DisassociateImageStream(Image *image)
1318 assert(image != (const Image *) NULL);
1319 assert(image->signature == MagickSignature);
1320 if (image->debug != MagickFalse)
1321 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1322 (void) DetachBlob(image->blob);
1326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1330 % G e t I m a g e A l p h a C h a n n e l %
1334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1336 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1337 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1340 % The format of the GetImageAlphaChannel method is:
1342 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1344 % A description of each parameter follows:
1346 % o image: the image.
1349 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1351 assert(image != (const Image *) NULL);
1352 if (image->debug != MagickFalse)
1353 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1354 assert(image->signature == MagickSignature);
1355 return(image->matte);
1359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1363 % G e t I m a g e C l i p M a s k %
1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1369 % GetImageClipMask() returns the clip path associated with the image.
1371 % The format of the GetImageClipMask method is:
1373 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1375 % A description of each parameter follows:
1377 % o image: the image.
1380 MagickExport Image *GetImageClipMask(const Image *image,
1381 ExceptionInfo *exception)
1383 assert(image != (const Image *) NULL);
1384 if (image->debug != MagickFalse)
1385 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1386 assert(image->signature == MagickSignature);
1387 if (image->clip_mask == (Image *) NULL)
1388 return((Image *) NULL);
1389 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1397 % G e t I m a g e I n f o %
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1403 % GetImageInfo() initializes image_info to default values.
1405 % The format of the GetImageInfo method is:
1407 % void GetImageInfo(ImageInfo *image_info)
1409 % A description of each parameter follows:
1411 % o image_info: the image info.
1414 MagickExport void GetImageInfo(ImageInfo *image_info)
1423 File and image dimension members.
1425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1426 assert(image_info != (ImageInfo *) NULL);
1427 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1428 image_info->adjoin=MagickTrue;
1429 image_info->interlace=NoInterlace;
1430 image_info->channel=DefaultChannels;
1431 image_info->quality=UndefinedCompressionQuality;
1432 image_info->antialias=MagickTrue;
1433 image_info->dither=MagickTrue;
1434 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1435 if (synchronize != (const char *) NULL)
1436 image_info->synchronize=IsMagickTrue(synchronize);
1437 exception=AcquireExceptionInfo();
1438 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1439 &image_info->background_color,exception);
1440 (void) QueryColorCompliance(BorderColor,AllCompliance,
1441 &image_info->border_color,exception);
1442 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1444 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1445 &image_info->transparent_color,exception);
1446 exception=DestroyExceptionInfo(exception);
1447 image_info->debug=IsEventLogging();
1448 image_info->signature=MagickSignature;
1452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1456 % G e t I m a g e I n f o F i l e %
1460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1462 % GetImageInfoFile() returns the image info file member.
1464 % The format of the GetImageInfoFile method is:
1466 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1468 % A description of each parameter follows:
1470 % o image_info: the image info.
1473 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1475 return(image_info->file);
1479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1483 % G e t I m a g e M a s k %
1487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1489 % GetImageMask() returns the mask associated with the image.
1491 % The format of the GetImageMask method is:
1493 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1495 % A description of each parameter follows:
1497 % o image: the image.
1500 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1502 assert(image != (const Image *) NULL);
1503 if (image->debug != MagickFalse)
1504 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1505 assert(image->signature == MagickSignature);
1506 if (image->mask == (Image *) NULL)
1507 return((Image *) NULL);
1508 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1516 + G e t I m a g e R e f e r e n c e C o u n t %
1520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1522 % GetImageReferenceCount() returns the image reference count.
1524 % The format of the GetReferenceCount method is:
1526 % ssize_t GetImageReferenceCount(Image *image)
1528 % A description of each parameter follows:
1530 % o image: the image.
1533 MagickExport ssize_t GetImageReferenceCount(Image *image)
1538 assert(image != (Image *) NULL);
1539 assert(image->signature == MagickSignature);
1540 if (image->debug != MagickFalse)
1541 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1542 LockSemaphoreInfo(image->semaphore);
1543 reference_count=image->reference_count;
1544 UnlockSemaphoreInfo(image->semaphore);
1545 return(reference_count);
1549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1553 % 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 %
1557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1559 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1560 % image. A virtual pixel is any pixel access that is outside the boundaries
1561 % of the image cache.
1563 % The format of the GetImageVirtualPixelMethod() method is:
1565 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1567 % A description of each parameter follows:
1569 % o image: the image.
1572 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1574 assert(image != (Image *) NULL);
1575 assert(image->signature == MagickSignature);
1576 if (image->debug != MagickFalse)
1577 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1578 return(GetPixelCacheVirtualMethod(image));
1582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 % I n t e r p r e t I m a g e F i l e n a m e %
1590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592 % InterpretImageFilename() interprets embedded characters in an image filename.
1593 % The filename length is returned.
1595 % The format of the InterpretImageFilename method is:
1597 % size_t InterpretImageFilename(const ImageInfo *image_info,
1598 % Image *image,const char *format,int value,char *filename,
1599 % ExceptionInfo *exception)
1601 % A description of each parameter follows.
1603 % o image_info: the image info..
1605 % o image: the image.
1607 % o format: A filename describing the format to use to write the numeric
1608 % argument. Only the first numeric format identifier is replaced.
1610 % o value: Numeric value to substitute into format filename.
1612 % o filename: return the formatted filename in this character buffer.
1614 % o exception: return any errors or warnings in this structure.
1617 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1618 Image *image,const char *format,int value,char *filename,
1619 ExceptionInfo *exception)
1636 canonical=MagickFalse;
1638 (void) CopyMagickString(filename,format,MaxTextExtent);
1639 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1652 value=(ssize_t) strtol(q,&q,10);
1664 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1665 (p-format)),p,value);
1667 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1668 canonical=MagickTrue;
1677 pattern[MaxTextExtent];
1694 if (strchr(p,']') == (char *) NULL)
1698 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1709 if (LocaleNCompare(pattern,"filename:",9) != 0)
1711 value=(const char *) NULL;
1712 if ((image_info != (const ImageInfo *) NULL) &&
1713 (image != (const Image *) NULL))
1714 value=GetMagickProperty(image_info,image,pattern,exception);
1716 if (image != (Image *) NULL)
1717 value=GetImageProperty(image,pattern,exception);
1719 if (image_info != (ImageInfo *) NULL)
1720 value=GetImageOption(image_info,pattern);
1721 if (value == (const char *) NULL)
1726 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1727 (MaxTextExtent-(p-format-length)));
1728 length+=strlen(pattern)-1;
1730 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1731 canonical=MagickTrue;
1741 for (q=filename; *q != '\0'; q++)
1742 if ((*q == '%') && (*(q+1) == '%'))
1744 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1745 canonical=MagickTrue;
1747 if (canonical == MagickFalse)
1748 (void) CopyMagickString(filename,format,MaxTextExtent);
1749 return(strlen(filename));
1753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1757 % I s H i g h D y n a m i c R a n g e I m a g e %
1761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1764 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1767 % The format of the IsHighDynamicRangeImage method is:
1769 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1770 % ExceptionInfo *exception)
1772 % A description of each parameter follows:
1774 % o image: the image.
1776 % o exception: return any errors or warnings in this structure.
1779 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1780 ExceptionInfo *exception)
1782 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1785 return(MagickFalse);
1796 assert(image != (Image *) NULL);
1797 assert(image->signature == MagickSignature);
1798 if (image->debug != MagickFalse)
1799 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1801 image_view=AcquireCacheView(image);
1802 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1803 #pragma omp parallel for schedule(static,4) shared(status)
1805 for (y=0; y < (ssize_t) image->rows; y++)
1810 register const Quantum
1816 if (status == MagickFalse)
1818 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1819 if (p == (const Quantum *) NULL)
1824 for (x=0; x < (ssize_t) image->columns; x++)
1832 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1837 traits=GetPixelChannelMapTraits(image,i);
1838 if (traits == UndefinedPixelTrait)
1840 pixel=(MagickRealType) p[i];
1841 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1842 (pixel != (QuantumAny) pixel))
1845 p+=GetPixelChannels(image);
1846 if (i < (ssize_t) GetPixelChannels(image))
1849 if (x < (ssize_t) image->columns)
1852 image_view=DestroyCacheView(image_view);
1853 return(status != MagickFalse ? MagickFalse : MagickTrue);
1858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1862 % I s I m a g e O b j e c t %
1866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1868 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1869 % set of image objects.
1871 % The format of the IsImageObject method is:
1873 % MagickBooleanType IsImageObject(const Image *image)
1875 % A description of each parameter follows:
1877 % o image: the image.
1880 MagickExport MagickBooleanType IsImageObject(const Image *image)
1882 register const Image
1885 assert(image != (Image *) NULL);
1886 if (image->debug != MagickFalse)
1887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1888 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1889 if (p->signature != MagickSignature)
1890 return(MagickFalse);
1895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1899 % I s T a i n t I m a g e %
1903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1905 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1906 % since it was first constituted.
1908 % The format of the IsTaintImage method is:
1910 % MagickBooleanType IsTaintImage(const Image *image)
1912 % A description of each parameter follows:
1914 % o image: the image.
1917 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1920 magick[MaxTextExtent],
1921 filename[MaxTextExtent];
1923 register const Image
1926 assert(image != (Image *) NULL);
1927 if (image->debug != MagickFalse)
1928 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1929 assert(image->signature == MagickSignature);
1930 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1931 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1932 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1934 if (p->taint != MagickFalse)
1936 if (LocaleCompare(p->magick,magick) != 0)
1938 if (LocaleCompare(p->filename,filename) != 0)
1941 return(MagickFalse);
1945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1949 % M o d i f y I m a g e %
1953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1955 % ModifyImage() ensures that there is only a single reference to the image
1956 % to be modified, updating the provided image pointer to point to a clone of
1957 % the original image if necessary.
1959 % The format of the ModifyImage method is:
1961 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1963 % A description of each parameter follows:
1965 % o image: the image.
1967 % o exception: return any errors or warnings in this structure.
1970 MagickExport MagickBooleanType ModifyImage(Image **image,
1971 ExceptionInfo *exception)
1976 assert(image != (Image **) NULL);
1977 assert(*image != (Image *) NULL);
1978 assert((*image)->signature == MagickSignature);
1979 if ((*image)->debug != MagickFalse)
1980 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1981 if (GetImageReferenceCount(*image) <= 1)
1983 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1984 LockSemaphoreInfo((*image)->semaphore);
1985 (*image)->reference_count--;
1986 UnlockSemaphoreInfo((*image)->semaphore);
1992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1996 % N e w M a g i c k I m a g e %
2000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002 % NewMagickImage() creates a blank image canvas of the specified size and
2005 % The format of the NewMagickImage method is:
2007 % Image *NewMagickImage(const ImageInfo *image_info,
2008 % const size_t width,const size_t height,const PixelInfo *background,
2009 % ExceptionInfo *exception)
2011 % A description of each parameter follows:
2013 % o image: the image.
2015 % o width: the image width.
2017 % o height: the image height.
2019 % o background: the image color.
2021 % o exception: return any errors or warnings in this structure.
2024 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2025 const size_t width,const size_t height,const PixelInfo *background,
2026 ExceptionInfo *exception)
2040 assert(image_info != (const ImageInfo *) NULL);
2041 if (image_info->debug != MagickFalse)
2042 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2043 assert(image_info->signature == MagickSignature);
2044 assert(background != (const PixelInfo *) NULL);
2045 image=AcquireImage(image_info,exception);
2046 image->columns=width;
2048 image->colorspace=background->colorspace;
2049 image->matte=background->matte;
2050 image->fuzz=background->fuzz;
2051 image->depth=background->depth;
2053 image_view=AcquireCacheView(image);
2054 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2055 #pragma omp parallel for schedule(static,4) shared(status)
2057 for (y=0; y < (ssize_t) image->rows; y++)
2065 if (status == MagickFalse)
2067 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2068 if (q == (Quantum *) NULL)
2073 for (x=0; x < (ssize_t) image->columns; x++)
2075 SetPixelInfoPixel(image,background,q);
2076 q+=GetPixelChannels(image);
2078 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2081 image_view=DestroyCacheView(image_view);
2082 if (status == MagickFalse)
2083 image=DestroyImage(image);
2088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2092 % R e f e r e n c e I m a g e %
2096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2098 % ReferenceImage() increments the reference count associated with an image
2099 % returning a pointer to the image.
2101 % The format of the ReferenceImage method is:
2103 % Image *ReferenceImage(Image *image)
2105 % A description of each parameter follows:
2107 % o image: the image.
2110 MagickExport Image *ReferenceImage(Image *image)
2112 assert(image != (Image *) NULL);
2113 if (image->debug != MagickFalse)
2114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2115 assert(image->signature == MagickSignature);
2116 LockSemaphoreInfo(image->semaphore);
2117 image->reference_count++;
2118 UnlockSemaphoreInfo(image->semaphore);
2123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2127 % R e s e t I m a g e P a g e %
2131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2133 % ResetImagePage() resets the image page canvas and position.
2135 % The format of the ResetImagePage method is:
2137 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2139 % A description of each parameter follows:
2141 % o image: the image.
2143 % o page: the relative page specification.
2146 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2154 assert(image != (Image *) NULL);
2155 assert(image->signature == MagickSignature);
2156 if (image->debug != MagickFalse)
2157 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2158 flags=ParseAbsoluteGeometry(page,&geometry);
2159 if ((flags & WidthValue) != 0)
2161 if ((flags & HeightValue) == 0)
2162 geometry.height=geometry.width;
2163 image->page.width=geometry.width;
2164 image->page.height=geometry.height;
2166 if ((flags & AspectValue) != 0)
2168 if ((flags & XValue) != 0)
2169 image->page.x+=geometry.x;
2170 if ((flags & YValue) != 0)
2171 image->page.y+=geometry.y;
2175 if ((flags & XValue) != 0)
2177 image->page.x=geometry.x;
2178 if ((image->page.width == 0) && (geometry.x > 0))
2179 image->page.width=image->columns+geometry.x;
2181 if ((flags & YValue) != 0)
2183 image->page.y=geometry.y;
2184 if ((image->page.height == 0) && (geometry.y > 0))
2185 image->page.height=image->rows+geometry.y;
2192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2196 % S e p a r a t e I m a g e C h a n n e l %
2200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2202 % SeparateImage() separates a channel from the image and returns it as
2203 % a grayscale image. A channel is a particular color component of each pixel
2206 % The format of the SeparateImage method is:
2208 % MagickBooleanType SeparateImage(Image *image,ExceptionInfo *exception)
2210 % A description of each parameter follows:
2212 % o image: the image.
2214 % o exception: return any errors or warnings in this structure.
2217 MagickExport MagickBooleanType SeparateImage(Image *image,
2218 ExceptionInfo *exception)
2220 #define SeparateImageTag "Separate/Image"
2234 assert(image != (Image *) NULL);
2235 assert(image->signature == MagickSignature);
2236 if (image->debug != MagickFalse)
2237 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2238 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2239 return(MagickFalse);
2241 Separate image channels.
2245 image_view=AcquireCacheView(image);
2246 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2247 #pragma omp parallel for schedule(static,4) shared(progress,status)
2249 for (y=0; y < (ssize_t) image->rows; y++)
2257 if (status == MagickFalse)
2259 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2260 if (q == (Quantum *) NULL)
2265 for (x=0; x < (ssize_t) image->columns; x++)
2270 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2281 channel=GetPixelChannelMapChannel(image,i);
2282 traits=GetPixelChannelMapTraits(image,channel);
2283 if (traits == UndefinedPixelTrait)
2285 if ((traits & UpdatePixelTrait) != 0)
2286 for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
2289 q+=GetPixelChannels(image);
2291 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2293 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2298 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2299 #pragma omp critical (MagickCore_SeparateImage)
2301 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2302 if (proceed == MagickFalse)
2306 image_view=DestroyCacheView(image_view);
2307 (void) SetImageColorspace(image,RGBColorspace,exception);
2312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2316 % S e p a r a t e I m a g e s %
2320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2322 % SeparateImages() returns a separate grayscale image for each channel
2325 % The format of the SeparateImages method is:
2327 % MagickBooleanType SeparateImages(const Image *image,
2328 % ExceptionInfo *exception)
2330 % A description of each parameter follows:
2332 % o image: the image.
2334 % o exception: return any errors or warnings in this structure.
2337 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2349 assert(image != (Image *) NULL);
2350 assert(image->signature == MagickSignature);
2351 if (image->debug != MagickFalse)
2352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2353 images=NewImageList();
2354 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2362 channel=GetPixelChannelMapChannel(image,i);
2363 traits=GetPixelChannelMapTraits(image,channel);
2364 if (traits == UndefinedPixelTrait)
2366 if ((traits & UpdatePixelTrait) != 0)
2368 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2369 if (separate_image != (Image *) NULL)
2371 channel_mask=SetPixelChannelMask(separate_image,
2372 (ChannelType) (1 << i));
2373 (void) SeparateImage(separate_image,exception);
2374 (void) SetPixelChannelMapMask(separate_image,channel_mask);
2375 AppendImageToList(&images,separate_image);
2383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2387 % S e t I m a g e A l p h a C h a n n e l %
2391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2393 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2396 % The format of the SetImageAlphaChannel method is:
2398 % MagickBooleanType SetImageAlphaChannel(Image *image,
2399 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2401 % A description of each parameter follows:
2403 % o image: the image.
2405 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2406 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2407 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2408 % TransparentAlphaChannel.
2410 % o exception: return any errors or warnings in this structure.
2413 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2414 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2422 assert(image != (Image *) NULL);
2423 if (image->debug != MagickFalse)
2424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2425 assert(image->signature == MagickSignature);
2429 case ActivateAlphaChannel:
2431 image->matte=MagickTrue;
2434 case BackgroundAlphaChannel:
2446 Set transparent pixels to background color.
2448 image->matte=MagickTrue;
2449 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2451 background=image->background_color;
2452 image_view=AcquireCacheView(image);
2453 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2454 #pragma omp parallel for schedule(static,4) shared(status)
2456 for (y=0; y < (ssize_t) image->rows; y++)
2464 if (status == MagickFalse)
2466 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2468 if (q == (Quantum *) NULL)
2473 for (x=0; x < (ssize_t) image->columns; x++)
2475 if (GetPixelAlpha(image,q) == TransparentAlpha)
2476 SetPixelInfoPixel(image,&background,q);
2477 q+=GetPixelChannels(image);
2479 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2482 image_view=DestroyCacheView(image_view);
2485 case DeactivateAlphaChannel:
2487 image->matte=MagickFalse;
2490 case ShapeAlphaChannel:
2491 case CopyAlphaChannel:
2494 Special usage case for SeparateImage(): copy grayscale color to
2497 channel_mask=SetPixelChannelMask(image,GrayChannel);
2498 status=SeparateImage(image,exception);
2499 (void) SetPixelChannelMask(image,channel_mask);
2500 image->matte=MagickTrue; /* make sure transparency is now on! */
2501 if (alpha_type == ShapeAlphaChannel)
2507 Reset all color channels to background color.
2509 background=image->background_color;
2510 (void) LevelImageColors(image,&background,&background,MagickTrue,
2515 case ExtractAlphaChannel:
2517 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2518 status=SeparateImage(image,exception);
2519 (void) SetPixelChannelMask(image,channel_mask);
2520 image->matte=MagickFalse;
2523 case OpaqueAlphaChannel:
2525 status=SetImageAlpha(image,OpaqueAlpha,exception);
2528 case TransparentAlphaChannel:
2530 status=SetImageAlpha(image,TransparentAlpha,exception);
2533 case SetAlphaChannel:
2535 if (image->matte == MagickFalse)
2536 status=SetImageAlpha(image,OpaqueAlpha,exception);
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)
2586 assert(image != (Image *) NULL);
2587 if (image->debug != MagickFalse)
2588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2589 assert(image->signature == MagickSignature);
2590 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2591 return(MagickFalse);
2593 Set image background color.
2596 image_view=AcquireCacheView(image);
2597 for (y=0; y < (ssize_t) image->rows; y++)
2605 if (status == MagickFalse)
2607 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2608 if (q == (Quantum *) NULL)
2613 for (x=0; x < (ssize_t) image->columns; x++)
2615 SetPixelInfoPixel(image,&image->background_color,q);
2616 q+=GetPixelChannels(image);
2618 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2621 image_view=DestroyCacheView(image_view);
2626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2630 % S e t I m a g e C o l o r %
2634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2636 % SetImageColor() set the entire image canvas to the specified color.
2638 % The format of the SetImageColor method is:
2640 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2641 % ExeptionInfo *exception)
2643 % A description of each parameter follows:
2645 % o image: the image.
2647 % o background: the image color.
2649 % o exception: return any errors or warnings in this structure.
2652 MagickExport MagickBooleanType SetImageColor(Image *image,
2653 const PixelInfo *color,ExceptionInfo *exception)
2664 assert(image != (Image *) NULL);
2665 if (image->debug != MagickFalse)
2666 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2667 assert(image->signature == MagickSignature);
2668 assert(color != (const PixelInfo *) NULL);
2669 image->colorspace=color->colorspace;
2670 image->matte=color->matte;
2671 image->fuzz=color->fuzz;
2672 image->depth=color->depth;
2674 image_view=AcquireCacheView(image);
2675 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2676 #pragma omp parallel for schedule(static,4) shared(status)
2678 for (y=0; y < (ssize_t) image->rows; y++)
2686 if (status == MagickFalse)
2688 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2689 if (q == (Quantum *) NULL)
2694 for (x=0; x < (ssize_t) image->columns; x++)
2696 SetPixelInfoPixel(image,color,q);
2697 q+=GetPixelChannels(image);
2699 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2702 image_view=DestroyCacheView(image_view);
2707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2711 % S e t I m a g e S t o r a g e C l a s s %
2715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2717 % SetImageStorageClass() sets the image class: DirectClass for true color
2718 % images or PseudoClass for colormapped images.
2720 % The format of the SetImageStorageClass method is:
2722 % MagickBooleanType SetImageStorageClass(Image *image,
2723 % const ClassType storage_class,ExceptionInfo *exception)
2725 % A description of each parameter follows:
2727 % o image: the image.
2729 % o storage_class: The image class.
2731 % o exception: return any errors or warnings in this structure.
2734 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2735 const ClassType storage_class,ExceptionInfo *exception)
2737 image->storage_class=storage_class;
2738 return(SyncImagePixelCache(image,exception));
2742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2746 % S e t I m a g e C l i p M a s k %
2750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2752 % SetImageClipMask() associates a clip path with the image. The clip path
2753 % must be the same dimensions as the image. Set any pixel component of
2754 % the clip path to TransparentAlpha to prevent that corresponding image
2755 % pixel component from being updated when SyncAuthenticPixels() is applied.
2757 % The format of the SetImageClipMask method is:
2759 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2760 % ExceptionInfo *exception)
2762 % A description of each parameter follows:
2764 % o image: the image.
2766 % o clip_mask: the image clip path.
2768 % o exception: return any errors or warnings in this structure.
2771 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2772 const Image *clip_mask,ExceptionInfo *exception)
2774 assert(image != (Image *) NULL);
2775 if (image->debug != MagickFalse)
2776 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2777 assert(image->signature == MagickSignature);
2778 if (clip_mask != (const Image *) NULL)
2779 if ((clip_mask->columns != image->columns) ||
2780 (clip_mask->rows != image->rows))
2781 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2782 if (image->clip_mask != (Image *) NULL)
2783 image->clip_mask=DestroyImage(image->clip_mask);
2784 image->clip_mask=NewImageList();
2785 if (clip_mask == (Image *) NULL)
2787 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2788 return(MagickFalse);
2789 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,exception);
2790 if (image->clip_mask == (Image *) NULL)
2791 return(MagickFalse);
2796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2800 % S e t I m a g e E x t e n t %
2804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2806 % SetImageExtent() sets the image size (i.e. columns & rows).
2808 % The format of the SetImageExtent method is:
2810 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2811 % const size_t rows,ExceptionInfo *exception)
2813 % A description of each parameter follows:
2815 % o image: the image.
2817 % o columns: The image width in pixels.
2819 % o rows: The image height in pixels.
2821 % o exception: return any errors or warnings in this structure.
2824 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2825 const size_t rows,ExceptionInfo *exception)
2827 if ((columns == 0) || (rows == 0))
2828 return(MagickFalse);
2829 image->columns=columns;
2831 return(SyncImagePixelCache(image,exception));
2835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2839 + S e t I m a g e I n f o %
2843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2845 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2846 % It is set to a type of image format based on the prefix or suffix of the
2847 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2848 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2849 % precendence over the suffix. Use an optional index enclosed in brackets
2850 % after a file name to specify a desired scene of a multi-resolution image
2851 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2852 % indicates success.
2854 % The format of the SetImageInfo method is:
2856 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2857 % const unsigned int frames,ExceptionInfo *exception)
2859 % A description of each parameter follows:
2861 % o image_info: the image info.
2863 % o frames: the number of images you intend to write.
2865 % o exception: return any errors or warnings in this structure.
2868 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2869 const unsigned int frames,ExceptionInfo *exception)
2872 extension[MaxTextExtent],
2873 filename[MaxTextExtent],
2874 magic[MaxTextExtent],
2876 subimage[MaxTextExtent];
2900 magick[2*MaxTextExtent];
2903 Look for 'image.format' in filename.
2905 assert(image_info != (ImageInfo *) NULL);
2906 assert(image_info->signature == MagickSignature);
2907 if (image_info->debug != MagickFalse)
2908 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2909 image_info->filename);
2913 GetPathComponent(image_info->filename,SubimagePath,subimage);
2914 if (*subimage != '\0')
2917 Look for scene specification (e.g. img0001.pcd[4]).
2919 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2921 if (IsGeometry(subimage) != MagickFalse)
2922 (void) CloneString(&image_info->extract,subimage);
2930 (void) CloneString(&image_info->scenes,subimage);
2931 image_info->scene=StringToUnsignedLong(image_info->scenes);
2932 image_info->number_scenes=image_info->scene;
2933 p=image_info->scenes;
2934 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2936 while ((isspace((int) ((unsigned char) *p)) != 0) ||
2939 first=(size_t) strtol(p,&q,10);
2941 while (isspace((int) ((unsigned char) *q)) != 0)
2944 last=(size_t) strtol(q+1,&q,10);
2947 if (first < image_info->scene)
2948 image_info->scene=first;
2949 if (last > image_info->number_scenes)
2950 image_info->number_scenes=last;
2953 image_info->number_scenes-=image_info->scene-1;
2958 GetPathComponent(image_info->filename,ExtensionPath,extension);
2959 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2960 if (*extension != '\0')
2961 if ((LocaleCompare(extension,"gz") == 0) ||
2962 (LocaleCompare(extension,"Z") == 0) ||
2963 (LocaleCompare(extension,"wmz") == 0))
2966 path[MaxTextExtent];
2968 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2969 path[strlen(path)-strlen(extension)-1]='\0';
2970 GetPathComponent(path,ExtensionPath,extension);
2973 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2974 if (*extension != '\0')
2975 if (LocaleCompare(extension,"bz2") == 0)
2978 path[MaxTextExtent];
2980 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2981 path[strlen(path)-strlen(extension)-1]='\0';
2982 GetPathComponent(path,ExtensionPath,extension);
2985 image_info->affirm=MagickFalse;
2986 sans_exception=AcquireExceptionInfo();
2987 if (*extension != '\0')
2996 *format_type_formats[] =
3019 User specified image format.
3021 (void) CopyMagickString(magic,extension,MaxTextExtent);
3024 Look for explicit image formats.
3026 format_type=UndefinedFormatType;
3028 while ((format_type == UndefinedFormatType) &&
3029 (format_type_formats[i] != (char *) NULL))
3031 if ((*magic == *format_type_formats[i]) &&
3032 (LocaleCompare(magic,format_type_formats[i]) == 0))
3033 format_type=ExplicitFormatType;
3036 magick_info=GetMagickInfo(magic,sans_exception);
3037 if ((magick_info != (const MagickInfo *) NULL) &&
3038 (magick_info->format_type != UndefinedFormatType))
3039 format_type=magick_info->format_type;
3040 if (format_type == UndefinedFormatType)
3041 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3043 if (format_type == ExplicitFormatType)
3045 image_info->affirm=MagickTrue;
3046 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3048 if (LocaleCompare(magic,"RGB") == 0)
3049 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3052 Look for explicit 'format:image' in filename.
3055 GetPathComponent(image_info->filename,MagickPath,magic);
3057 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3061 User specified image format.
3064 if (IsMagickConflict(magic) == MagickFalse)
3066 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3067 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3068 image_info->affirm=MagickTrue;
3070 image_info->temporary=MagickTrue;
3073 magick_info=GetMagickInfo(magic,sans_exception);
3074 sans_exception=DestroyExceptionInfo(sans_exception);
3075 if ((magick_info == (const MagickInfo *) NULL) ||
3076 (GetMagickEndianSupport(magick_info) == MagickFalse))
3077 image_info->endian=UndefinedEndian;
3078 GetPathComponent(image_info->filename,CanonicalPath,filename);
3079 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3080 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3083 Test for multiple image support (e.g. image%02d.png).
3085 (void) InterpretImageFilename(image_info,(Image *) NULL,
3086 image_info->filename,(int) image_info->scene,filename,exception);
3087 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3088 (strchr(filename,'%') == (char *) NULL))
3089 image_info->adjoin=MagickFalse;
3091 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3094 Some image formats do not support multiple frames per file.
3096 magick_info=GetMagickInfo(magic,exception);
3097 if (magick_info != (const MagickInfo *) NULL)
3098 if (GetMagickAdjoin(magick_info) == MagickFalse)
3099 image_info->adjoin=MagickFalse;
3101 if (image_info->affirm != MagickFalse)
3106 Determine the image format from the first few bytes of the file.
3108 image=AcquireImage(image_info,exception);
3109 (void) CopyMagickString(image->filename,image_info->filename,
3111 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3112 if (status == MagickFalse)
3114 image=DestroyImage(image);
3115 return(MagickFalse);
3117 if ((IsBlobSeekable(image) == MagickFalse) ||
3118 (IsBlobExempt(image) != MagickFalse))
3121 Copy standard input or pipe to temporary file.
3124 status=ImageToFile(image,filename,exception);
3125 (void) CloseBlob(image);
3126 if (status == MagickFalse)
3128 image=DestroyImage(image);
3129 return(MagickFalse);
3131 SetImageInfoFile(image_info,(FILE *) NULL);
3132 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3133 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3134 if (status == MagickFalse)
3136 image=DestroyImage(image);
3137 return(MagickFalse);
3139 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3140 image_info->temporary=MagickTrue;
3142 (void) ResetMagickMemory(magick,0,sizeof(magick));
3143 count=ReadBlob(image,2*MaxTextExtent,magick);
3144 (void) CloseBlob(image);
3145 image=DestroyImage(image);
3147 Check magic.xml configuration file.
3149 sans_exception=AcquireExceptionInfo();
3150 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3151 if ((magic_info != (const MagicInfo *) NULL) &&
3152 (GetMagicName(magic_info) != (char *) NULL))
3154 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3156 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3157 if ((magick_info == (const MagickInfo *) NULL) ||
3158 (GetMagickEndianSupport(magick_info) == MagickFalse))
3159 image_info->endian=UndefinedEndian;
3160 sans_exception=DestroyExceptionInfo(sans_exception);
3163 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3164 if ((magick_info == (const MagickInfo *) NULL) ||
3165 (GetMagickEndianSupport(magick_info) == MagickFalse))
3166 image_info->endian=UndefinedEndian;
3167 sans_exception=DestroyExceptionInfo(sans_exception);
3173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3177 % S e t I m a g e I n f o B l o b %
3181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3183 % SetImageInfoBlob() sets the image info blob member.
3185 % The format of the SetImageInfoBlob method is:
3187 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3188 % const size_t length)
3190 % A description of each parameter follows:
3192 % o image_info: the image info.
3196 % o length: the blob length.
3199 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3200 const size_t length)
3202 assert(image_info != (ImageInfo *) NULL);
3203 assert(image_info->signature == MagickSignature);
3204 if (image_info->debug != MagickFalse)
3205 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3206 image_info->filename);
3207 image_info->blob=(void *) blob;
3208 image_info->length=length;
3212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3216 % S e t I m a g e I n f o F i l e %
3220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3222 % SetImageInfoFile() sets the image info file member.
3224 % The format of the SetImageInfoFile method is:
3226 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3228 % A description of each parameter follows:
3230 % o image_info: the image info.
3235 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3237 assert(image_info != (ImageInfo *) NULL);
3238 assert(image_info->signature == MagickSignature);
3239 if (image_info->debug != MagickFalse)
3240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3241 image_info->filename);
3242 image_info->file=file;
3246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3250 % S e t I m a g e M a s k %
3254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3256 % SetImageMask() associates a mask with the image. The mask must be the same
3257 % dimensions as the image.
3259 % The format of the SetImageMask method is:
3261 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3262 % ExceptionInfo *exception)
3264 % A description of each parameter follows:
3266 % o image: the image.
3268 % o mask: the image mask.
3270 % o exception: return any errors or warnings in this structure.
3273 MagickExport MagickBooleanType SetImageMask(Image *image,
3274 const Image *mask,ExceptionInfo *exception)
3276 assert(image != (Image *) NULL);
3277 if (image->debug != MagickFalse)
3278 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3279 assert(image->signature == MagickSignature);
3280 if (mask != (const Image *) NULL)
3281 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3282 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3283 if (image->mask != (Image *) NULL)
3284 image->mask=DestroyImage(image->mask);
3285 image->mask=NewImageList();
3286 if (mask == (Image *) NULL)
3288 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3289 return(MagickFalse);
3290 image->mask=CloneImage(mask,0,0,MagickTrue,exception);
3291 if (image->mask == (Image *) NULL)
3292 return(MagickFalse);
3297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3301 % S e t I m a g e A l p h a %
3305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3307 % SetImageAlpha() sets the alpha levels of the image.
3309 % The format of the SetImageAlpha method is:
3311 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3312 % ExceptionInfo *exception)
3314 % A description of each parameter follows:
3316 % o image: the image.
3318 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3319 % fully transparent.
3322 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3323 ExceptionInfo *exception)
3334 assert(image != (Image *) NULL);
3335 if (image->debug != MagickFalse)
3336 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3337 assert(image->signature == MagickSignature);
3338 image->matte=MagickTrue;
3340 image_view=AcquireCacheView(image);
3341 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3342 #pragma omp parallel for schedule(static,4) shared(status)
3344 for (y=0; y < (ssize_t) image->rows; y++)
3352 if (status == MagickFalse)
3354 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3355 if (q == (Quantum *) NULL)
3360 for (x=0; x < (ssize_t) image->columns; x++)
3362 SetPixelAlpha(image,alpha,q);
3363 q+=GetPixelChannels(image);
3365 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3368 image_view=DestroyCacheView(image_view);
3373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3377 % S e t I m a g e T y p e %
3381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3383 % SetImageType() sets the type of image. Choose from these types:
3385 % Bilevel Grayscale GrayscaleMatte
3386 % Palette PaletteMatte TrueColor
3387 % TrueColorMatte ColorSeparation ColorSeparationMatte
3390 % The format of the SetImageType method is:
3392 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3393 % ExceptionInfo *exception)
3395 % A description of each parameter follows:
3397 % o image: the image.
3399 % o type: Image type.
3401 % o exception: return any errors or warnings in this structure.
3404 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3405 ExceptionInfo *exception)
3419 assert(image != (Image *) NULL);
3420 if (image->debug != MagickFalse)
3421 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3422 assert(image->signature == MagickSignature);
3424 image_info=AcquireImageInfo();
3425 image_info->dither=image->dither;
3426 artifact=GetImageArtifact(image,"dither");
3427 if (artifact != (const char *) NULL)
3428 (void) SetImageOption(image_info,"dither",artifact);
3433 if (IsImageMonochrome(image,exception) == MagickFalse)
3435 quantize_info=AcquireQuantizeInfo(image_info);
3436 quantize_info->number_colors=2;
3437 quantize_info->colorspace=GRAYColorspace;
3438 status=QuantizeImage(quantize_info,image,exception);
3439 quantize_info=DestroyQuantizeInfo(quantize_info);
3441 image->matte=MagickFalse;
3446 if (IsImageGray(image,exception) == MagickFalse)
3447 status=TransformImageColorspace(image,GRAYColorspace,exception);
3448 image->matte=MagickFalse;
3451 case GrayscaleMatteType:
3453 if (IsImageGray(image,exception) == MagickFalse)
3454 status=TransformImageColorspace(image,GRAYColorspace,exception);
3455 if (image->matte == MagickFalse)
3456 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3461 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3462 status=TransformImageColorspace(image,RGBColorspace,exception);
3463 if ((image->storage_class == DirectClass) || (image->colors > 256))
3465 quantize_info=AcquireQuantizeInfo(image_info);
3466 quantize_info->number_colors=256;
3467 status=QuantizeImage(quantize_info,image,exception);
3468 quantize_info=DestroyQuantizeInfo(quantize_info);
3470 image->matte=MagickFalse;
3473 case PaletteBilevelMatteType:
3478 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3479 status=TransformImageColorspace(image,RGBColorspace,exception);
3480 if (image->matte == MagickFalse)
3481 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3482 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3483 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
3484 (void) SetPixelChannelMask(image,channel_mask);
3485 quantize_info=AcquireQuantizeInfo(image_info);
3486 status=QuantizeImage(quantize_info,image,exception);
3487 quantize_info=DestroyQuantizeInfo(quantize_info);
3490 case PaletteMatteType:
3492 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3493 status=TransformImageColorspace(image,RGBColorspace,exception);
3494 if (image->matte == MagickFalse)
3495 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3496 quantize_info=AcquireQuantizeInfo(image_info);
3497 quantize_info->colorspace=TransparentColorspace;
3498 status=QuantizeImage(quantize_info,image,exception);
3499 quantize_info=DestroyQuantizeInfo(quantize_info);
3504 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3505 status=TransformImageColorspace(image,RGBColorspace,exception);
3506 if (image->storage_class != DirectClass)
3507 status=SetImageStorageClass(image,DirectClass,exception);
3508 image->matte=MagickFalse;
3511 case TrueColorMatteType:
3513 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3514 status=TransformImageColorspace(image,RGBColorspace,exception);
3515 if (image->storage_class != DirectClass)
3516 status=SetImageStorageClass(image,DirectClass,exception);
3517 if (image->matte == MagickFalse)
3518 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3521 case ColorSeparationType:
3523 if (image->colorspace != CMYKColorspace)
3525 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3526 status=TransformImageColorspace(image,RGBColorspace,exception);
3527 status=TransformImageColorspace(image,CMYKColorspace,exception);
3529 if (image->storage_class != DirectClass)
3530 status=SetImageStorageClass(image,DirectClass,exception);
3531 image->matte=MagickFalse;
3534 case ColorSeparationMatteType:
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 if (image->matte == MagickFalse)
3545 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3553 image_info=DestroyImageInfo(image_info);
3558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3562 % 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 %
3566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3568 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3569 % image and returns the previous setting. A virtual pixel is any pixel access
3570 % that is outside the boundaries of the image cache.
3572 % The format of the SetImageVirtualPixelMethod() method is:
3574 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3575 % const VirtualPixelMethod virtual_pixel_method)
3577 % A description of each parameter follows:
3579 % o image: the image.
3581 % o virtual_pixel_method: choose the type of virtual pixel.
3584 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3585 const VirtualPixelMethod virtual_pixel_method)
3587 assert(image != (const Image *) NULL);
3588 assert(image->signature == MagickSignature);
3589 if (image->debug != MagickFalse)
3590 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3591 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3599 % S m u s h I m a g e s %
3603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3605 % SmushImages() takes all images from the current image pointer to the end
3606 % of the image list and smushes them to each other top-to-bottom if the
3607 % stack parameter is true, otherwise left-to-right.
3609 % The current gravity setting now effects how the image is justified in the
3612 % The format of the SmushImages method is:
3614 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3615 % ExceptionInfo *exception)
3617 % A description of each parameter follows:
3619 % o images: the image sequence.
3621 % o stack: A value other than 0 stacks the images top-to-bottom.
3623 % o offset: minimum distance in pixels between images.
3625 % o exception: return any errors or warnings in this structure.
3629 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3630 const ssize_t offset,ExceptionInfo *exception)
3644 register const Quantum
3657 if (images->previous == (Image *) NULL)
3660 SetGeometry(smush_image,&right_geometry);
3661 GravityAdjustGeometry(right_image->columns,right_image->rows,
3662 right_image->gravity,&right_geometry);
3663 left_image=images->previous;
3664 SetGeometry(smush_image,&left_geometry);
3665 GravityAdjustGeometry(left_image->columns,left_image->rows,
3666 left_image->gravity,&left_geometry);
3667 gap=right_image->columns;
3668 left_view=AcquireCacheView(left_image);
3669 right_view=AcquireCacheView(right_image);
3670 for (y=0; y < (ssize_t) smush_image->rows; y++)
3672 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3674 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3675 if ((p == (const Quantum *) NULL) ||
3676 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3677 ((left_image->columns-x-1) >= gap))
3680 i=(ssize_t) left_image->columns-x-1;
3681 for (x=0; x < (ssize_t) right_image->columns; x++)
3683 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3685 if ((p == (const Quantum *) NULL) ||
3686 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3687 ((x+i) >= (ssize_t) gap))
3690 if ((x+i) < (ssize_t) gap)
3693 right_view=DestroyCacheView(right_view);
3694 left_view=DestroyCacheView(left_view);
3695 if (y < (ssize_t) smush_image->rows)
3697 return((ssize_t) gap-offset);
3700 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3701 const ssize_t offset,ExceptionInfo *exception)
3715 register const Quantum
3728 if (images->previous == (Image *) NULL)
3730 bottom_image=images;
3731 SetGeometry(smush_image,&bottom_geometry);
3732 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3733 bottom_image->gravity,&bottom_geometry);
3734 top_image=images->previous;
3735 SetGeometry(smush_image,&top_geometry);
3736 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3738 gap=bottom_image->rows;
3739 top_view=AcquireCacheView(top_image);
3740 bottom_view=AcquireCacheView(bottom_image);
3741 for (x=0; x < (ssize_t) smush_image->columns; x++)
3743 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3745 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3746 if ((p == (const Quantum *) NULL) ||
3747 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3748 ((top_image->rows-y-1) >= gap))
3751 i=(ssize_t) top_image->rows-y-1;
3752 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3754 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3756 if ((p == (const Quantum *) NULL) ||
3757 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3758 ((y+i) >= (ssize_t) gap))
3761 if ((y+i) < (ssize_t) gap)
3764 bottom_view=DestroyCacheView(bottom_view);
3765 top_view=DestroyCacheView(top_view);
3766 if (x < (ssize_t) smush_image->columns)
3768 return((ssize_t) gap-offset);
3771 MagickExport Image *SmushImages(const Image *images,
3772 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3774 #define SmushImageTag "Smush/Image"
3796 register const Image
3809 Compute maximum area of smushed area.
3811 assert(images != (Image *) NULL);
3812 assert(images->signature == MagickSignature);
3813 if (images->debug != MagickFalse)
3814 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3815 assert(exception != (ExceptionInfo *) NULL);
3816 assert(exception->signature == MagickSignature);
3820 width=image->columns;
3822 next=GetNextImageInList(image);
3823 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3825 if (next->matte != MagickFalse)
3828 if (stack != MagickFalse)
3830 if (next->columns > width)
3831 width=next->columns;
3833 if (next->previous != (Image *) NULL)
3837 width+=next->columns;
3838 if (next->previous != (Image *) NULL)
3840 if (next->rows > height)
3846 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3847 if (smush_image == (Image *) NULL)
3848 return((Image *) NULL);
3849 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3851 smush_image=DestroyImage(smush_image);
3852 return((Image *) NULL);
3854 smush_image->matte=matte;
3855 (void) SetImageBackgroundColor(smush_image,exception);
3859 smush_view=AcquireCacheView(smush_image);
3860 for (n=0; n < (MagickOffsetType) number_images; n++)
3862 SetGeometry(smush_image,&geometry);
3863 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3864 if (stack != MagickFalse)
3866 x_offset-=geometry.x;
3867 y_offset-=SmushYGap(smush_image,image,offset,exception);
3871 x_offset-=SmushXGap(smush_image,image,offset,exception);
3872 y_offset-=geometry.y;
3874 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
3876 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3877 if (proceed == MagickFalse)
3879 if (stack == MagickFalse)
3881 x_offset+=(ssize_t) image->columns;
3887 y_offset+=(ssize_t) image->rows;
3889 image=GetNextImageInList(image);
3891 if (stack == MagickFalse)
3892 smush_image->columns=(size_t) x_offset;
3894 smush_image->rows=(size_t) y_offset;
3895 smush_view=DestroyCacheView(smush_view);
3896 if (status == MagickFalse)
3897 smush_image=DestroyImage(smush_image);
3898 return(smush_image);
3902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3906 % S t r i p I m a g e %
3910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3912 % StripImage() strips an image of all profiles and comments.
3914 % The format of the StripImage method is:
3916 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3918 % A description of each parameter follows:
3920 % o image: the image.
3922 % o exception: return any errors or warnings in this structure.
3925 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3930 assert(image != (Image *) NULL);
3931 if (image->debug != MagickFalse)
3932 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3934 DestroyImageProfiles(image);
3935 (void) DeleteImageProperty(image,"comment");
3936 (void) DeleteImageProperty(image,"date:create");
3937 (void) DeleteImageProperty(image,"date:modify");
3938 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
3943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3947 + S y n c I m a g e %
3951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3953 % SyncImage() initializes the red, green, and blue intensities of each pixel
3954 % as defined by the colormap index.
3956 % The format of the SyncImage method is:
3958 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3960 % A description of each parameter follows:
3962 % o image: the image.
3964 % o exception: return any errors or warnings in this structure.
3968 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3969 MagickBooleanType *range_exception)
3971 if (index < image->colors)
3973 *range_exception=MagickTrue;
3977 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3989 assert(image != (Image *) NULL);
3990 if (image->debug != MagickFalse)
3991 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3992 assert(image->signature == MagickSignature);
3993 if (image->storage_class == DirectClass)
3994 return(MagickFalse);
3995 range_exception=MagickFalse;
3997 image_view=AcquireCacheView(image);
3998 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3999 #pragma omp parallel for schedule(static,4) shared(status)
4001 for (y=0; y < (ssize_t) image->rows; y++)
4012 if (status == MagickFalse)
4014 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4015 if (q == (Quantum *) NULL)
4020 for (x=0; x < (ssize_t) image->columns; x++)
4022 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4023 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
4024 q+=GetPixelChannels(image);
4026 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4029 image_view=DestroyCacheView(image_view);
4030 if (range_exception != MagickFalse)
4031 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
4032 "InvalidColormapIndex","`%s'",image->filename);
4037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4041 % S y n c I m a g e S e t t i n g s %
4045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4047 % SyncImageSettings() sync the image info options to the image.
4049 % The format of the SyncImageSettings method is:
4051 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4052 % Image *image,ExceptionInfo *exception)
4053 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4054 % Image *image,ExceptionInfo *exception)
4056 % A description of each parameter follows:
4058 % o image_info: the image info.
4060 % o image: the image.
4062 % o exception: return any errors or warnings in this structure.
4066 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4067 Image *images,ExceptionInfo *exception)
4072 assert(image_info != (const ImageInfo *) NULL);
4073 assert(image_info->signature == MagickSignature);
4074 assert(images != (Image *) NULL);
4075 assert(images->signature == MagickSignature);
4076 if (images->debug != MagickFalse)
4077 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4079 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4080 (void) SyncImageSettings(image_info,image,exception);
4081 (void) DeleteImageOption(image_info,"page");
4085 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4086 Image *image,ExceptionInfo *exception)
4089 property[MaxTextExtent];
4107 assert(image_info != (const ImageInfo *) NULL);
4108 assert(image_info->signature == MagickSignature);
4109 assert(image != (Image *) NULL);
4110 assert(image->signature == MagickSignature);
4111 if (image->debug != MagickFalse)
4112 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4113 option=GetImageOption(image_info,"background");
4114 if (option != (const char *) NULL)
4115 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4117 option=GetImageOption(image_info,"bias");
4118 if (option != (const char *) NULL)
4119 image->bias=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4120 option=GetImageOption(image_info,"black-point-compensation");
4121 if (option != (const char *) NULL)
4122 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4123 MagickBooleanOptions,MagickFalse,option);
4124 option=GetImageOption(image_info,"blue-primary");
4125 if (option != (const char *) NULL)
4127 flags=ParseGeometry(option,&geometry_info);
4128 image->chromaticity.blue_primary.x=geometry_info.rho;
4129 image->chromaticity.blue_primary.y=geometry_info.sigma;
4130 if ((flags & SigmaValue) == 0)
4131 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4133 option=GetImageOption(image_info,"bordercolor");
4134 if (option != (const char *) NULL)
4135 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4137 option=GetImageOption(image_info,"compose");
4138 if (option != (const char *) NULL)
4139 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4140 MagickFalse,option);
4141 option=GetImageOption(image_info,"compress");
4142 if (option != (const char *) NULL)
4143 image->compression=(CompressionType) ParseCommandOption(
4144 MagickCompressOptions,MagickFalse,option);
4145 option=GetImageOption(image_info,"debug");
4146 if (option != (const char *) NULL)
4147 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4148 MagickFalse,option);
4149 option=GetImageOption(image_info,"density");
4150 if (option != (const char *) NULL)
4155 flags=ParseGeometry(option,&geometry_info);
4156 image->resolution.x=geometry_info.rho;
4157 image->resolution.y=geometry_info.sigma;
4158 if ((flags & SigmaValue) == 0)
4159 image->resolution.y=image->resolution.x;
4161 option=GetImageOption(image_info,"depth");
4162 if (option != (const char *) NULL)
4163 image->depth=StringToUnsignedLong(option);
4164 option=GetImageOption(image_info,"endian");
4165 if (option != (const char *) NULL)
4166 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4167 MagickFalse,option);
4168 option=GetImageOption(image_info,"filter");
4169 if (option != (const char *) NULL)
4170 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4171 MagickFalse,option);
4172 option=GetImageOption(image_info,"fuzz");
4173 if (option != (const char *) NULL)
4174 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4175 option=GetImageOption(image_info,"gravity");
4176 if (option != (const char *) NULL)
4177 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4178 MagickFalse,option);
4179 option=GetImageOption(image_info,"green-primary");
4180 if (option != (const char *) NULL)
4182 flags=ParseGeometry(option,&geometry_info);
4183 image->chromaticity.green_primary.x=geometry_info.rho;
4184 image->chromaticity.green_primary.y=geometry_info.sigma;
4185 if ((flags & SigmaValue) == 0)
4186 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4188 option=GetImageOption(image_info,"intent");
4189 if (option != (const char *) NULL)
4190 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4191 MagickIntentOptions,MagickFalse,option);
4192 option=GetImageOption(image_info,"interlace");
4193 if (option != (const char *) NULL)
4194 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4195 MagickFalse,option);
4196 option=GetImageOption(image_info,"interpolate");
4197 if (option != (const char *) NULL)
4198 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4199 MagickInterpolateOptions,MagickFalse,option);
4200 option=GetImageOption(image_info,"loop");
4201 if (option != (const char *) NULL)
4202 image->iterations=StringToUnsignedLong(option);
4203 option=GetImageOption(image_info,"mattecolor");
4204 if (option != (const char *) NULL)
4205 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4207 option=GetImageOption(image_info,"orient");
4208 if (option != (const char *) NULL)
4209 image->orientation=(OrientationType) ParseCommandOption(
4210 MagickOrientationOptions,MagickFalse,option);
4211 option=GetImageOption(image_info,"page");
4212 if (option != (const char *) NULL)
4217 geometry=GetPageGeometry(option);
4218 flags=ParseAbsoluteGeometry(geometry,&image->page);
4219 geometry=DestroyString(geometry);
4221 option=GetImageOption(image_info,"quality");
4222 if (option != (const char *) NULL)
4223 image->quality=StringToUnsignedLong(option);
4224 option=GetImageOption(image_info,"red-primary");
4225 if (option != (const char *) NULL)
4227 flags=ParseGeometry(option,&geometry_info);
4228 image->chromaticity.red_primary.x=geometry_info.rho;
4229 image->chromaticity.red_primary.y=geometry_info.sigma;
4230 if ((flags & SigmaValue) == 0)
4231 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4233 if (image_info->quality != UndefinedCompressionQuality)
4234 image->quality=image_info->quality;
4235 option=GetImageOption(image_info,"scene");
4236 if (option != (const char *) NULL)
4237 image->scene=StringToUnsignedLong(option);
4238 option=GetImageOption(image_info,"taint");
4239 if (option != (const char *) NULL)
4240 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4241 MagickFalse,option);
4242 option=GetImageOption(image_info,"tile-offset");
4243 if (option != (const char *) NULL)
4248 geometry=GetPageGeometry(option);
4249 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4250 geometry=DestroyString(geometry);
4252 option=GetImageOption(image_info,"transparent-color");
4253 if (option != (const char *) NULL)
4254 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4256 option=GetImageOption(image_info,"type");
4257 if (option != (const char *) NULL)
4258 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4260 option=GetImageOption(image_info,"units");
4261 if (option != (const char *) NULL)
4262 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4263 MagickFalse,option);
4265 units = image_info->units;
4266 if (units != UndefinedResolution)
4268 if (image->units != units)
4269 switch (image->units)
4271 case PixelsPerInchResolution:
4273 if (units == PixelsPerCentimeterResolution)
4275 image->resolution.x/=2.54;
4276 image->resolution.y/=2.54;
4280 case PixelsPerCentimeterResolution:
4282 if (units == PixelsPerInchResolution)
4284 image->resolution.x=(double) ((size_t) (100.0*2.54*
4285 image->resolution.x+0.5))/100.0;
4286 image->resolution.y=(double) ((size_t) (100.0*2.54*
4287 image->resolution.y+0.5))/100.0;
4296 option=GetImageOption(image_info,"white-point");
4297 if (option != (const char *) NULL)
4299 flags=ParseGeometry(option,&geometry_info);
4300 image->chromaticity.white_point.x=geometry_info.rho;
4301 image->chromaticity.white_point.y=geometry_info.sigma;
4302 if ((flags & SigmaValue) == 0)
4303 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4305 ResetImageOptionIterator(image_info);
4306 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4308 value=GetImageOption(image_info,option);
4309 if (value != (const char *) NULL)
4311 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4312 (void) SetImageArtifact(image,property,value);
4314 option=GetNextImageOption(image_info);