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-2010 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 "magick/studio.h"
44 #include "magick/animate.h"
45 #include "magick/artifact.h"
46 #include "magick/blob.h"
47 #include "magick/blob-private.h"
48 #include "magick/cache.h"
49 #include "magick/cache-private.h"
50 #include "magick/cache-view.h"
51 #include "magick/client.h"
52 #include "magick/color.h"
53 #include "magick/color-private.h"
54 #include "magick/colormap.h"
55 #include "magick/colorspace.h"
56 #include "magick/colorspace-private.h"
57 #include "magick/composite.h"
58 #include "magick/composite-private.h"
59 #include "magick/compress.h"
60 #include "magick/constitute.h"
61 #include "magick/deprecate.h"
62 #include "magick/display.h"
63 #include "magick/draw.h"
64 #include "magick/enhance.h"
65 #include "magick/exception.h"
66 #include "magick/exception-private.h"
67 #include "magick/gem.h"
68 #include "magick/geometry.h"
69 #include "magick/histogram.h"
70 #include "magick/image-private.h"
71 #include "magick/list.h"
72 #include "magick/magic.h"
73 #include "magick/magick.h"
74 #include "magick/memory_.h"
75 #include "magick/module.h"
76 #include "magick/monitor.h"
77 #include "magick/monitor-private.h"
78 #include "magick/option.h"
79 #include "magick/paint.h"
80 #include "magick/pixel-private.h"
81 #include "magick/profile.h"
82 #include "magick/property.h"
83 #include "magick/quantize.h"
84 #include "magick/random_.h"
85 #include "magick/segment.h"
86 #include "magick/semaphore.h"
87 #include "magick/signature-private.h"
88 #include "magick/statistic.h"
89 #include "magick/string_.h"
90 #include "magick/string-private.h"
91 #include "magick/thread-private.h"
92 #include "magick/threshold.h"
93 #include "magick/timer.h"
94 #include "magick/utility.h"
95 #include "magick/version.h"
96 #include "magick/xwindow-private.h"
102 BackgroundColor[] = "#ffffff", /* white */
103 BorderColor[] = "#dfdfdf", /* gray */
104 DefaultTileFrame[] = "15x15+3+3",
105 DefaultTileGeometry[] = "120x120+4+3>",
106 DefaultTileLabel[] = "%f\n%G\n%b",
107 ForegroundColor[] = "#000", /* black */
108 LoadImageTag[] = "Load/Image",
109 LoadImagesTag[] = "Load/Images",
110 MatteColor[] = "#bdbdbd", /* gray */
111 PSDensityGeometry[] = "72.0x72.0",
112 PSPageGeometry[] = "612x792",
113 SaveImageTag[] = "Save/Image",
114 SaveImagesTag[] = "Save/Images",
115 TransparentColor[] = "#00000000"; /* transparent black */
118 DefaultResolution = 72.0;
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 % A c q u i r e I m a g e %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % AcquireImage() returns a pointer to an image structure initialized to
134 % The format of the AcquireImage method is:
136 % Image *AcquireImage(const ImageInfo *image_info)
138 % A description of each parameter follows:
140 % o image_info: Many of the image default values are set from this
141 % structure. For example, filename, compression, depth, background color,
145 MagickExport Image *AcquireImage(const ImageInfo *image_info)
157 Allocate image structure.
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
160 image=(Image *) AcquireMagickMemory(sizeof(*image));
161 if (image == (Image *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 (void) ResetMagickMemory(image,0,sizeof(*image));
165 Initialize Image structure.
167 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
168 image->storage_class=DirectClass;
169 image->depth=MAGICKCORE_QUANTUM_DEPTH;
170 image->colorspace=RGBColorspace;
171 image->interlace=NoInterlace;
172 image->ticks_per_second=UndefinedTicksPerSecond;
173 image->compose=OverCompositeOp;
175 GetExceptionInfo(&image->exception);
176 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
178 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
179 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
180 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
182 image->x_resolution=DefaultResolution;
183 image->y_resolution=DefaultResolution;
184 image->units=PixelsPerInchResolution;
185 GetTimerInfo(&image->timer);
186 image->ping=MagickFalse;
187 image->cache=AcquirePixelCache(0);
188 image->blob=CloneBlobInfo((BlobInfo *) NULL);
189 image->debug=IsEventLogging();
190 image->reference_count=1;
191 image->semaphore=AllocateSemaphoreInfo();
192 image->signature=MagickSignature;
193 if (image_info == (ImageInfo *) NULL)
198 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
200 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
201 (void) CopyMagickString(image->magick_filename,image_info->filename,
203 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
204 if (image_info->size != (char *) NULL)
206 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
207 image->columns=image->extract_info.width;
208 image->rows=image->extract_info.height;
209 image->offset=image->extract_info.x;
210 image->extract_info.x=0;
211 image->extract_info.y=0;
213 if (image_info->extract != (char *) NULL)
218 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
219 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
221 image->extract_info=geometry;
222 Swap(image->columns,image->extract_info.width);
223 Swap(image->rows,image->extract_info.height);
226 image->compression=image_info->compression;
227 image->quality=image_info->quality;
228 image->endian=image_info->endian;
229 image->interlace=image_info->interlace;
230 image->units=image_info->units;
231 if (image_info->density != (char *) NULL)
236 flags=ParseGeometry(image_info->density,&geometry_info);
237 image->x_resolution=geometry_info.rho;
238 image->y_resolution=geometry_info.sigma;
239 if ((flags & SigmaValue) == 0)
240 image->y_resolution=image->x_resolution;
242 if (image_info->page != (char *) NULL)
247 image->page=image->extract_info;
248 geometry=GetPageGeometry(image_info->page);
249 (void) ParseAbsoluteGeometry(geometry,&image->page);
250 geometry=DestroyString(geometry);
252 if (image_info->depth != 0)
253 image->depth=image_info->depth;
254 image->dither=image_info->dither;
255 image->background_color=image_info->background_color;
256 image->border_color=image_info->border_color;
257 image->matte_color=image_info->matte_color;
258 image->transparent_color=image_info->transparent_color;
259 image->ping=image_info->ping;
260 image->progress_monitor=image_info->progress_monitor;
261 image->client_data=image_info->client_data;
262 if (image_info->cache != (void *) NULL)
263 ClonePixelCacheMethods(image->cache,image_info->cache);
264 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
265 (void) SyncImageSettings(image_info,image);
266 option=GetImageOption(image_info,"delay");
267 if (option != (const char *) NULL)
272 flags=ParseGeometry(option,&geometry_info);
273 if ((flags & GreaterValue) != 0)
275 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
276 image->delay=(size_t) floor(geometry_info.rho+0.5);
279 if ((flags & LessValue) != 0)
281 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
282 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
285 image->delay=(size_t) floor(geometry_info.rho+0.5);
286 if ((flags & SigmaValue) != 0)
287 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
289 option=GetImageOption(image_info,"dispose");
290 if (option != (const char *) NULL)
291 image->dispose=(DisposeType) ParseMagickOption(MagickDisposeOptions,
297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 % A c q u i r e I m a g e I n f o %
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 % AcquireImageInfo() allocates the ImageInfo structure.
309 % The format of the AcquireImageInfo method is:
311 % ImageInfo *AcquireImageInfo(void)
314 MagickExport ImageInfo *AcquireImageInfo(void)
319 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
320 if (image_info == (ImageInfo *) NULL)
321 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
322 GetImageInfo(image_info);
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % A c q u i r e N e x t I m a g e %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % AcquireNextImage() initializes the next image in a sequence to
338 % default values. The next member of image points to the newly allocated
339 % image. If there is a memory shortage, next is assigned NULL.
341 % The format of the AcquireNextImage method is:
343 % void AcquireNextImage(const ImageInfo *image_info,Image *image)
345 % A description of each parameter follows:
347 % o image_info: Many of the image default values are set from this
348 % structure. For example, filename, compression, depth, background color,
351 % o image: the image.
354 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
357 Allocate image structure.
359 assert(image != (Image *) NULL);
360 assert(image->signature == MagickSignature);
361 if (image->debug != MagickFalse)
362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
363 image->next=AcquireImage(image_info);
364 if (GetNextImageInList(image) == (Image *) NULL)
366 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
368 if (image_info != (ImageInfo *) NULL)
369 (void) CopyMagickString(GetNextImageInList(image)->filename,
370 image_info->filename,MaxTextExtent);
371 DestroyBlob(GetNextImageInList(image));
372 image->next->blob=ReferenceBlob(image->blob);
373 image->next->endian=image->endian;
374 image->next->scene=image->scene+1;
375 image->next->previous=image;
379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 % A p p e n d I m a g e s %
387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 % AppendImages() takes all images from the current image pointer to the end
390 % of the image list and appends them to each other top-to-bottom if the
391 % stack parameter is true, otherwise left-to-right.
393 % The current gravity setting now effects how the image is justified in the
396 % The format of the AppendImages method is:
398 % Image *AppendImages(const Image *image,const MagickBooleanType stack,
399 % ExceptionInfo *exception)
401 % A description of each parameter follows:
403 % o image: the image sequence.
405 % o stack: A value other than 0 stacks the images top-to-bottom.
407 % o exception: return any errors or warnings in this structure.
410 MagickExport Image *AppendImages(const Image *image,
411 const MagickBooleanType stack,ExceptionInfo *exception)
413 #define AppendImageTag "Append/Image"
447 Ensure the image have the same column width.
449 assert(image != (Image *) NULL);
450 assert(image->signature == MagickSignature);
451 if (image->debug != MagickFalse)
452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
453 assert(exception != (ExceptionInfo *) NULL);
454 assert(exception->signature == MagickSignature);
457 width=image->columns;
459 next=GetNextImageInList(image);
460 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
462 if (next->matte != MagickFalse)
465 if (stack != MagickFalse)
467 if (next->columns > width)
472 width+=next->columns;
473 if (next->rows > height)
477 Initialize append next attributes.
479 append_image=CloneImage(image,width,height,MagickTrue,exception);
480 if (append_image == (Image *) NULL)
481 return((Image *) NULL);
482 if (SetImageStorageClass(append_image,DirectClass) == MagickFalse)
484 InheritException(exception,&append_image->exception);
485 append_image=DestroyImage(append_image);
486 return((Image *) NULL);
488 append_image->matte=matte;
489 (void) SetImageBackgroundColor(append_image);
493 append_view=AcquireCacheView(append_image);
494 for (n=0; n < (MagickOffsetType) number_images; n++)
496 SetGeometry(append_image,&geometry);
497 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
498 if (stack != MagickFalse)
499 x_offset-=geometry.x;
501 y_offset-=geometry.y;
502 image_view=AcquireCacheView(image);
503 #if defined(MAGICKCORE_OPENMP_SUPPORT)
504 #pragma omp parallel for schedule(dynamic,4) shared(status)
506 for (y=0; y < (ssize_t) image->rows; y++)
511 register const IndexPacket
514 register const PixelPacket
518 *restrict append_indexes;
526 if (status == MagickFalse)
528 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
529 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
530 image->columns,1,exception);
531 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
536 indexes=GetCacheViewVirtualIndexQueue(image_view);
537 append_indexes=GetCacheViewAuthenticIndexQueue(append_view);
538 for (x=0; x < (ssize_t) image->columns; x++)
540 SetRedPixelComponent(q,GetRedPixelComponent(p));
541 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
542 SetBluePixelComponent(q,GetBluePixelComponent(p));
543 SetOpacityPixelComponent(q,OpaqueOpacity);
544 if (image->matte != MagickFalse)
545 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
546 if (image->colorspace == CMYKColorspace)
547 append_indexes[x]=indexes[x];
551 sync=SyncCacheViewAuthenticPixels(append_view,exception);
552 if (sync == MagickFalse)
555 image_view=DestroyCacheView(image_view);
556 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
557 if (proceed == MagickFalse)
559 if (stack == MagickFalse)
561 x_offset+=(ssize_t) image->columns;
567 y_offset+=(ssize_t) image->rows;
569 image=GetNextImageInList(image);
571 append_view=DestroyCacheView(append_view);
572 if (status == MagickFalse)
573 append_image=DestroyImage(append_image);
574 return(append_image);
578 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582 % C a t c h I m a g e E x c e p t i o n %
586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
588 % CatchImageException() returns if no exceptions are found in the image
589 % sequence, otherwise it determines the most severe exception and reports
590 % it as a warning or error depending on the severity.
592 % The format of the CatchImageException method is:
594 % ExceptionType CatchImageException(Image *image)
596 % A description of each parameter follows:
598 % o image: An image sequence.
601 MagickExport ExceptionType CatchImageException(Image *image)
609 assert(image != (const Image *) NULL);
610 assert(image->signature == MagickSignature);
611 if (image->debug != MagickFalse)
612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
613 exception=AcquireExceptionInfo();
614 GetImageException(image,exception);
615 CatchException(exception);
616 severity=exception->severity;
617 exception=DestroyExceptionInfo(exception);
622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
626 % C l i p I m a g e P a t h %
630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
632 % ClipImagePath() sets the image clip mask based any clipping path information
635 % The format of the ClipImagePath method is:
637 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
638 % const MagickBooleanType inside)
640 % A description of each parameter follows:
642 % o image: the image.
644 % o pathname: name of clipping path resource. If name is preceded by #, use
645 % clipping path numbered by name.
647 % o inside: if non-zero, later operations take effect inside clipping path.
648 % Otherwise later operations take effect outside clipping path.
652 MagickExport MagickBooleanType ClipImage(Image *image)
654 return(ClipImagePath(image,"#1",MagickTrue));
657 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
658 const MagickBooleanType inside)
660 #define ClipImagePathTag "ClipPath/Image"
674 assert(image != (const Image *) NULL);
675 assert(image->signature == MagickSignature);
676 if (image->debug != MagickFalse)
677 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
678 assert(pathname != NULL);
679 property=AcquireString(pathname);
680 (void) FormatMagickString(property,MaxTextExtent,"8BIM:1999,2998:%s",
682 value=GetImageProperty(image,property);
683 property=DestroyString(property);
684 if (value == (const char *) NULL)
686 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
690 image_info=AcquireImageInfo();
691 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
692 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
693 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
694 image_info=DestroyImageInfo(image_info);
695 if (clip_mask == (Image *) NULL)
697 if (clip_mask->storage_class == PseudoClass)
699 (void) SyncImage(clip_mask);
700 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
703 if (inside == MagickFalse)
704 (void) NegateImage(clip_mask,MagickFalse);
705 (void) FormatMagickString(clip_mask->magick_filename,MaxTextExtent,
706 "8BIM:1999,2998:%s\nPS",pathname);
707 (void) SetImageClipMask(image,clip_mask);
708 clip_mask=DestroyImage(clip_mask);
713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
717 % C l o n e I m a g e %
721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723 % CloneImage() copies an image and returns the copy as a new image object.
724 % If the specified columns and rows is 0, an exact copy of the image is
725 % returned, otherwise the pixel data is undefined and must be initialized
726 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
727 % failure, a NULL image is returned and exception describes the reason for the
730 % The format of the CloneImage method is:
732 % Image *CloneImage(const Image *image,const size_t columns,
733 % const size_t rows,const MagickBooleanType orphan,
734 % ExceptionInfo *exception)
736 % A description of each parameter follows:
738 % o image: the image.
740 % o columns: the number of columns in the cloned image.
742 % o rows: the number of rows in the cloned image.
744 % o detach: With a value other than 0, the cloned image is detached from
745 % its parent I/O stream.
747 % o exception: return any errors or warnings in this structure.
750 MagickExport Image *CloneImage(const Image *image,const size_t columns,
751 const size_t rows,const MagickBooleanType detach,
752 ExceptionInfo *exception)
766 assert(image != (const Image *) NULL);
767 assert(image->signature == MagickSignature);
768 if (image->debug != MagickFalse)
769 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
770 assert(exception != (ExceptionInfo *) NULL);
771 assert(exception->signature == MagickSignature);
772 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
773 if (clone_image == (Image *) NULL)
774 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
775 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
776 clone_image->signature=MagickSignature;
777 clone_image->storage_class=image->storage_class;
778 clone_image->colorspace=image->colorspace;
779 clone_image->matte=image->matte;
780 clone_image->columns=image->columns;
781 clone_image->rows=image->rows;
782 clone_image->dither=image->dither;
783 if (image->colormap != (PixelPacket *) NULL)
786 Allocate and copy the image colormap.
788 clone_image->colors=image->colors;
789 length=(size_t) image->colors;
790 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
791 sizeof(*clone_image->colormap));
792 if (clone_image->colormap == (PixelPacket *) NULL)
793 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
794 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
795 sizeof(*clone_image->colormap));
797 (void) CloneImageProfiles(clone_image,image);
798 (void) CloneImageProperties(clone_image,image);
799 (void) CloneImageArtifacts(clone_image,image);
800 GetTimerInfo(&clone_image->timer);
801 GetExceptionInfo(&clone_image->exception);
802 InheritException(&clone_image->exception,&image->exception);
803 if (image->ascii85 != (void *) NULL)
804 Ascii85Initialize(clone_image);
805 clone_image->magick_columns=image->magick_columns;
806 clone_image->magick_rows=image->magick_rows;
807 clone_image->type=image->type;
808 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
810 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
811 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
812 clone_image->progress_monitor=image->progress_monitor;
813 clone_image->client_data=image->client_data;
814 clone_image->reference_count=1;
815 clone_image->next=NewImageList();
816 clone_image->previous=NewImageList();
817 clone_image->list=NewImageList();
818 clone_image->clip_mask=NewImageList();
819 clone_image->mask=NewImageList();
820 if (detach == MagickFalse)
821 clone_image->blob=ReferenceBlob(image->blob);
823 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
824 clone_image->ping=image->ping;
825 clone_image->debug=IsEventLogging();
826 clone_image->semaphore=AllocateSemaphoreInfo();
827 if ((columns == 0) && (rows == 0))
829 if (image->montage != (char *) NULL)
830 (void) CloneString(&clone_image->montage,image->montage);
831 if (image->directory != (char *) NULL)
832 (void) CloneString(&clone_image->directory,image->directory);
833 if (image->clip_mask != (Image *) NULL)
834 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
836 if (image->mask != (Image *) NULL)
837 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
838 clone_image->cache=ReferencePixelCache(image->cache);
841 scale=(MagickRealType) columns/(MagickRealType) image->columns;
842 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
843 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
844 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
845 scale=(MagickRealType) rows/(MagickRealType) image->rows;
846 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
847 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
848 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
849 clone_image->columns=columns;
850 clone_image->rows=rows;
851 clone_image->cache=ClonePixelCache(image->cache);
856 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
860 % C l o n e I m a g e I n f o %
864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
866 % CloneImageInfo() makes a copy of the given image info structure. If
867 % NULL is specified, a new image info structure is created initialized to
870 % The format of the CloneImageInfo method is:
872 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
874 % A description of each parameter follows:
876 % o image_info: the image info.
879 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
884 clone_info=AcquireImageInfo();
885 if (image_info == (ImageInfo *) NULL)
887 clone_info->compression=image_info->compression;
888 clone_info->temporary=image_info->temporary;
889 clone_info->adjoin=image_info->adjoin;
890 clone_info->antialias=image_info->antialias;
891 clone_info->scene=image_info->scene;
892 clone_info->number_scenes=image_info->number_scenes;
893 clone_info->depth=image_info->depth;
894 if (image_info->size != (char *) NULL)
895 (void) CloneString(&clone_info->size,image_info->size);
896 if (image_info->extract != (char *) NULL)
897 (void) CloneString(&clone_info->extract,image_info->extract);
898 if (image_info->scenes != (char *) NULL)
899 (void) CloneString(&clone_info->scenes,image_info->scenes);
900 if (image_info->page != (char *) NULL)
901 (void) CloneString(&clone_info->page,image_info->page);
902 clone_info->interlace=image_info->interlace;
903 clone_info->endian=image_info->endian;
904 clone_info->units=image_info->units;
905 clone_info->quality=image_info->quality;
906 if (image_info->sampling_factor != (char *) NULL)
907 (void) CloneString(&clone_info->sampling_factor,
908 image_info->sampling_factor);
909 if (image_info->server_name != (char *) NULL)
910 (void) CloneString(&clone_info->server_name,image_info->server_name);
911 if (image_info->font != (char *) NULL)
912 (void) CloneString(&clone_info->font,image_info->font);
913 if (image_info->texture != (char *) NULL)
914 (void) CloneString(&clone_info->texture,image_info->texture);
915 if (image_info->density != (char *) NULL)
916 (void) CloneString(&clone_info->density,image_info->density);
917 clone_info->pointsize=image_info->pointsize;
918 clone_info->fuzz=image_info->fuzz;
919 clone_info->pen=image_info->pen;
920 clone_info->background_color=image_info->background_color;
921 clone_info->border_color=image_info->border_color;
922 clone_info->matte_color=image_info->matte_color;
923 clone_info->transparent_color=image_info->transparent_color;
924 clone_info->dither=image_info->dither;
925 clone_info->monochrome=image_info->monochrome;
926 clone_info->colors=image_info->colors;
927 clone_info->colorspace=image_info->colorspace;
928 clone_info->type=image_info->type;
929 clone_info->orientation=image_info->orientation;
930 clone_info->preview_type=image_info->preview_type;
931 clone_info->group=image_info->group;
932 clone_info->ping=image_info->ping;
933 clone_info->verbose=image_info->verbose;
934 if (image_info->view != (char *) NULL)
935 (void) CloneString(&clone_info->view,image_info->view);
936 if (image_info->authenticate != (char *) NULL)
937 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
938 (void) CloneImageOptions(clone_info,image_info);
939 clone_info->progress_monitor=image_info->progress_monitor;
940 clone_info->client_data=image_info->client_data;
941 clone_info->cache=image_info->cache;
942 if (image_info->cache != (void *) NULL)
943 clone_info->cache=ReferencePixelCache(image_info->cache);
944 if (image_info->profile != (void *) NULL)
945 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
946 image_info->profile);
947 SetImageInfoFile(clone_info,image_info->file);
948 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
949 clone_info->stream=image_info->stream;
950 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
951 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
952 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
953 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
954 (void) CopyMagickString(clone_info->filename,image_info->filename,
956 clone_info->subimage=image_info->scene; /* deprecated */
957 clone_info->subrange=image_info->number_scenes; /* deprecated */
958 clone_info->channel=image_info->channel;
959 clone_info->debug=IsEventLogging();
960 clone_info->signature=image_info->signature;
965 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
969 % C o m b i n e I m a g e s %
973 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975 % CombineImages() combines one or more images into a single image. The
976 % grayscale value of the pixels of each image in the sequence is assigned in
977 % order to the specified channels of the combined image. The typical
978 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
980 % The format of the CombineImages method is:
982 % Image *CombineImages(const Image *image,const ChannelType channel,
983 % ExceptionInfo *exception)
985 % A description of each parameter follows:
987 % o image: the image.
989 % o exception: return any errors or warnings in this structure.
992 MagickExport Image *CombineImages(const Image *image,const ChannelType channel,
993 ExceptionInfo *exception)
995 #define CombineImageTag "Combine/Image"
1016 Ensure the image are the same size.
1018 assert(image != (const Image *) NULL);
1019 assert(image->signature == MagickSignature);
1020 if (image->debug != MagickFalse)
1021 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1022 assert(exception != (ExceptionInfo *) NULL);
1023 assert(exception->signature == MagickSignature);
1024 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1026 if ((next->columns != image->columns) || (next->rows != image->rows))
1027 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1029 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1030 if (combine_image == (Image *) NULL)
1031 return((Image *) NULL);
1032 if (SetImageStorageClass(combine_image,DirectClass) == MagickFalse)
1034 InheritException(exception,&combine_image->exception);
1035 combine_image=DestroyImage(combine_image);
1036 return((Image *) NULL);
1038 if ((channel & OpacityChannel) != 0)
1039 combine_image->matte=MagickTrue;
1040 (void) SetImageBackgroundColor(combine_image);
1046 combine_view=AcquireCacheView(combine_image);
1047 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1048 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1050 for (y=0; y < (ssize_t) combine_image->rows; y++)
1061 register const PixelPacket
1064 register PixelPacket
1070 if (status == MagickFalse)
1072 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1074 if (pixels == (PixelPacket *) NULL)
1080 if (((channel & RedChannel) != 0) && (next != (Image *) NULL))
1082 image_view=AcquireCacheView(next);
1083 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1084 if (p == (const PixelPacket *) NULL)
1087 for (x=0; x < (ssize_t) combine_image->columns; x++)
1089 SetRedPixelComponent(q,PixelIntensityToQuantum(p));
1093 image_view=DestroyCacheView(image_view);
1094 next=GetNextImageInList(next);
1096 if (((channel & GreenChannel) != 0) && (next != (Image *) NULL))
1098 image_view=AcquireCacheView(next);
1099 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1100 if (p == (const PixelPacket *) NULL)
1103 for (x=0; x < (ssize_t) combine_image->columns; x++)
1105 SetGreenPixelComponent(q,PixelIntensityToQuantum(p));
1109 image_view=DestroyCacheView(image_view);
1110 next=GetNextImageInList(next);
1112 if (((channel & BlueChannel) != 0) && (next != (Image *) NULL))
1114 image_view=AcquireCacheView(next);
1115 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1116 if (p == (const PixelPacket *) NULL)
1119 for (x=0; x < (ssize_t) combine_image->columns; x++)
1121 SetBluePixelComponent(q,PixelIntensityToQuantum(p));
1125 image_view=DestroyCacheView(image_view);
1126 next=GetNextImageInList(next);
1128 if (((channel & OpacityChannel) != 0) && (next != (Image *) NULL))
1130 image_view=AcquireCacheView(next);
1131 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1132 if (p == (const PixelPacket *) NULL)
1135 for (x=0; x < (ssize_t) combine_image->columns; x++)
1137 SetOpacityPixelComponent(q,PixelIntensityToQuantum(p));
1141 image_view=DestroyCacheView(image_view);
1142 next=GetNextImageInList(next);
1144 if (((channel & IndexChannel) != 0) &&
1145 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1150 image_view=AcquireCacheView(next);
1151 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1152 if (p == (const PixelPacket *) NULL)
1154 indexes=GetCacheViewAuthenticIndexQueue(combine_view);
1155 for (x=0; x < (ssize_t) combine_image->columns; x++)
1157 indexes[x]=PixelIntensityToQuantum(p);
1160 image_view=DestroyCacheView(image_view);
1161 next=GetNextImageInList(next);
1163 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1165 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1170 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1171 #pragma omp critical (MagickCore_CombineImages)
1173 proceed=SetImageProgress(image,CombineImageTag,progress++,
1174 combine_image->rows);
1175 if (proceed == MagickFalse)
1179 combine_view=DestroyCacheView(combine_view);
1180 if (status == MagickFalse)
1181 combine_image=DestroyImage(combine_image);
1182 return(combine_image);
1186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1190 % D e s t r o y I m a g e %
1194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1196 % DestroyImage() dereferences an image, deallocating memory associated with
1197 % the image if the reference count becomes zero.
1199 % The format of the DestroyImage method is:
1201 % Image *DestroyImage(Image *image)
1203 % A description of each parameter follows:
1205 % o image: the image.
1208 MagickExport Image *DestroyImage(Image *image)
1216 assert(image != (Image *) NULL);
1217 assert(image->signature == MagickSignature);
1218 if (image->debug != MagickFalse)
1219 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1220 destroy=MagickFalse;
1221 LockSemaphoreInfo(image->semaphore);
1222 image->reference_count--;
1223 if (image->reference_count == 0)
1225 UnlockSemaphoreInfo(image->semaphore);
1226 if (destroy == MagickFalse)
1227 return((Image *) NULL);
1231 DestroyImagePixels(image);
1232 if (image->clip_mask != (Image *) NULL)
1233 image->clip_mask=DestroyImage(image->clip_mask);
1234 if (image->mask != (Image *) NULL)
1235 image->mask=DestroyImage(image->mask);
1236 if (image->montage != (char *) NULL)
1237 image->montage=DestroyString(image->montage);
1238 if (image->directory != (char *) NULL)
1239 image->directory=DestroyString(image->directory);
1240 if (image->colormap != (PixelPacket *) NULL)
1241 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1242 if (image->geometry != (char *) NULL)
1243 image->geometry=DestroyString(image->geometry);
1244 DestroyImageProfiles(image);
1245 DestroyImageProperties(image);
1246 DestroyImageArtifacts(image);
1247 if (image->ascii85 != (Ascii85Info*) NULL)
1248 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1250 (void) DestroyExceptionInfo(&image->exception);
1251 if (image->semaphore != (SemaphoreInfo *) NULL)
1252 DestroySemaphoreInfo(&image->semaphore);
1253 image->signature=(~MagickSignature);
1254 image=(Image *) RelinquishMagickMemory(image);
1259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1263 % D e s t r o y I m a g e I n f o %
1267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1269 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1272 % The format of the DestroyImageInfo method is:
1274 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1276 % A description of each parameter follows:
1278 % o image_info: the image info.
1281 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1283 assert(image_info != (ImageInfo *) NULL);
1284 assert(image_info->signature == MagickSignature);
1285 if (image_info->debug != MagickFalse)
1286 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1287 image_info->filename);
1288 if (image_info->size != (char *) NULL)
1289 image_info->size=DestroyString(image_info->size);
1290 if (image_info->extract != (char *) NULL)
1291 image_info->extract=DestroyString(image_info->extract);
1292 if (image_info->scenes != (char *) NULL)
1293 image_info->scenes=DestroyString(image_info->scenes);
1294 if (image_info->page != (char *) NULL)
1295 image_info->page=DestroyString(image_info->page);
1296 if (image_info->sampling_factor != (char *) NULL)
1297 image_info->sampling_factor=DestroyString(
1298 image_info->sampling_factor);
1299 if (image_info->server_name != (char *) NULL)
1300 image_info->server_name=DestroyString(
1301 image_info->server_name);
1302 if (image_info->font != (char *) NULL)
1303 image_info->font=DestroyString(image_info->font);
1304 if (image_info->texture != (char *) NULL)
1305 image_info->texture=DestroyString(image_info->texture);
1306 if (image_info->density != (char *) NULL)
1307 image_info->density=DestroyString(image_info->density);
1308 if (image_info->view != (char *) NULL)
1309 image_info->view=DestroyString(image_info->view);
1310 if (image_info->authenticate != (char *) NULL)
1311 image_info->authenticate=DestroyString(
1312 image_info->authenticate);
1313 DestroyImageOptions(image_info);
1314 if (image_info->cache != (void *) NULL)
1315 image_info->cache=DestroyPixelCache(image_info->cache);
1316 if (image_info->profile != (StringInfo *) NULL)
1317 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1318 image_info->profile);
1319 image_info->signature=(~MagickSignature);
1320 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1329 + D i s a s s o c i a t e I m a g e S t r e a m %
1333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1335 % DisassociateImageStream() disassociates the image stream.
1337 % The format of the DisassociateImageStream method is:
1339 % MagickBooleanType DisassociateImageStream(const Image *image)
1341 % A description of each parameter follows:
1343 % o image: the image.
1346 MagickExport void DisassociateImageStream(Image *image)
1348 assert(image != (const Image *) NULL);
1349 assert(image->signature == MagickSignature);
1350 if (image->debug != MagickFalse)
1351 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1352 (void) DetachBlob(image->blob);
1356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1360 % G e t I m a g e A l p h a C h a n n e l %
1364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1366 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1367 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1370 % The format of the GetImageAlphaChannel method is:
1372 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1374 % A description of each parameter follows:
1376 % o image: the image.
1379 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1381 assert(image != (const Image *) NULL);
1382 if (image->debug != MagickFalse)
1383 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1384 assert(image->signature == MagickSignature);
1385 return(image->matte);
1389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393 % G e t I m a g e C l i p M a s k %
1397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1399 % GetImageClipMask() returns the clip path associated with the image.
1401 % The format of the GetImageClipMask method is:
1403 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1405 % A description of each parameter follows:
1407 % o image: the image.
1410 MagickExport Image *GetImageClipMask(const Image *image,
1411 ExceptionInfo *exception)
1413 assert(image != (const Image *) NULL);
1414 if (image->debug != MagickFalse)
1415 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1416 assert(image->signature == MagickSignature);
1417 if (image->clip_mask == (Image *) NULL)
1418 return((Image *) NULL);
1419 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1427 % G e t I m a g e E x c e p t i o n %
1431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1433 % GetImageException() traverses an image sequence and returns any
1434 % error more severe than noted by the exception parameter.
1436 % The format of the GetImageException method is:
1438 % void GetImageException(Image *image,ExceptionInfo *exception)
1440 % A description of each parameter follows:
1442 % o image: Specifies a pointer to a list of one or more images.
1444 % o exception: return the highest severity exception.
1447 MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1452 assert(image != (Image *) NULL);
1453 assert(image->signature == MagickSignature);
1454 if (image->debug != MagickFalse)
1455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1456 assert(exception != (ExceptionInfo *) NULL);
1457 assert(exception->signature == MagickSignature);
1458 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1460 if (next->exception.severity == UndefinedException)
1462 if (next->exception.severity > exception->severity)
1463 InheritException(exception,&next->exception);
1464 next->exception.severity=UndefinedException;
1469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1473 % G e t I m a g e I n f o %
1477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1479 % GetImageInfo() initializes image_info to default values.
1481 % The format of the GetImageInfo method is:
1483 % void GetImageInfo(ImageInfo *image_info)
1485 % A description of each parameter follows:
1487 % o image_info: the image info.
1490 MagickExport void GetImageInfo(ImageInfo *image_info)
1499 File and image dimension members.
1501 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1502 assert(image_info != (ImageInfo *) NULL);
1503 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1504 image_info->adjoin=MagickTrue;
1505 image_info->interlace=NoInterlace;
1506 image_info->channel=DefaultChannels;
1507 image_info->quality=UndefinedCompressionQuality;
1508 image_info->antialias=MagickTrue;
1509 image_info->dither=MagickTrue;
1510 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1511 if (synchronize != (const char *) NULL)
1512 image_info->synchronize=IsMagickTrue(synchronize);
1513 exception=AcquireExceptionInfo();
1514 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1516 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1517 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1518 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1520 exception=DestroyExceptionInfo(exception);
1521 image_info->debug=IsEventLogging();
1522 image_info->signature=MagickSignature;
1526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1530 % G e t I m a g e I n f o F i l e %
1534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1536 % GetImageInfoFile() returns the image info file member.
1538 % The format of the GetImageInfoFile method is:
1540 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1542 % A description of each parameter follows:
1544 % o image_info: the image info.
1547 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1549 return(image_info->file);
1553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1557 % G e t I m a g e M a s k %
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1563 % GetImageMask() returns the mask associated with the image.
1565 % The format of the GetImageMask method is:
1567 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1569 % A description of each parameter follows:
1571 % o image: the image.
1574 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1576 assert(image != (const Image *) NULL);
1577 if (image->debug != MagickFalse)
1578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1579 assert(image->signature == MagickSignature);
1580 if (image->mask == (Image *) NULL)
1581 return((Image *) NULL);
1582 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1590 + G e t I m a g e R e f e r e n c e C o u n t %
1594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1596 % GetImageReferenceCount() returns the image reference count.
1598 % The format of the GetReferenceCount method is:
1600 % ssize_t GetImageReferenceCount(Image *image)
1602 % A description of each parameter follows:
1604 % o image: the image.
1607 MagickExport ssize_t GetImageReferenceCount(Image *image)
1612 assert(image != (Image *) NULL);
1613 assert(image->signature == MagickSignature);
1614 if (image->debug != MagickFalse)
1615 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1616 LockSemaphoreInfo(image->semaphore);
1617 reference_count=image->reference_count;
1618 UnlockSemaphoreInfo(image->semaphore);
1619 return(reference_count);
1623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1627 % 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 %
1631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1633 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1634 % image. A virtual pixel is any pixel access that is outside the boundaries
1635 % of the image cache.
1637 % The format of the GetImageVirtualPixelMethod() method is:
1639 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1641 % A description of each parameter follows:
1643 % o image: the image.
1646 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1648 assert(image != (Image *) NULL);
1649 assert(image->signature == MagickSignature);
1650 if (image->debug != MagickFalse)
1651 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1652 return(GetPixelCacheVirtualMethod(image));
1656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1660 % I n t e r p r e t I m a g e F i l e n a m e %
1664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1666 % InterpretImageFilename() interprets embedded characters in an image filename.
1667 % The filename length is returned.
1669 % The format of the InterpretImageFilename method is:
1671 % size_t InterpretImageFilename(const ImageInfo *image_info,
1672 % Image *image,const char *format,int value,char *filename)
1674 % A description of each parameter follows.
1676 % o image_info: the image info..
1678 % o image: the image.
1680 % o format: A filename describing the format to use to write the numeric
1681 % argument. Only the first numeric format identifier is replaced.
1683 % o value: Numeric value to substitute into format filename.
1685 % o filename: return the formatted filename in this character buffer.
1688 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1689 Image *image,const char *format,int value,char *filename)
1703 canonical=MagickFalse;
1704 (void) CopyMagickString(filename,format,MaxTextExtent);
1705 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1718 value=(ssize_t) strtol(q,&q,10);
1729 (void) FormatMagickString(filename+(p-format),(size_t) (MaxTextExtent-
1730 (p-format)),p,value);
1732 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1733 canonical=MagickTrue;
1742 pattern[MaxTextExtent];
1759 if (strchr(p,']') == (char *) NULL)
1763 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1774 if (LocaleNCompare(pattern,"filename:",9) != 0)
1776 value=(const char *) NULL;
1777 if ((image_info != (const ImageInfo *) NULL) &&
1778 (image != (const Image *) NULL))
1779 value=GetMagickProperty(image_info,image,pattern);
1781 if (image != (Image *) NULL)
1782 value=GetImageProperty(image,pattern);
1784 if (image_info != (ImageInfo *) NULL)
1785 value=GetImageOption(image_info,pattern);
1786 if (value == (const char *) NULL)
1791 (void) CopyMagickString(filename+(p-format),value,(size_t)
1792 (MaxTextExtent-(p-format)));
1794 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1795 canonical=MagickTrue;
1805 for (q=filename; *q != '\0'; q++)
1806 if ((*q == '%') && (*(q+1) == '%'))
1807 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1808 if (canonical == MagickFalse)
1809 (void) CopyMagickString(filename,format,MaxTextExtent);
1810 return(strlen(filename));
1814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1818 % I s H i g h D y n a m i c R a n g e I m a g e %
1822 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1824 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1825 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1828 % The format of the IsHighDynamicRangeImage method is:
1830 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1831 % ExceptionInfo *exception)
1833 % A description of each parameter follows:
1835 % o image: the image.
1837 % o exception: return any errors or warnings in this structure.
1840 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1841 ExceptionInfo *exception)
1843 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1846 return(MagickFalse);
1860 assert(image != (Image *) NULL);
1861 assert(image->signature == MagickSignature);
1862 if (image->debug != MagickFalse)
1863 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1865 GetMagickPixelPacket(image,&zero);
1866 image_view=AcquireCacheView(image);
1867 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1868 #pragma omp parallel for schedule(dynamic,4) shared(status)
1870 for (y=0; y < (ssize_t) image->rows; y++)
1875 register const IndexPacket
1878 register const PixelPacket
1884 if (status == MagickFalse)
1886 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1887 if (p == (const PixelPacket *) NULL)
1892 indexes=GetCacheViewVirtualIndexQueue(image_view);
1894 for (x=0; x < (ssize_t) image->columns; x++)
1896 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1897 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1898 (pixel.red != (QuantumAny) pixel.red))
1900 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1901 (pixel.green != (QuantumAny) pixel.green))
1903 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1904 (pixel.blue != (QuantumAny) pixel.blue))
1906 if (pixel.matte != MagickFalse)
1908 if ((pixel.opacity < 0.0) || (pixel.opacity > QuantumRange) ||
1909 (pixel.opacity != (QuantumAny) pixel.opacity))
1912 if (pixel.colorspace == CMYKColorspace)
1914 if ((pixel.index < 0.0) || (pixel.index > QuantumRange) ||
1915 (pixel.index != (QuantumAny) pixel.index))
1920 if (x < (ssize_t) image->columns)
1923 image_view=DestroyCacheView(image_view);
1924 return(status != MagickFalse ? MagickFalse : MagickTrue);
1929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1933 % I s I m a g e O b j e c t %
1937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1939 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1940 % set of image objects.
1942 % The format of the IsImageObject method is:
1944 % MagickBooleanType IsImageObject(const Image *image)
1946 % A description of each parameter follows:
1948 % o image: the image.
1951 MagickExport MagickBooleanType IsImageObject(const Image *image)
1953 register const Image
1956 assert(image != (Image *) NULL);
1957 if (image->debug != MagickFalse)
1958 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1959 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1960 if (p->signature != MagickSignature)
1961 return(MagickFalse);
1966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1970 % I s T a i n t I m a g e %
1974 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1976 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1977 % since it was first constituted.
1979 % The format of the IsTaintImage method is:
1981 % MagickBooleanType IsTaintImage(const Image *image)
1983 % A description of each parameter follows:
1985 % o image: the image.
1988 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1991 magick[MaxTextExtent],
1992 filename[MaxTextExtent];
1994 register const Image
1997 assert(image != (Image *) NULL);
1998 if (image->debug != MagickFalse)
1999 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2000 assert(image->signature == MagickSignature);
2001 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2002 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2003 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2005 if (p->taint != MagickFalse)
2007 if (LocaleCompare(p->magick,magick) != 0)
2009 if (LocaleCompare(p->filename,filename) != 0)
2012 return(MagickFalse);
2016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2020 % M o d i f y I m a g e %
2024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2026 % ModifyImage() ensures that there is only a single reference to the image
2027 % to be modified, updating the provided image pointer to point to a clone of
2028 % the original image if necessary.
2030 % The format of the ModifyImage method is:
2032 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2034 % A description of each parameter follows:
2036 % o image: the image.
2038 % o exception: return any errors or warnings in this structure.
2041 MagickExport MagickBooleanType ModifyImage(Image **image,
2042 ExceptionInfo *exception)
2047 assert(image != (Image **) NULL);
2048 assert(*image != (Image *) NULL);
2049 assert((*image)->signature == MagickSignature);
2050 if ((*image)->debug != MagickFalse)
2051 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2052 if (GetImageReferenceCount(*image) <= 1)
2054 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2055 LockSemaphoreInfo((*image)->semaphore);
2056 (*image)->reference_count--;
2057 UnlockSemaphoreInfo((*image)->semaphore);
2063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2067 % N e w M a g i c k I m a g e %
2071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2073 % NewMagickImage() creates a blank image canvas of the specified size and
2076 % The format of the NewMagickImage method is:
2078 % Image *NewMagickImage(const ImageInfo *image_info,
2079 % const size_t width,const size_t height,
2080 % const MagickPixelPacket *background)
2082 % A description of each parameter follows:
2084 % o image: the image.
2086 % o width: the image width.
2088 % o height: the image height.
2090 % o background: the image color.
2093 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2094 const size_t width,const size_t height,
2095 const MagickPixelPacket *background)
2112 assert(image_info != (const ImageInfo *) NULL);
2113 if (image_info->debug != MagickFalse)
2114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2115 assert(image_info->signature == MagickSignature);
2116 assert(background != (const MagickPixelPacket *) NULL);
2117 image=AcquireImage(image_info);
2118 image->columns=width;
2120 image->colorspace=background->colorspace;
2121 image->matte=background->matte;
2122 image->fuzz=background->fuzz;
2123 image->depth=background->depth;
2125 exception=(&image->exception);
2126 image_view=AcquireCacheView(image);
2127 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2128 #pragma omp parallel for schedule(dynamic,4) shared(status)
2130 for (y=0; y < (ssize_t) image->rows; y++)
2132 register IndexPacket
2135 register PixelPacket
2141 if (status == MagickFalse)
2143 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2144 if (q == (PixelPacket *) NULL)
2149 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2150 for (x=0; x < (ssize_t) image->columns; x++)
2152 SetPixelPacket(image,background,q,indexes+x);
2155 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2158 image_view=DestroyCacheView(image_view);
2159 if (status == MagickFalse)
2160 image=DestroyImage(image);
2165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2169 % R e f e r e n c e I m a g e %
2173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2175 % ReferenceImage() increments the reference count associated with an image
2176 % returning a pointer to the image.
2178 % The format of the ReferenceImage method is:
2180 % Image *ReferenceImage(Image *image)
2182 % A description of each parameter follows:
2184 % o image: the image.
2187 MagickExport Image *ReferenceImage(Image *image)
2189 assert(image != (Image *) NULL);
2190 if (image->debug != MagickFalse)
2191 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2192 assert(image->signature == MagickSignature);
2193 LockSemaphoreInfo(image->semaphore);
2194 image->reference_count++;
2195 UnlockSemaphoreInfo(image->semaphore);
2200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2204 % R e s e t I m a g e P a g e %
2208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2210 % ResetImagePage() resets the image page canvas and position.
2212 % The format of the ResetImagePage method is:
2214 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2216 % A description of each parameter follows:
2218 % o image: the image.
2220 % o page: the relative page specification.
2223 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2231 assert(image != (Image *) NULL);
2232 assert(image->signature == MagickSignature);
2233 if (image->debug != MagickFalse)
2234 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2235 flags=ParseAbsoluteGeometry(page,&geometry);
2236 if ((flags & WidthValue) != 0)
2238 if ((flags & HeightValue) == 0)
2239 geometry.height=geometry.width;
2240 image->page.width=geometry.width;
2241 image->page.height=geometry.height;
2243 if ((flags & AspectValue) != 0)
2245 if ((flags & XValue) != 0)
2246 image->page.x+=geometry.x;
2247 if ((flags & YValue) != 0)
2248 image->page.y+=geometry.y;
2252 if ((flags & XValue) != 0)
2254 image->page.x=geometry.x;
2255 if ((image->page.width == 0) && (geometry.x > 0))
2256 image->page.width=image->columns+geometry.x;
2258 if ((flags & YValue) != 0)
2260 image->page.y=geometry.y;
2261 if ((image->page.height == 0) && (geometry.y > 0))
2262 image->page.height=image->rows+geometry.y;
2269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2273 % S e p a r a t e I m a g e C h a n n e l %
2277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2279 % SeparateImageChannel() separates a channel from the image and returns it as
2280 % a grayscale image. A channel is a particular color component of each pixel
2283 % The format of the SeparateImageChannel method is:
2285 % MagickBooleanType SeparateImageChannel(Image *image,
2286 % const ChannelType channel)
2288 % A description of each parameter follows:
2290 % o image: the image.
2292 % o channel: Identify which channel to extract: RedChannel, GreenChannel,
2293 % BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2294 % YellowChannel, or BlackChannel.
2297 MagickExport MagickBooleanType SeparateImageChannel(Image *image,
2298 const ChannelType channel)
2300 #define SeparateImageTag "Separate/Image"
2317 assert(image != (Image *) NULL);
2318 assert(image->signature == MagickSignature);
2319 if (image->debug != MagickFalse)
2320 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2321 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2322 return(MagickFalse);
2324 Separate image channels.
2327 if (channel == GrayChannels)
2328 image->matte=MagickTrue;
2330 exception=(&image->exception);
2331 image_view=AcquireCacheView(image);
2332 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2333 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2335 for (y=0; y < (ssize_t) image->rows; y++)
2337 register IndexPacket
2340 register PixelPacket
2346 if (status == MagickFalse)
2348 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2349 if (q == (PixelPacket *) NULL)
2354 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2359 for (x=0; x < (ssize_t) image->columns; x++)
2369 for (x=0; x < (ssize_t) image->columns; x++)
2379 for (x=0; x < (ssize_t) image->columns; x++)
2387 case OpacityChannel:
2389 for (x=0; x < (ssize_t) image->columns; x++)
2392 q->green=q->opacity;
2400 if ((image->storage_class != PseudoClass) &&
2401 (image->colorspace != CMYKColorspace))
2403 for (x=0; x < (ssize_t) image->columns; x++)
2406 q->green=indexes[x];
2412 case TrueAlphaChannel:
2414 for (x=0; x < (ssize_t) image->columns; x++)
2416 q->red=(Quantum) GetAlphaPixelComponent(q);
2417 q->green=(Quantum) GetAlphaPixelComponent(q);
2418 q->blue=(Quantum) GetAlphaPixelComponent(q);
2425 for (x=0; x < (ssize_t) image->columns; x++)
2427 q->opacity=(Quantum) (QuantumRange-PixelIntensityToQuantum(q));
2435 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2437 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2442 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2443 #pragma omp critical (MagickCore_SeparateImageChannel)
2445 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2446 if (proceed == MagickFalse)
2450 image_view=DestroyCacheView(image_view);
2451 if (channel != GrayChannels)
2452 image->matte=MagickFalse;
2453 (void) SetImageColorspace(image,RGBColorspace);
2458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2462 % S e p a r a t e I m a g e s %
2466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2468 % SeparateImages() returns a separate grayscale image for each channel
2471 % The format of the SeparateImages method is:
2473 % MagickBooleanType SeparateImages(const Image *image,
2474 % const ChannelType channel,ExceptionInfo *exception)
2476 % A description of each parameter follows:
2478 % o image: the image.
2480 % o channel: Identify which channels to extract: RedChannel, GreenChannel,
2481 % BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2482 % YellowChannel, or BlackChannel.
2484 % o exception: return any errors or warnings in this structure.
2487 MagickExport Image *SeparateImages(const Image *image,const ChannelType channel,
2488 ExceptionInfo *exception)
2494 assert(image != (Image *) NULL);
2495 assert(image->signature == MagickSignature);
2496 if (image->debug != MagickFalse)
2497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2498 images=NewImageList();
2499 if ((channel & RedChannel) != 0)
2501 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2502 (void) SeparateImageChannel(separate_image,RedChannel);
2503 AppendImageToList(&images,separate_image);
2505 if ((channel & GreenChannel) != 0)
2507 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2508 (void) SeparateImageChannel(separate_image,GreenChannel);
2509 AppendImageToList(&images,separate_image);
2511 if ((channel & BlueChannel) != 0)
2513 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2514 (void) SeparateImageChannel(separate_image,BlueChannel);
2515 AppendImageToList(&images,separate_image);
2517 if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace))
2519 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2520 (void) SeparateImageChannel(separate_image,BlackChannel);
2521 AppendImageToList(&images,separate_image);
2523 if ((channel & OpacityChannel) != 0)
2525 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2526 (void) SeparateImageChannel(separate_image,OpacityChannel);
2527 AppendImageToList(&images,separate_image);
2533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2537 % S e t I m a g e A l p h a C h a n n e l %
2541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2543 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2546 % The format of the SetImageAlphaChannel method is:
2548 % MagickBooleanType SetImageAlphaChannel(Image *image,
2549 % const AlphaChannelType alpha_type)
2551 % A description of each parameter follows:
2553 % o image: the image.
2555 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2556 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2557 % OpaqueAlphaChannel, ResetAlphaChannel, SetAlphaChannel,
2558 % ShapeAlphaChannel, and TransparentAlphaChannel.
2561 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2562 const AlphaChannelType alpha_type)
2567 assert(image != (Image *) NULL);
2568 if (image->debug != MagickFalse)
2569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2570 assert(image->signature == MagickSignature);
2574 case ActivateAlphaChannel:
2576 image->matte=MagickTrue;
2579 case BackgroundAlphaChannel:
2603 Set transparent pixels to background color.
2605 if (image->matte == MagickFalse)
2607 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2609 GetMagickPixelPacket(image,&background);
2610 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2612 if (image->colorspace == CMYKColorspace)
2613 ConvertRGBToCMYK(&background);
2615 SetPixelPacket(image,&background,&pixel,&index);
2617 exception=(&image->exception);
2618 image_view=AcquireCacheView(image);
2619 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2620 #pragma omp parallel for schedule(dynamic,4) shared(status)
2622 for (y=0; y < (ssize_t) image->rows; y++)
2624 register IndexPacket
2627 register PixelPacket
2633 if (status == MagickFalse)
2635 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2637 if (q == (PixelPacket *) NULL)
2642 for (x=0; x < (ssize_t) image->columns; x++)
2644 if (q->opacity == TransparentOpacity)
2647 q->green=pixel.green;
2652 if (image->colorspace == CMYKColorspace)
2654 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2655 for (x=0; x < (ssize_t) image->columns; x++)
2658 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2661 image_view=DestroyCacheView(image_view);
2664 case DeactivateAlphaChannel:
2666 image->matte=MagickFalse;
2669 case ShapeAlphaChannel:
2670 case CopyAlphaChannel:
2673 Special usage case for SeparateImageChannel(): copy grayscale color to
2676 status=SeparateImageChannel(image,GrayChannels);
2677 image->matte=MagickTrue; /* make sure transparency is now on! */
2678 if (alpha_type == ShapeAlphaChannel)
2684 Reset all color channels to background color.
2686 GetMagickPixelPacket(image,&background);
2687 SetMagickPixelPacket(image,&(image->background_color),(IndexPacket *)
2689 (void) LevelColorsImage(image,&background,&background,MagickTrue);
2693 case ExtractAlphaChannel:
2695 status=SeparateImageChannel(image,TrueAlphaChannel);
2696 image->matte=MagickFalse;
2699 case ResetAlphaChannel: /* deprecated */
2700 case OpaqueAlphaChannel:
2702 status=SetImageOpacity(image,OpaqueOpacity);
2703 image->matte=MagickTrue;
2706 case TransparentAlphaChannel:
2708 status=SetImageOpacity(image,TransparentOpacity);
2709 image->matte=MagickTrue;
2712 case SetAlphaChannel:
2714 if (image->matte == MagickFalse)
2716 status=SetImageOpacity(image,OpaqueOpacity);
2717 image->matte=MagickTrue;
2721 case UndefinedAlphaChannel:
2728 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2732 % S e t I m a g e B a c k g r o u n d C o l o r %
2736 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2738 % SetImageBackgroundColor() initializes the image pixels to the image
2739 % background color. The background color is defined by the background_color
2740 % member of the image structure.
2742 % The format of the SetImage method is:
2744 % MagickBooleanType SetImageBackgroundColor(Image *image)
2746 % A description of each parameter follows:
2748 % o image: the image.
2751 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2774 assert(image != (Image *) NULL);
2775 if (image->debug != MagickFalse)
2776 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2777 assert(image->signature == MagickSignature);
2778 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2779 return(MagickFalse);
2780 if (image->background_color.opacity != OpaqueOpacity)
2781 image->matte=MagickTrue;
2782 GetMagickPixelPacket(image,&background);
2783 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2785 if (image->colorspace == CMYKColorspace)
2786 ConvertRGBToCMYK(&background);
2788 SetPixelPacket(image,&background,&pixel,&index);
2790 Set image background color.
2793 exception=(&image->exception);
2794 image_view=AcquireCacheView(image);
2795 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2796 #pragma omp parallel for schedule(dynamic,4) shared(status)
2798 for (y=0; y < (ssize_t) image->rows; y++)
2800 register IndexPacket
2803 register PixelPacket
2809 if (status == MagickFalse)
2811 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2812 if (q == (PixelPacket *) NULL)
2817 for (x=0; x < (ssize_t) image->columns; x++)
2819 if (image->colorspace == CMYKColorspace)
2821 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2822 for (x=0; x < (ssize_t) image->columns; x++)
2825 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2828 image_view=DestroyCacheView(image_view);
2833 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2837 % S e t I m a g e C o l o r %
2841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2843 % SetImageColor() set the entire image canvas to the specified color.
2845 % The format of the SetImageColor method is:
2847 % MagickBooleanType SetImageColor(Image *image,
2848 % const MagickPixelPacket *color)
2850 % A description of each parameter follows:
2852 % o image: the image.
2854 % o background: the image color.
2857 MagickExport MagickBooleanType SetImageColor(Image *image,
2858 const MagickPixelPacket *color)
2872 assert(image != (Image *) NULL);
2873 if (image->debug != MagickFalse)
2874 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2875 assert(image->signature == MagickSignature);
2876 assert(color != (const MagickPixelPacket *) NULL);
2877 image->colorspace=color->colorspace;
2878 image->matte=color->matte;
2879 image->fuzz=color->fuzz;
2880 image->depth=color->depth;
2882 exception=(&image->exception);
2883 image_view=AcquireCacheView(image);
2884 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2885 #pragma omp parallel for schedule(dynamic,4) shared(status)
2887 for (y=0; y < (ssize_t) image->rows; y++)
2889 register IndexPacket
2892 register PixelPacket
2898 if (status == MagickFalse)
2900 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2901 if (q == (PixelPacket *) NULL)
2906 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2907 for (x=0; x < (ssize_t) image->columns; x++)
2909 SetPixelPacket(image,color,q,indexes+x);
2912 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2915 image_view=DestroyCacheView(image_view);
2920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2924 % S e t I m a g e S t o r a g e C l a s s %
2928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2930 % SetImageStorageClass() sets the image class: DirectClass for true color
2931 % images or PseudoClass for colormapped images.
2933 % The format of the SetImageStorageClass method is:
2935 % MagickBooleanType SetImageStorageClass(Image *image,
2936 % const ClassType storage_class)
2938 % A description of each parameter follows:
2940 % o image: the image.
2942 % o storage_class: The image class.
2945 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2946 const ClassType storage_class)
2948 image->storage_class=storage_class;
2953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2957 % S e t I m a g e C l i p M a s k %
2961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2963 % SetImageClipMask() associates a clip path with the image. The clip path
2964 % must be the same dimensions as the image. Set any pixel component of
2965 % the clip path to TransparentOpacity to prevent that corresponding image
2966 % pixel component from being updated when SyncAuthenticPixels() is applied.
2968 % The format of the SetImageClipMask method is:
2970 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2972 % A description of each parameter follows:
2974 % o image: the image.
2976 % o clip_mask: the image clip path.
2979 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2980 const Image *clip_mask)
2982 assert(image != (Image *) NULL);
2983 if (image->debug != MagickFalse)
2984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2985 assert(image->signature == MagickSignature);
2986 if (clip_mask != (const Image *) NULL)
2987 if ((clip_mask->columns != image->columns) ||
2988 (clip_mask->rows != image->rows))
2989 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2990 if (image->clip_mask != (Image *) NULL)
2991 image->clip_mask=DestroyImage(image->clip_mask);
2992 image->clip_mask=NewImageList();
2993 if (clip_mask == (Image *) NULL)
2995 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2996 return(MagickFalse);
2997 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2998 if (image->clip_mask == (Image *) NULL)
2999 return(MagickFalse);
3004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3008 % S e t I m a g e E x t e n t %
3012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3014 % SetImageExtent() sets the image size (i.e. columns & rows).
3016 % The format of the SetImageExtent method is:
3018 % MagickBooleanType SetImageExtent(Image *image,
3019 % const size_t columns,const size_t rows)
3021 % A description of each parameter follows:
3023 % o image: the image.
3025 % o columns: The image width in pixels.
3027 % o rows: The image height in pixels.
3030 MagickExport MagickBooleanType SetImageExtent(Image *image,
3031 const size_t columns,const size_t rows)
3033 if ((columns == 0) || (rows == 0))
3034 return(MagickFalse);
3035 image->columns=columns;
3041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3045 + S e t I m a g e I n f o %
3049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3051 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
3052 % It is set to a type of image format based on the prefix or suffix of the
3053 % filename. For example, `ps:image' returns PS indicating a Postscript image.
3054 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
3055 % precendence over the suffix. Use an optional index enclosed in brackets
3056 % after a file name to specify a desired scene of a multi-resolution image
3057 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
3058 % indicates success.
3060 % The format of the SetImageInfo method is:
3062 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
3063 % const unsigned int frames,ExceptionInfo *exception)
3065 % A description of each parameter follows:
3067 % o image_info: the image info.
3069 % o frames: the number of images you intend to write.
3071 % o exception: return any errors or warnings in this structure.
3074 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
3075 const unsigned int frames,ExceptionInfo *exception)
3078 extension[MaxTextExtent],
3079 filename[MaxTextExtent],
3080 magic[MaxTextExtent],
3082 subimage[MaxTextExtent];
3106 magick[2*MaxTextExtent];
3109 Look for 'image.format' in filename.
3111 assert(image_info != (ImageInfo *) NULL);
3112 assert(image_info->signature == MagickSignature);
3113 if (image_info->debug != MagickFalse)
3114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3115 image_info->filename);
3119 GetPathComponent(image_info->filename,SubimagePath,subimage);
3120 if (*subimage != '\0')
3123 Look for scene specification (e.g. img0001.pcd[4]).
3125 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3127 if (IsGeometry(subimage) != MagickFalse)
3128 (void) CloneString(&image_info->extract,subimage);
3136 (void) CloneString(&image_info->scenes,subimage);
3137 image_info->scene=StringToUnsignedLong(image_info->scenes);
3138 image_info->number_scenes=image_info->scene;
3139 p=image_info->scenes;
3140 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3142 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3145 first=(size_t) strtol(p,&q,10);
3147 while (isspace((int) ((unsigned char) *q)) != 0)
3150 last=(size_t) strtol(q+1,&q,10);
3153 if (first < image_info->scene)
3154 image_info->scene=first;
3155 if (last > image_info->number_scenes)
3156 image_info->number_scenes=last;
3159 image_info->number_scenes-=image_info->scene-1;
3160 image_info->subimage=image_info->scene;
3161 image_info->subrange=image_info->number_scenes;
3166 GetPathComponent(image_info->filename,ExtensionPath,extension);
3167 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3168 if (*extension != '\0')
3169 if ((LocaleCompare(extension,"gz") == 0) ||
3170 (LocaleCompare(extension,"Z") == 0) ||
3171 (LocaleCompare(extension,"wmz") == 0))
3174 path[MaxTextExtent];
3176 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3177 path[strlen(path)-strlen(extension)-1]='\0';
3178 GetPathComponent(path,ExtensionPath,extension);
3181 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3182 if (*extension != '\0')
3183 if (LocaleCompare(extension,"bz2") == 0)
3186 path[MaxTextExtent];
3188 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3189 path[strlen(path)-strlen(extension)-1]='\0';
3190 GetPathComponent(path,ExtensionPath,extension);
3193 image_info->affirm=MagickFalse;
3194 sans_exception=AcquireExceptionInfo();
3195 if (*extension != '\0')
3204 *format_type_formats[] =
3227 User specified image format.
3229 (void) CopyMagickString(magic,extension,MaxTextExtent);
3232 Look for explicit image formats.
3234 format_type=UndefinedFormatType;
3236 while ((format_type == UndefinedFormatType) &&
3237 (format_type_formats[i] != (char *) NULL))
3239 if ((*magic == *format_type_formats[i]) &&
3240 (LocaleCompare(magic,format_type_formats[i]) == 0))
3241 format_type=ExplicitFormatType;
3244 magick_info=GetMagickInfo(magic,sans_exception);
3245 if ((magick_info != (const MagickInfo *) NULL) &&
3246 (magick_info->format_type != UndefinedFormatType))
3247 format_type=magick_info->format_type;
3248 if (format_type == UndefinedFormatType)
3249 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3251 if (format_type == ExplicitFormatType)
3253 image_info->affirm=MagickTrue;
3254 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3256 if (LocaleCompare(magic,"RGB") == 0)
3257 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3260 Look for explicit 'format:image' in filename.
3263 GetPathComponent(image_info->filename,MagickPath,magic);
3265 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3269 User specified image format.
3272 if (IsMagickConflict(magic) == MagickFalse)
3274 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3275 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3276 image_info->affirm=MagickTrue;
3278 image_info->temporary=MagickTrue;
3281 magick_info=GetMagickInfo(magic,sans_exception);
3282 sans_exception=DestroyExceptionInfo(sans_exception);
3283 if ((magick_info == (const MagickInfo *) NULL) ||
3284 (GetMagickEndianSupport(magick_info) == MagickFalse))
3285 image_info->endian=UndefinedEndian;
3286 GetPathComponent(image_info->filename,CanonicalPath,filename);
3287 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3288 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3291 Test for multiple image support (e.g. image%02d.png).
3293 (void) InterpretImageFilename(image_info,(Image *) NULL,
3294 image_info->filename,(int) image_info->scene,filename);
3295 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3296 (strchr(filename,'%') == (char *) NULL))
3297 image_info->adjoin=MagickFalse;
3299 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3302 Some image formats do not support multiple frames per file.
3304 magick_info=GetMagickInfo(magic,exception);
3305 if (magick_info != (const MagickInfo *) NULL)
3306 if (GetMagickAdjoin(magick_info) == MagickFalse)
3307 image_info->adjoin=MagickFalse;
3309 if (image_info->affirm != MagickFalse)
3314 Determine the image format from the first few bytes of the file.
3316 image=AcquireImage(image_info);
3317 (void) CopyMagickString(image->filename,image_info->filename,
3319 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3320 if (status == MagickFalse)
3322 image=DestroyImage(image);
3323 return(MagickFalse);
3325 if ((IsBlobSeekable(image) == MagickFalse) ||
3326 (IsBlobExempt(image) != MagickFalse))
3329 Copy standard input or pipe to temporary file.
3332 status=ImageToFile(image,filename,exception);
3333 (void) CloseBlob(image);
3334 if (status == MagickFalse)
3336 image=DestroyImage(image);
3337 return(MagickFalse);
3339 SetImageInfoFile(image_info,(FILE *) NULL);
3340 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3341 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3342 if (status == MagickFalse)
3344 image=DestroyImage(image);
3345 return(MagickFalse);
3347 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3348 image_info->temporary=MagickTrue;
3350 (void) ResetMagickMemory(magick,0,sizeof(magick));
3351 count=ReadBlob(image,2*MaxTextExtent,magick);
3352 (void) CloseBlob(image);
3353 image=DestroyImage(image);
3355 Check magic.xml configuration file.
3357 sans_exception=AcquireExceptionInfo();
3358 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3359 if ((magic_info != (const MagicInfo *) NULL) &&
3360 (GetMagicName(magic_info) != (char *) NULL))
3362 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3364 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3365 if ((magick_info == (const MagickInfo *) NULL) ||
3366 (GetMagickEndianSupport(magick_info) == MagickFalse))
3367 image_info->endian=UndefinedEndian;
3368 sans_exception=DestroyExceptionInfo(sans_exception);
3371 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3372 if ((magick_info == (const MagickInfo *) NULL) ||
3373 (GetMagickEndianSupport(magick_info) == MagickFalse))
3374 image_info->endian=UndefinedEndian;
3375 sans_exception=DestroyExceptionInfo(sans_exception);
3381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3385 % S e t I m a g e I n f o B l o b %
3389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3391 % SetImageInfoBlob() sets the image info blob member.
3393 % The format of the SetImageInfoBlob method is:
3395 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3396 % const size_t length)
3398 % A description of each parameter follows:
3400 % o image_info: the image info.
3404 % o length: the blob length.
3407 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3408 const size_t length)
3410 assert(image_info != (ImageInfo *) NULL);
3411 assert(image_info->signature == MagickSignature);
3412 if (image_info->debug != MagickFalse)
3413 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3414 image_info->filename);
3415 image_info->blob=(void *) blob;
3416 image_info->length=length;
3420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3424 % S e t I m a g e I n f o F i l e %
3428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3430 % SetImageInfoFile() sets the image info file member.
3432 % The format of the SetImageInfoFile method is:
3434 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3436 % A description of each parameter follows:
3438 % o image_info: the image info.
3443 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3445 assert(image_info != (ImageInfo *) NULL);
3446 assert(image_info->signature == MagickSignature);
3447 if (image_info->debug != MagickFalse)
3448 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3449 image_info->filename);
3450 image_info->file=file;
3454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3458 % S e t I m a g e M a s k %
3462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3464 % SetImageMask() associates a mask with the image. The mask must be the same
3465 % dimensions as the image.
3467 % The format of the SetImageMask method is:
3469 % MagickBooleanType SetImageMask(Image *image,const Image *mask)
3471 % A description of each parameter follows:
3473 % o image: the image.
3475 % o mask: the image mask.
3478 MagickExport MagickBooleanType SetImageMask(Image *image,
3481 assert(image != (Image *) NULL);
3482 if (image->debug != MagickFalse)
3483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3484 assert(image->signature == MagickSignature);
3485 if (mask != (const Image *) NULL)
3486 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3487 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3488 if (image->mask != (Image *) NULL)
3489 image->mask=DestroyImage(image->mask);
3490 image->mask=NewImageList();
3491 if (mask == (Image *) NULL)
3493 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3494 return(MagickFalse);
3495 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3496 if (image->mask == (Image *) NULL)
3497 return(MagickFalse);
3502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3506 % S e t I m a g e O p a c i t y %
3510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3512 % SetImageOpacity() sets the opacity levels of the image.
3514 % The format of the SetImageOpacity method is:
3516 % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3518 % A description of each parameter follows:
3520 % o image: the image.
3522 % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3523 % fully transparent.
3526 MagickExport MagickBooleanType SetImageOpacity(Image *image,
3527 const Quantum opacity)
3541 assert(image != (Image *) NULL);
3542 if (image->debug != MagickFalse)
3543 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3544 assert(image->signature == MagickSignature);
3545 image->matte=opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
3547 exception=(&image->exception);
3548 image_view=AcquireCacheView(image);
3549 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3550 #pragma omp parallel for schedule(dynamic,4) shared(status)
3552 for (y=0; y < (ssize_t) image->rows; y++)
3554 register PixelPacket
3560 if (status == MagickFalse)
3562 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3563 if (q == (PixelPacket *) NULL)
3568 for (x=0; x < (ssize_t) image->columns; x++)
3570 SetOpacityPixelComponent(q,opacity);
3573 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3576 image_view=DestroyCacheView(image_view);
3581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3585 % S e t I m a g e T y p e %
3589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3591 % SetImageType() sets the type of image. Choose from these types:
3593 % Bilevel Grayscale GrayscaleMatte
3594 % Palette PaletteMatte TrueColor
3595 % TrueColorMatte ColorSeparation ColorSeparationMatte
3598 % The format of the SetImageType method is:
3600 % MagickBooleanType SetImageType(Image *image,const ImageType type)
3602 % A description of each parameter follows:
3604 % o image: the image.
3606 % o type: Image type.
3609 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3623 assert(image != (Image *) NULL);
3624 if (image->debug != MagickFalse)
3625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3626 assert(image->signature == MagickSignature);
3628 image_info=AcquireImageInfo();
3629 image_info->dither=image->dither;
3630 artifact=GetImageArtifact(image,"dither");
3631 if (artifact != (const char *) NULL)
3632 (void) SetImageOption(image_info,"dither",artifact);
3637 if (IsGrayImage(image,&image->exception) == MagickFalse)
3638 status=TransformImageColorspace(image,GRAYColorspace);
3639 if (IsMonochromeImage(image,&image->exception) == MagickFalse)
3641 quantize_info=AcquireQuantizeInfo(image_info);
3642 quantize_info->number_colors=2;
3643 quantize_info->colorspace=GRAYColorspace;
3644 status=QuantizeImage(quantize_info,image);
3645 quantize_info=DestroyQuantizeInfo(quantize_info);
3647 image->matte=MagickFalse;
3652 if (IsGrayImage(image,&image->exception) == MagickFalse)
3653 status=TransformImageColorspace(image,GRAYColorspace);
3654 image->matte=MagickFalse;
3657 case GrayscaleMatteType:
3659 if (IsGrayImage(image,&image->exception) == MagickFalse)
3660 status=TransformImageColorspace(image,GRAYColorspace);
3661 if (image->matte == MagickFalse)
3662 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3667 if (image->colorspace != RGBColorspace)
3668 status=TransformImageColorspace(image,RGBColorspace);
3669 if ((image->storage_class == DirectClass) || (image->colors > 256))
3671 quantize_info=AcquireQuantizeInfo(image_info);
3672 quantize_info->number_colors=256;
3673 status=QuantizeImage(quantize_info,image);
3674 quantize_info=DestroyQuantizeInfo(quantize_info);
3676 image->matte=MagickFalse;
3679 case PaletteBilevelMatteType:
3681 if (image->colorspace != RGBColorspace)
3682 status=TransformImageColorspace(image,RGBColorspace);
3683 if (image->matte == MagickFalse)
3684 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3685 (void) BilevelImageChannel(image,AlphaChannel,(double) QuantumRange/2.0);
3686 quantize_info=AcquireQuantizeInfo(image_info);
3687 status=QuantizeImage(quantize_info,image);
3688 quantize_info=DestroyQuantizeInfo(quantize_info);
3691 case PaletteMatteType:
3693 if (image->colorspace != RGBColorspace)
3694 status=TransformImageColorspace(image,RGBColorspace);
3695 if (image->matte == MagickFalse)
3696 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3697 quantize_info=AcquireQuantizeInfo(image_info);
3698 quantize_info->colorspace=TransparentColorspace;
3699 status=QuantizeImage(quantize_info,image);
3700 quantize_info=DestroyQuantizeInfo(quantize_info);
3705 if (image->colorspace != RGBColorspace)
3706 status=TransformImageColorspace(image,RGBColorspace);
3707 if (image->storage_class != DirectClass)
3708 status=SetImageStorageClass(image,DirectClass);
3709 image->matte=MagickFalse;
3712 case TrueColorMatteType:
3714 if (image->colorspace != RGBColorspace)
3715 status=TransformImageColorspace(image,RGBColorspace);
3716 if (image->storage_class != DirectClass)
3717 status=SetImageStorageClass(image,DirectClass);
3718 if (image->matte == MagickFalse)
3719 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3722 case ColorSeparationType:
3724 if (image->colorspace != CMYKColorspace)
3726 if (image->colorspace != RGBColorspace)
3727 status=TransformImageColorspace(image,RGBColorspace);
3728 status=TransformImageColorspace(image,CMYKColorspace);
3730 if (image->storage_class != DirectClass)
3731 status=SetImageStorageClass(image,DirectClass);
3732 image->matte=MagickFalse;
3735 case ColorSeparationMatteType:
3737 if (image->colorspace != CMYKColorspace)
3739 if (image->colorspace != RGBColorspace)
3740 status=TransformImageColorspace(image,RGBColorspace);
3741 status=TransformImageColorspace(image,CMYKColorspace);
3743 if (image->storage_class != DirectClass)
3744 status=SetImageStorageClass(image,DirectClass);
3745 if (image->matte == MagickFalse)
3746 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3754 image_info=DestroyImageInfo(image_info);
3759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3763 % 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 %
3767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3769 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3770 % image and returns the previous setting. A virtual pixel is any pixel access
3771 % that is outside the boundaries of the image cache.
3773 % The format of the SetImageVirtualPixelMethod() method is:
3775 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3776 % const VirtualPixelMethod virtual_pixel_method)
3778 % A description of each parameter follows:
3780 % o image: the image.
3782 % o virtual_pixel_method: choose the type of virtual pixel.
3785 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3786 const VirtualPixelMethod virtual_pixel_method)
3788 assert(image != (const Image *) NULL);
3789 assert(image->signature == MagickSignature);
3790 if (image->debug != MagickFalse)
3791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3792 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3800 % S t r i p I m a g e %
3804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3806 % StripImage() strips an image of all profiles and comments.
3808 % The format of the StripImage method is:
3810 % MagickBooleanType StripImage(Image *image)
3812 % A description of each parameter follows:
3814 % o image: the image.
3817 MagickExport MagickBooleanType StripImage(Image *image)
3819 assert(image != (Image *) NULL);
3820 if (image->debug != MagickFalse)
3821 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3822 DestroyImageProfiles(image);
3823 (void) DeleteImageProperty(image,"comment");
3824 (void) DeleteImageProperty(image,"date:create");
3825 (void) DeleteImageProperty(image,"date:modify");
3830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3834 + S y n c I m a g e %
3838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3840 % SyncImage() initializes the red, green, and blue intensities of each pixel
3841 % as defined by the colormap index.
3843 % The format of the SyncImage method is:
3845 % MagickBooleanType SyncImage(Image *image)
3847 % A description of each parameter follows:
3849 % o image: the image.
3853 static inline IndexPacket PushColormapIndex(Image *image,
3854 const size_t index,MagickBooleanType *range_exception)
3856 if (index < image->colors)
3857 return((IndexPacket) index);
3858 *range_exception=MagickTrue;
3859 return((IndexPacket) 0);
3862 MagickExport MagickBooleanType SyncImage(Image *image)
3877 assert(image != (Image *) NULL);
3878 if (image->debug != MagickFalse)
3879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3880 assert(image->signature == MagickSignature);
3881 if (image->storage_class == DirectClass)
3882 return(MagickFalse);
3883 range_exception=MagickFalse;
3885 exception=(&image->exception);
3886 image_view=AcquireCacheView(image);
3887 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3888 #pragma omp parallel for schedule(dynamic,4) shared(status)
3890 for (y=0; y < (ssize_t) image->rows; y++)
3898 register IndexPacket
3901 register PixelPacket
3907 if (status == MagickFalse)
3909 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3910 if (q == (PixelPacket *) NULL)
3915 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3916 for (x=0; x < (ssize_t) image->columns; x++)
3918 index=PushColormapIndex(image,(size_t) indexes[x],
3920 pixel=image->colormap[(ssize_t) index];
3922 q->green=pixel.green;
3924 if (image->matte != MagickFalse)
3925 q->opacity=pixel.opacity;
3928 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3931 image_view=DestroyCacheView(image_view);
3932 if (range_exception != MagickFalse)
3933 (void) ThrowMagickException(&image->exception,GetMagickModule(),
3934 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
3939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3943 % S y n c I m a g e S e t t i n g s %
3947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3949 % SyncImageSettings() sync the image info options to the image.
3951 % The format of the SyncImageSettings method is:
3953 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3955 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3958 % A description of each parameter follows:
3960 % o image_info: the image info.
3962 % o image: the image.
3966 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3972 assert(image_info != (const ImageInfo *) NULL);
3973 assert(image_info->signature == MagickSignature);
3974 assert(images != (Image *) NULL);
3975 assert(images->signature == MagickSignature);
3976 if (images->debug != MagickFalse)
3977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3979 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3980 (void) SyncImageSettings(image_info,image);
3981 (void) DeleteImageOption(image_info,"page");
3985 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3989 property[MaxTextExtent];
4007 assert(image_info != (const ImageInfo *) NULL);
4008 assert(image_info->signature == MagickSignature);
4009 assert(image != (Image *) NULL);
4010 assert(image->signature == MagickSignature);
4011 if (image->debug != MagickFalse)
4012 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4013 option=GetImageOption(image_info,"background");
4014 if (option != (const char *) NULL)
4015 (void) QueryColorDatabase(option,&image->background_color,
4017 option=GetImageOption(image_info,"bias");
4018 if (option != (const char *) NULL)
4019 image->bias=SiPrefixToDouble(option,QuantumRange);
4020 option=GetImageOption(image_info,"black-point-compensation");
4021 if (option != (const char *) NULL)
4022 image->black_point_compensation=(MagickBooleanType) ParseMagickOption(
4023 MagickBooleanOptions,MagickFalse,option);
4024 option=GetImageOption(image_info,"blue-primary");
4025 if (option != (const char *) NULL)
4027 flags=ParseGeometry(option,&geometry_info);
4028 image->chromaticity.blue_primary.x=geometry_info.rho;
4029 image->chromaticity.blue_primary.y=geometry_info.sigma;
4030 if ((flags & SigmaValue) == 0)
4031 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4033 option=GetImageOption(image_info,"bordercolor");
4034 if (option != (const char *) NULL)
4035 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4036 option=GetImageOption(image_info,"colors");
4037 if (option != (const char *) NULL)
4038 image->colors=StringToUnsignedLong(option);
4039 option=GetImageOption(image_info,"compose");
4040 if (option != (const char *) NULL)
4041 image->compose=(CompositeOperator) ParseMagickOption(MagickComposeOptions,
4042 MagickFalse,option);
4043 option=GetImageOption(image_info,"compress");
4044 if (option != (const char *) NULL)
4045 image->compression=(CompressionType) ParseMagickOption(
4046 MagickCompressOptions,MagickFalse,option);
4047 option=GetImageOption(image_info,"debug");
4048 if (option != (const char *) NULL)
4049 image->debug=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4050 MagickFalse,option);
4051 option=GetImageOption(image_info,"density");
4052 if (option != (const char *) NULL)
4060 flags=ParseGeometry(option,&geometry_info);
4061 image->x_resolution=geometry_info.rho;
4062 image->y_resolution=geometry_info.sigma;
4063 if ((flags & SigmaValue) == 0)
4064 image->y_resolution=image->x_resolution;
4066 option=GetImageOption(image_info,"depth");
4067 if (option != (const char *) NULL)
4068 image->depth=StringToUnsignedLong(option);
4069 option=GetImageOption(image_info,"endian");
4070 if (option != (const char *) NULL)
4071 image->endian=(EndianType) ParseMagickOption(MagickEndianOptions,
4072 MagickFalse,option);
4073 if (image_info->extract != (char *) NULL)
4074 (void) ParseAbsoluteGeometry(image_info->extract,&image->extract_info);
4075 option=GetImageOption(image_info,"filter");
4076 if (option != (const char *) NULL)
4077 image->filter=(FilterTypes) ParseMagickOption(MagickFilterOptions,
4078 MagickFalse,option);
4079 option=GetImageOption(image_info,"fuzz");
4080 if (option != (const char *) NULL)
4081 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4082 option=GetImageOption(image_info,"gravity");
4083 if (option != (const char *) NULL)
4084 image->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4085 MagickFalse,option);
4086 option=GetImageOption(image_info,"green-primary");
4087 if (option != (const char *) NULL)
4089 flags=ParseGeometry(option,&geometry_info);
4090 image->chromaticity.green_primary.x=geometry_info.rho;
4091 image->chromaticity.green_primary.y=geometry_info.sigma;
4092 if ((flags & SigmaValue) == 0)
4093 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4095 option=GetImageOption(image_info,"intent");
4096 if (option != (const char *) NULL)
4097 image->rendering_intent=(RenderingIntent) ParseMagickOption(
4098 MagickIntentOptions,MagickFalse,option);
4099 option=GetImageOption(image_info,"interlace");
4100 if (option != (const char *) NULL)
4101 image->interlace=(InterlaceType) ParseMagickOption(MagickInterlaceOptions,
4102 MagickFalse,option);
4103 option=GetImageOption(image_info,"interpolate");
4104 if (option != (const char *) NULL)
4105 image->interpolate=(InterpolatePixelMethod) ParseMagickOption(
4106 MagickInterpolateOptions,MagickFalse,option);
4107 option=GetImageOption(image_info,"loop");
4108 if (option != (const char *) NULL)
4109 image->iterations=StringToUnsignedLong(option);
4110 option=GetImageOption(image_info,"mattecolor");
4111 if (option != (const char *) NULL)
4112 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4113 option=GetImageOption(image_info,"orient");
4114 if (option != (const char *) NULL)
4115 image->orientation=(OrientationType) ParseMagickOption(
4116 MagickOrientationOptions,MagickFalse,option);
4117 option=GetImageOption(image_info,"page");
4118 if (option != (const char *) NULL)
4123 geometry=GetPageGeometry(option);
4124 flags=ParseAbsoluteGeometry(geometry,&image->page);
4125 geometry=DestroyString(geometry);
4127 option=GetImageOption(image_info,"quality");
4128 if (option != (const char *) NULL)
4129 image->quality=StringToUnsignedLong(option);
4130 option=GetImageOption(image_info,"red-primary");
4131 if (option != (const char *) NULL)
4133 flags=ParseGeometry(option,&geometry_info);
4134 image->chromaticity.red_primary.x=geometry_info.rho;
4135 image->chromaticity.red_primary.y=geometry_info.sigma;
4136 if ((flags & SigmaValue) == 0)
4137 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4139 if (image_info->quality != UndefinedCompressionQuality)
4140 image->quality=image_info->quality;
4141 option=GetImageOption(image_info,"scene");
4142 if (option != (const char *) NULL)
4143 image->scene=StringToUnsignedLong(option);
4144 option=GetImageOption(image_info,"taint");
4145 if (option != (const char *) NULL)
4146 image->taint=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4147 MagickFalse,option);
4148 option=GetImageOption(image_info,"tile-offset");
4149 if (option != (const char *) NULL)
4154 geometry=GetPageGeometry(option);
4155 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4156 geometry=DestroyString(geometry);
4158 option=GetImageOption(image_info,"transparent-color");
4159 if (option != (const char *) NULL)
4160 (void) QueryColorDatabase(option,&image->transparent_color,
4162 option=GetImageOption(image_info,"type");
4163 if (option != (const char *) NULL)
4164 image->type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
4166 option=GetImageOption(image_info,"units");
4167 if (option != (const char *) NULL)
4168 units=(ResolutionType) ParseMagickOption(MagickResolutionOptions,
4169 MagickFalse,option);
4171 units = image_info->units;
4172 if (units != UndefinedResolution)
4174 if (image->units != units)
4175 switch (image->units)
4177 case PixelsPerInchResolution:
4179 if (units == PixelsPerCentimeterResolution)
4181 image->x_resolution/=2.54;
4182 image->y_resolution/=2.54;
4186 case PixelsPerCentimeterResolution:
4188 if (units == PixelsPerInchResolution)
4190 image->x_resolution=(double) ((size_t) (100.0*2.54*
4191 image->x_resolution+0.5))/100.0;
4192 image->y_resolution=(double) ((size_t) (100.0*2.54*
4193 image->y_resolution+0.5))/100.0;
4202 option=GetImageOption(image_info,"white-point");
4203 if (option != (const char *) NULL)
4205 flags=ParseGeometry(option,&geometry_info);
4206 image->chromaticity.white_point.x=geometry_info.rho;
4207 image->chromaticity.white_point.y=geometry_info.sigma;
4208 if ((flags & SigmaValue) == 0)
4209 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4211 ResetImageOptionIterator(image_info);
4212 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4214 value=GetImageOption(image_info,option);
4215 if (value != (const char *) NULL)
4217 (void) FormatMagickString(property,MaxTextExtent,"%s",option);
4218 (void) SetImageArtifact(image,property,value);
4220 option=GetNextImageOption(image_info);