2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII M M AAA GGGG EEEEE %
8 % I M M M AAAAA G GG EEE %
10 % IIIII M M A A GGGG EEEEE %
13 % MagickCore Image Methods %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/segment.h"
87 #include "MagickCore/semaphore.h"
88 #include "MagickCore/signature-private.h"
89 #include "MagickCore/statistic.h"
90 #include "MagickCore/string_.h"
91 #include "MagickCore/string-private.h"
92 #include "MagickCore/thread-private.h"
93 #include "MagickCore/threshold.h"
94 #include "MagickCore/timer.h"
95 #include "MagickCore/utility.h"
96 #include "MagickCore/utility-private.h"
97 #include "MagickCore/version.h"
98 #include "MagickCore/xwindow-private.h"
101 Constant declaration.
104 BackgroundColor[] = "#ffffff", /* white */
105 BorderColor[] = "#dfdfdf", /* gray */
106 DefaultTileFrame[] = "15x15+3+3",
107 DefaultTileGeometry[] = "120x120+4+3>",
108 DefaultTileLabel[] = "%f\n%G\n%b",
109 ForegroundColor[] = "#000", /* black */
110 LoadImageTag[] = "Load/Image",
111 LoadImagesTag[] = "Load/Images",
112 MatteColor[] = "#bdbdbd", /* gray */
113 PSDensityGeometry[] = "72.0x72.0",
114 PSPageGeometry[] = "612x792",
115 SaveImageTag[] = "Save/Image",
116 SaveImagesTag[] = "Save/Images",
117 TransparentColor[] = "#00000000"; /* transparent black */
120 DefaultResolution = 72.0;
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 % A c q u i r e I m a g e %
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % AcquireImage() returns a pointer to an image structure initialized to
136 % The format of the AcquireImage method is:
138 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
140 % A description of each parameter follows:
142 % o image_info: Many of the image default values are set from this
143 % structure. For example, filename, compression, depth, background color,
146 % o exception: return any errors or warnings in this structure.
149 MagickExport Image *AcquireImage(const ImageInfo *image_info,
150 ExceptionInfo *exception)
162 Allocate image structure.
164 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
165 image=(Image *) AcquireMagickMemory(sizeof(*image));
166 if (image == (Image *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 (void) ResetMagickMemory(image,0,sizeof(*image));
170 Initialize Image structure.
172 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
173 image->storage_class=DirectClass;
174 image->depth=MAGICKCORE_QUANTUM_DEPTH;
175 image->colorspace=RGBColorspace;
176 image->interlace=NoInterlace;
177 image->ticks_per_second=UndefinedTicksPerSecond;
178 image->compose=OverCompositeOp;
180 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
181 &image->background_color,exception);
182 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
184 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
186 (void) QueryColorCompliance(TransparentColor,AllCompliance,
187 &image->transparent_color,exception);
188 image->resolution.x=DefaultResolution;
189 image->resolution.y=DefaultResolution;
190 image->units=PixelsPerInchResolution;
191 GetTimerInfo(&image->timer);
192 image->cache=AcquirePixelCache(0);
193 image->channel_mask=DefaultChannels;
194 image->channel_map=AcquirePixelChannelMap();
195 image->blob=CloneBlobInfo((BlobInfo *) NULL);
196 image->debug=IsEventLogging();
197 image->reference_count=1;
198 image->semaphore=AllocateSemaphoreInfo();
199 image->signature=MagickSignature;
200 if (image_info == (ImageInfo *) NULL)
205 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
207 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
208 (void) CopyMagickString(image->magick_filename,image_info->filename,
210 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
211 if (image_info->size != (char *) NULL)
213 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
214 image->columns=image->extract_info.width;
215 image->rows=image->extract_info.height;
216 image->offset=image->extract_info.x;
217 image->extract_info.x=0;
218 image->extract_info.y=0;
220 if (image_info->extract != (char *) NULL)
225 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
226 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
228 image->extract_info=geometry;
229 Swap(image->columns,image->extract_info.width);
230 Swap(image->rows,image->extract_info.height);
233 image->compression=image_info->compression;
234 image->quality=image_info->quality;
235 image->endian=image_info->endian;
236 image->interlace=image_info->interlace;
237 image->units=image_info->units;
238 if (image_info->density != (char *) NULL)
243 flags=ParseGeometry(image_info->density,&geometry_info);
244 image->resolution.x=geometry_info.rho;
245 image->resolution.y=geometry_info.sigma;
246 if ((flags & SigmaValue) == 0)
247 image->resolution.y=image->resolution.x;
249 if (image_info->page != (char *) NULL)
254 image->page=image->extract_info;
255 geometry=GetPageGeometry(image_info->page);
256 (void) ParseAbsoluteGeometry(geometry,&image->page);
257 geometry=DestroyString(geometry);
259 if (image_info->depth != 0)
260 image->depth=image_info->depth;
261 image->dither=image_info->dither;
262 image->background_color=image_info->background_color;
263 image->border_color=image_info->border_color;
264 image->matte_color=image_info->matte_color;
265 image->transparent_color=image_info->transparent_color;
266 image->ping=image_info->ping;
267 image->progress_monitor=image_info->progress_monitor;
268 image->client_data=image_info->client_data;
269 if (image_info->cache != (void *) NULL)
270 ClonePixelCacheMethods(image->cache,image_info->cache);
271 (void) SyncImageSettings(image_info,image,exception);
272 option=GetImageOption(image_info,"delay");
273 if (option != (const char *) NULL)
278 flags=ParseGeometry(option,&geometry_info);
279 if ((flags & GreaterValue) != 0)
281 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
282 image->delay=(size_t) floor(geometry_info.rho+0.5);
285 if ((flags & LessValue) != 0)
287 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
288 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
291 image->delay=(size_t) floor(geometry_info.rho+0.5);
292 if ((flags & SigmaValue) != 0)
293 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
295 option=GetImageOption(image_info,"dispose");
296 if (option != (const char *) NULL)
297 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 % A c q u i r e I m a g e I n f o %
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 % AcquireImageInfo() allocates the ImageInfo structure.
315 % The format of the AcquireImageInfo method is:
317 % ImageInfo *AcquireImageInfo(void)
320 MagickExport ImageInfo *AcquireImageInfo(void)
325 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
326 if (image_info == (ImageInfo *) NULL)
327 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
328 GetImageInfo(image_info);
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % A c q u i r e N e x t I m a g e %
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 % AcquireNextImage() initializes the next image in a sequence to
344 % default values. The next member of image points to the newly allocated
345 % image. If there is a memory shortage, next is assigned NULL.
347 % The format of the AcquireNextImage method is:
349 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
350 % ExceptionInfo *exception)
352 % A description of each parameter follows:
354 % o image_info: Many of the image default values are set from this
355 % structure. For example, filename, compression, depth, background color,
358 % o image: the image.
360 % o exception: return any errors or warnings in this structure.
363 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
364 ExceptionInfo *exception)
367 Allocate image structure.
369 assert(image != (Image *) NULL);
370 assert(image->signature == MagickSignature);
371 if (image->debug != MagickFalse)
372 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
373 image->next=AcquireImage(image_info,exception);
374 if (GetNextImageInList(image) == (Image *) NULL)
376 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
378 if (image_info != (ImageInfo *) NULL)
379 (void) CopyMagickString(GetNextImageInList(image)->filename,
380 image_info->filename,MaxTextExtent);
381 DestroyBlob(GetNextImageInList(image));
382 image->next->blob=ReferenceBlob(image->blob);
383 image->next->endian=image->endian;
384 image->next->scene=image->scene+1;
385 image->next->previous=image;
389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393 % A p p e n d I m a g e s %
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 % AppendImages() takes all images from the current image pointer to the end
400 % of the image list and appends them to each other top-to-bottom if the
401 % stack parameter is true, otherwise left-to-right.
403 % The current gravity setting now effects how the image is justified in the
406 % The format of the AppendImages method is:
408 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
409 % ExceptionInfo *exception)
411 % A description of each parameter follows:
413 % o images: the image sequence.
415 % o stack: A value other than 0 stacks the images top-to-bottom.
417 % o exception: return any errors or warnings in this structure.
420 MagickExport Image *AppendImages(const Image *images,
421 const MagickBooleanType stack,ExceptionInfo *exception)
423 #define AppendImageTag "Append/Image"
460 Compute maximum area of appended area.
462 assert(images != (Image *) NULL);
463 assert(images->signature == MagickSignature);
464 if (images->debug != MagickFalse)
465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
466 assert(exception != (ExceptionInfo *) NULL);
467 assert(exception->signature == MagickSignature);
471 width=image->columns;
473 next=GetNextImageInList(image);
474 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
476 if (next->matte != MagickFalse)
479 if (stack != MagickFalse)
481 if (next->columns > width)
486 width+=next->columns;
487 if (next->rows > height)
493 append_image=CloneImage(image,width,height,MagickTrue,exception);
494 if (append_image == (Image *) NULL)
495 return((Image *) NULL);
496 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
498 append_image=DestroyImage(append_image);
499 return((Image *) NULL);
501 append_image->matte=matte;
502 (void) SetImageBackgroundColor(append_image,exception);
506 append_view=AcquireCacheView(append_image);
507 for (n=0; n < (MagickOffsetType) number_images; n++)
509 SetGeometry(append_image,&geometry);
510 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
511 if (stack != MagickFalse)
512 x_offset-=geometry.x;
514 y_offset-=geometry.y;
515 image_view=AcquireCacheView(image);
516 #if defined(MAGICKCORE_OPENMP_SUPPORT)
517 #pragma omp parallel for schedule(static) shared(status)
519 for (y=0; y < (ssize_t) image->rows; y++)
524 register const Quantum
533 if (status == MagickFalse)
535 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
536 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
537 image->columns,1,exception);
538 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
543 for (x=0; x < (ssize_t) image->columns; x++)
548 if (GetPixelMask(image,p) != 0)
550 p+=GetPixelChannels(image);
551 q+=GetPixelChannels(append_image);
554 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
563 channel=GetPixelChannelMapChannel(image,i);
564 traits=GetPixelChannelMapTraits(image,channel);
565 append_traits=GetPixelChannelMapTraits(append_image,channel);
566 if ((traits == UndefinedPixelTrait) ||
567 (append_traits == UndefinedPixelTrait))
569 SetPixelChannel(append_image,channel,p[i],q);
571 p+=GetPixelChannels(image);
572 q+=GetPixelChannels(append_image);
574 sync=SyncCacheViewAuthenticPixels(append_view,exception);
575 if (sync == MagickFalse)
578 image_view=DestroyCacheView(image_view);
579 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
580 if (proceed == MagickFalse)
582 if (stack == MagickFalse)
584 x_offset+=(ssize_t) image->columns;
590 y_offset+=(ssize_t) image->rows;
592 image=GetNextImageInList(image);
594 append_view=DestroyCacheView(append_view);
595 if (status == MagickFalse)
596 append_image=DestroyImage(append_image);
597 return(append_image);
601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
605 % C a t c h I m a g e E x c e p t i o n %
609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
611 % CatchImageException() returns if no exceptions are found in the image
612 % sequence, otherwise it determines the most severe exception and reports
613 % it as a warning or error depending on the severity.
615 % The format of the CatchImageException method is:
617 % ExceptionType CatchImageException(Image *image)
619 % A description of each parameter follows:
621 % o image: An image sequence.
624 MagickExport ExceptionType CatchImageException(Image *image)
632 assert(image != (const Image *) NULL);
633 assert(image->signature == MagickSignature);
634 if (image->debug != MagickFalse)
635 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
636 exception=AcquireExceptionInfo();
637 CatchException(exception);
638 severity=exception->severity;
639 exception=DestroyExceptionInfo(exception);
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648 % C l i p I m a g e P a t h %
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % ClipImagePath() sets the image clip mask based any clipping path information
657 % The format of the ClipImagePath method is:
659 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
660 % const MagickBooleanType inside,ExceptionInfo *exception)
662 % A description of each parameter follows:
664 % o image: the image.
666 % o pathname: name of clipping path resource. If name is preceded by #, use
667 % clipping path numbered by name.
669 % o inside: if non-zero, later operations take effect inside clipping path.
670 % Otherwise later operations take effect outside clipping path.
672 % o exception: return any errors or warnings in this structure.
676 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
678 return(ClipImagePath(image,"#1",MagickTrue,exception));
681 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
682 const MagickBooleanType inside,ExceptionInfo *exception)
684 #define ClipImagePathTag "ClipPath/Image"
698 assert(image != (const Image *) NULL);
699 assert(image->signature == MagickSignature);
700 if (image->debug != MagickFalse)
701 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
702 assert(pathname != NULL);
703 property=AcquireString(pathname);
704 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
706 value=GetImageProperty(image,property,exception);
707 property=DestroyString(property);
708 if (value == (const char *) NULL)
710 ThrowFileException(exception,OptionError,"NoClipPathDefined",
714 image_info=AcquireImageInfo();
715 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
716 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
717 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
718 image_info=DestroyImageInfo(image_info);
719 if (clip_mask == (Image *) NULL)
721 if (clip_mask->storage_class == PseudoClass)
723 (void) SyncImage(clip_mask,exception);
724 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
727 if (inside == MagickFalse)
728 (void) NegateImage(clip_mask,MagickFalse,exception);
729 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
730 "8BIM:1999,2998:%s\nPS",pathname);
731 (void) SetImageMask(image,clip_mask,exception);
732 clip_mask=DestroyImage(clip_mask);
737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
741 % C l o n e I m a g e %
745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747 % CloneImage() copies an image and returns the copy as a new image object.
749 % If the specified columns and rows is 0, an exact copy of the image is
750 % returned, otherwise the pixel data is undefined and must be initialized
751 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
752 % failure, a NULL image is returned and exception describes the reason for the
755 % The format of the CloneImage method is:
757 % Image *CloneImage(const Image *image,const size_t columns,
758 % const size_t rows,const MagickBooleanType orphan,
759 % ExceptionInfo *exception)
761 % A description of each parameter follows:
763 % o image: the image.
765 % o columns: the number of columns in the cloned image.
767 % o rows: the number of rows in the cloned image.
769 % o detach: With a value other than 0, the cloned image is detached from
770 % its parent I/O stream.
772 % o exception: return any errors or warnings in this structure.
775 MagickExport Image *CloneImage(const Image *image,const size_t columns,
776 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
790 assert(image != (const Image *) NULL);
791 assert(image->signature == MagickSignature);
792 if (image->debug != MagickFalse)
793 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
794 assert(exception != (ExceptionInfo *) NULL);
795 assert(exception->signature == MagickSignature);
796 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
797 if (clone_image == (Image *) NULL)
798 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
799 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
800 clone_image->signature=MagickSignature;
801 clone_image->storage_class=image->storage_class;
802 clone_image->number_channels=image->number_channels;
803 clone_image->number_meta_channels=image->number_meta_channels;
804 clone_image->metacontent_extent=image->metacontent_extent;
805 clone_image->colorspace=image->colorspace;
806 clone_image->mask=image->mask;
807 clone_image->matte=image->matte;
808 clone_image->columns=image->columns;
809 clone_image->rows=image->rows;
810 clone_image->dither=image->dither;
811 if (image->colormap != (PixelInfo *) NULL)
814 Allocate and copy the image colormap.
816 clone_image->colors=image->colors;
817 length=(size_t) image->colors;
818 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
819 sizeof(*clone_image->colormap));
820 if (clone_image->colormap == (PixelInfo *) NULL)
821 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
822 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
823 sizeof(*clone_image->colormap));
825 (void) CloneImageProfiles(clone_image,image);
826 (void) CloneImageProperties(clone_image,image);
827 (void) CloneImageArtifacts(clone_image,image);
828 GetTimerInfo(&clone_image->timer);
829 if (image->ascii85 != (void *) NULL)
830 Ascii85Initialize(clone_image);
831 clone_image->magick_columns=image->magick_columns;
832 clone_image->magick_rows=image->magick_rows;
833 clone_image->type=image->type;
834 clone_image->channel_mask=image->channel_mask;
835 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
836 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
838 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
839 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
840 clone_image->progress_monitor=image->progress_monitor;
841 clone_image->client_data=image->client_data;
842 clone_image->reference_count=1;
843 clone_image->next=image->next;
844 clone_image->previous=image->previous;
845 clone_image->list=NewImageList();
846 if (detach == MagickFalse)
847 clone_image->blob=ReferenceBlob(image->blob);
850 clone_image->next=NewImageList();
851 clone_image->previous=NewImageList();
852 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
854 clone_image->ping=image->ping;
855 clone_image->debug=IsEventLogging();
856 clone_image->semaphore=AllocateSemaphoreInfo();
857 if ((columns == 0) && (rows == 0))
859 if (image->montage != (char *) NULL)
860 (void) CloneString(&clone_image->montage,image->montage);
861 if (image->directory != (char *) NULL)
862 (void) CloneString(&clone_image->directory,image->directory);
863 clone_image->cache=ReferencePixelCache(image->cache);
866 scale=(MagickRealType) columns/(MagickRealType) image->columns;
867 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
868 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
869 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
870 scale=(MagickRealType) rows/(MagickRealType) image->rows;
871 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
872 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
873 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
874 clone_image->columns=columns;
875 clone_image->rows=rows;
876 clone_image->cache=ClonePixelCache(image->cache);
881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885 % C l o n e I m a g e I n f o %
889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891 % CloneImageInfo() makes a copy of the given image info structure. If
892 % NULL is specified, a new image info structure is created initialized to
895 % The format of the CloneImageInfo method is:
897 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
899 % A description of each parameter follows:
901 % o image_info: the image info.
904 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
909 clone_info=AcquireImageInfo();
910 if (image_info == (ImageInfo *) NULL)
912 clone_info->compression=image_info->compression;
913 clone_info->temporary=image_info->temporary;
914 clone_info->adjoin=image_info->adjoin;
915 clone_info->antialias=image_info->antialias;
916 clone_info->scene=image_info->scene;
917 clone_info->number_scenes=image_info->number_scenes;
918 clone_info->depth=image_info->depth;
919 (void) CloneString(&clone_info->size,image_info->size);
920 (void) CloneString(&clone_info->extract,image_info->extract);
921 (void) CloneString(&clone_info->scenes,image_info->scenes);
922 (void) CloneString(&clone_info->page,image_info->page);
923 clone_info->interlace=image_info->interlace;
924 clone_info->endian=image_info->endian;
925 clone_info->units=image_info->units;
926 clone_info->quality=image_info->quality;
927 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
928 (void) CloneString(&clone_info->server_name,image_info->server_name);
929 (void) CloneString(&clone_info->font,image_info->font);
930 (void) CloneString(&clone_info->texture,image_info->texture);
931 (void) CloneString(&clone_info->density,image_info->density);
932 clone_info->pointsize=image_info->pointsize;
933 clone_info->fuzz=image_info->fuzz;
934 clone_info->background_color=image_info->background_color;
935 clone_info->border_color=image_info->border_color;
936 clone_info->matte_color=image_info->matte_color;
937 clone_info->transparent_color=image_info->transparent_color;
938 clone_info->dither=image_info->dither;
939 clone_info->monochrome=image_info->monochrome;
940 clone_info->colorspace=image_info->colorspace;
941 clone_info->type=image_info->type;
942 clone_info->orientation=image_info->orientation;
943 clone_info->preview_type=image_info->preview_type;
944 clone_info->group=image_info->group;
945 clone_info->ping=image_info->ping;
946 clone_info->verbose=image_info->verbose;
947 (void) CloneString(&clone_info->view,image_info->view);
948 clone_info->progress_monitor=image_info->progress_monitor;
949 clone_info->client_data=image_info->client_data;
950 clone_info->cache=image_info->cache;
951 if (image_info->cache != (void *) NULL)
952 clone_info->cache=ReferencePixelCache(image_info->cache);
953 if (image_info->profile != (void *) NULL)
954 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
955 image_info->profile);
956 SetImageInfoFile(clone_info,image_info->file);
957 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
958 clone_info->stream=image_info->stream;
959 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
960 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
961 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
962 (void) CopyMagickString(clone_info->filename,image_info->filename,
964 clone_info->channel=image_info->channel;
965 (void) CloneImageOptions(clone_info,image_info);
966 clone_info->debug=IsEventLogging();
967 clone_info->signature=image_info->signature;
972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976 % C o m b i n e I m a g e s %
980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
982 % CombineImages() combines one or more images into a single image. The
983 % grayscale value of the pixels of each image in the sequence is assigned in
984 % order to the specified channels of the combined image. The typical
985 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
987 % The format of the CombineImages method is:
989 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
991 % A description of each parameter follows:
993 % o image: the image.
995 % o exception: return any errors or warnings in this structure.
999 static inline size_t MagickMin(const size_t x,const size_t y)
1006 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1008 #define CombineImageTag "Combine/Image"
1026 Ensure the image are the same size.
1028 assert(image != (const Image *) NULL);
1029 assert(image->signature == MagickSignature);
1030 if (image->debug != MagickFalse)
1031 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1032 assert(exception != (ExceptionInfo *) NULL);
1033 assert(exception->signature == MagickSignature);
1034 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1035 if (combine_image == (Image *) NULL)
1036 return((Image *) NULL);
1037 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1039 combine_image=DestroyImage(combine_image);
1040 return((Image *) NULL);
1042 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1043 combine_image->matte=MagickTrue;
1049 combine_view=AcquireCacheView(combine_image);
1050 for (y=0; y < (ssize_t) combine_image->rows; y++)
1061 register const Quantum
1070 if (status == MagickFalse)
1072 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1074 if (pixels == (Quantum *) NULL)
1080 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1092 if (next == (Image *) NULL)
1094 channel=GetPixelChannelMapChannel(image,i);
1095 traits=GetPixelChannelMapTraits(image,channel);
1096 combine_traits=GetPixelChannelMapTraits(combine_image,channel);
1097 if ((traits == UndefinedPixelTrait) ||
1098 (combine_traits == UndefinedPixelTrait))
1100 image_view=AcquireCacheView(next);
1101 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1102 if (p == (const Quantum *) NULL)
1105 for (x=0; x < (ssize_t) combine_image->columns; x++)
1107 if (x < (ssize_t) image->columns)
1109 q[i]=GetPixelGray(image,p);
1110 p+=GetPixelChannels(image);
1112 q+=GetPixelChannels(combine_image);
1114 image_view=DestroyCacheView(image_view);
1115 next=GetNextImageInList(next);
1116 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1118 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1123 proceed=SetImageProgress(image,CombineImageTag,progress++,
1124 combine_image->rows);
1125 if (proceed == MagickFalse)
1130 combine_view=DestroyCacheView(combine_view);
1131 if (status == MagickFalse)
1132 combine_image=DestroyImage(combine_image);
1133 return(combine_image);
1137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1141 % D e s t r o y I m a g e %
1145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147 % DestroyImage() dereferences an image, deallocating memory associated with
1148 % the image if the reference count becomes zero.
1150 % The format of the DestroyImage method is:
1152 % Image *DestroyImage(Image *image)
1154 % A description of each parameter follows:
1156 % o image: the image.
1159 MagickExport Image *DestroyImage(Image *image)
1167 assert(image != (Image *) NULL);
1168 assert(image->signature == MagickSignature);
1169 if (image->debug != MagickFalse)
1170 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1171 destroy=MagickFalse;
1172 LockSemaphoreInfo(image->semaphore);
1173 image->reference_count--;
1174 if (image->reference_count == 0)
1176 UnlockSemaphoreInfo(image->semaphore);
1177 if (destroy == MagickFalse)
1178 return((Image *) NULL);
1182 DestroyImagePixels(image);
1183 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1184 if (image->montage != (char *) NULL)
1185 image->montage=DestroyString(image->montage);
1186 if (image->directory != (char *) NULL)
1187 image->directory=DestroyString(image->directory);
1188 if (image->colormap != (PixelInfo *) NULL)
1189 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1190 if (image->geometry != (char *) NULL)
1191 image->geometry=DestroyString(image->geometry);
1192 DestroyImageProfiles(image);
1193 DestroyImageProperties(image);
1194 DestroyImageArtifacts(image);
1195 if (image->ascii85 != (Ascii85Info*) NULL)
1196 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1198 if (image->semaphore != (SemaphoreInfo *) NULL)
1199 DestroySemaphoreInfo(&image->semaphore);
1200 image->signature=(~MagickSignature);
1201 image=(Image *) RelinquishMagickMemory(image);
1206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1210 % D e s t r o y I m a g e I n f o %
1214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1216 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1219 % The format of the DestroyImageInfo method is:
1221 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1223 % A description of each parameter follows:
1225 % o image_info: the image info.
1228 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1230 assert(image_info != (ImageInfo *) NULL);
1231 assert(image_info->signature == MagickSignature);
1232 if (image_info->debug != MagickFalse)
1233 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1234 image_info->filename);
1235 if (image_info->size != (char *) NULL)
1236 image_info->size=DestroyString(image_info->size);
1237 if (image_info->extract != (char *) NULL)
1238 image_info->extract=DestroyString(image_info->extract);
1239 if (image_info->scenes != (char *) NULL)
1240 image_info->scenes=DestroyString(image_info->scenes);
1241 if (image_info->page != (char *) NULL)
1242 image_info->page=DestroyString(image_info->page);
1243 if (image_info->sampling_factor != (char *) NULL)
1244 image_info->sampling_factor=DestroyString(
1245 image_info->sampling_factor);
1246 if (image_info->server_name != (char *) NULL)
1247 image_info->server_name=DestroyString(
1248 image_info->server_name);
1249 if (image_info->font != (char *) NULL)
1250 image_info->font=DestroyString(image_info->font);
1251 if (image_info->texture != (char *) NULL)
1252 image_info->texture=DestroyString(image_info->texture);
1253 if (image_info->density != (char *) NULL)
1254 image_info->density=DestroyString(image_info->density);
1255 if (image_info->view != (char *) NULL)
1256 image_info->view=DestroyString(image_info->view);
1257 if (image_info->cache != (void *) NULL)
1258 image_info->cache=DestroyPixelCache(image_info->cache);
1259 if (image_info->profile != (StringInfo *) NULL)
1260 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1261 image_info->profile);
1262 DestroyImageOptions(image_info);
1263 image_info->signature=(~MagickSignature);
1264 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1273 + D i s a s s o c i a t e I m a g e S t r e a m %
1277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 % DisassociateImageStream() disassociates the image stream.
1281 % The format of the DisassociateImageStream method is:
1283 % MagickBooleanType DisassociateImageStream(const Image *image)
1285 % A description of each parameter follows:
1287 % o image: the image.
1290 MagickExport void DisassociateImageStream(Image *image)
1292 assert(image != (const Image *) NULL);
1293 assert(image->signature == MagickSignature);
1294 if (image->debug != MagickFalse)
1295 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1296 (void) DetachBlob(image->blob);
1300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1304 % G e t I m a g e A l p h a C h a n n e l %
1308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1310 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1311 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1314 % The format of the GetImageAlphaChannel method is:
1316 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1318 % A description of each parameter follows:
1320 % o image: the image.
1323 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1325 assert(image != (const Image *) NULL);
1326 if (image->debug != MagickFalse)
1327 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1328 assert(image->signature == MagickSignature);
1329 return(image->matte);
1333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337 % G e t I m a g e I n f o %
1341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1343 % GetImageInfo() initializes image_info to default values.
1345 % The format of the GetImageInfo method is:
1347 % void GetImageInfo(ImageInfo *image_info)
1349 % A description of each parameter follows:
1351 % o image_info: the image info.
1354 MagickExport void GetImageInfo(ImageInfo *image_info)
1363 File and image dimension members.
1365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1366 assert(image_info != (ImageInfo *) NULL);
1367 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1368 image_info->adjoin=MagickTrue;
1369 image_info->interlace=NoInterlace;
1370 image_info->channel=DefaultChannels;
1371 image_info->quality=UndefinedCompressionQuality;
1372 image_info->antialias=MagickTrue;
1373 image_info->dither=MagickTrue;
1374 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1375 if (synchronize != (const char *) NULL)
1376 image_info->synchronize=IsMagickTrue(synchronize);
1377 exception=AcquireExceptionInfo();
1378 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1379 &image_info->background_color,exception);
1380 (void) QueryColorCompliance(BorderColor,AllCompliance,
1381 &image_info->border_color,exception);
1382 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1384 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1385 &image_info->transparent_color,exception);
1386 exception=DestroyExceptionInfo(exception);
1387 image_info->debug=IsEventLogging();
1388 image_info->signature=MagickSignature;
1392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1396 % G e t I m a g e I n f o F i l e %
1400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1402 % GetImageInfoFile() returns the image info file member.
1404 % The format of the GetImageInfoFile method is:
1406 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1408 % A description of each parameter follows:
1410 % o image_info: the image info.
1413 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1415 return(image_info->file);
1419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1423 % G e t I m a g e M a s k %
1427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1429 % GetImageMask() returns the mask associated with the image.
1431 % The format of the GetImageMask method is:
1433 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1435 % A description of each parameter follows:
1437 % o image: the image.
1440 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1458 assert(image != (Image *) NULL);
1459 if (image->debug != MagickFalse)
1460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1461 assert(image->signature == MagickSignature);
1462 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1463 if (mask_image == (Image *) NULL)
1464 return((Image *) NULL);
1466 mask_image->colorspace=GRAYColorspace;
1467 mask_image->mask=MagickFalse;
1468 image_view=AcquireCacheView(image);
1469 mask_view=AcquireCacheView(mask_image);
1470 for (y=0; y < (ssize_t) image->rows; y++)
1472 register const Quantum
1481 if (status == MagickFalse)
1483 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1484 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1486 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1491 for (x=0; x < (ssize_t) image->columns; x++)
1493 SetPixelGray(mask_image,GetPixelMask(image,p),q);
1494 p+=GetPixelChannels(image);
1495 q+=GetPixelChannels(mask_image);
1497 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1500 mask_view=DestroyCacheView(mask_view);
1501 image_view=DestroyCacheView(image_view);
1506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1510 + G e t I m a g e R e f e r e n c e C o u n t %
1514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1516 % GetImageReferenceCount() returns the image reference count.
1518 % The format of the GetReferenceCount method is:
1520 % ssize_t GetImageReferenceCount(Image *image)
1522 % A description of each parameter follows:
1524 % o image: the image.
1527 MagickExport ssize_t GetImageReferenceCount(Image *image)
1532 assert(image != (Image *) NULL);
1533 assert(image->signature == MagickSignature);
1534 if (image->debug != MagickFalse)
1535 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1536 LockSemaphoreInfo(image->semaphore);
1537 reference_count=image->reference_count;
1538 UnlockSemaphoreInfo(image->semaphore);
1539 return(reference_count);
1543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1547 % 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 %
1551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1553 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1554 % image. A virtual pixel is any pixel access that is outside the boundaries
1555 % of the image cache.
1557 % The format of the GetImageVirtualPixelMethod() method is:
1559 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1561 % A description of each parameter follows:
1563 % o image: the image.
1566 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1568 assert(image != (Image *) NULL);
1569 assert(image->signature == MagickSignature);
1570 if (image->debug != MagickFalse)
1571 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1572 return(GetPixelCacheVirtualMethod(image));
1576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1580 % I n t e r p r e t I m a g e F i l e n a m e %
1584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 % InterpretImageFilename() interprets embedded characters in an image filename.
1587 % The filename length is returned.
1589 % The format of the InterpretImageFilename method is:
1591 % size_t InterpretImageFilename(const ImageInfo *image_info,
1592 % Image *image,const char *format,int value,char *filename,
1593 % ExceptionInfo *exception)
1595 % A description of each parameter follows.
1597 % o image_info: the image info..
1599 % o image: the image.
1601 % o format: A filename describing the format to use to write the numeric
1602 % argument. Only the first numeric format identifier is replaced.
1604 % o value: Numeric value to substitute into format filename.
1606 % o filename: return the formatted filename in this character buffer.
1608 % o exception: return any errors or warnings in this structure.
1611 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1612 Image *image,const char *format,int value,char *filename,
1613 ExceptionInfo *exception)
1630 canonical=MagickFalse;
1632 (void) CopyMagickString(filename,format,MaxTextExtent);
1633 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1646 value=(ssize_t) strtol(q,&q,10);
1658 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1659 (p-format)),p,value);
1661 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1662 canonical=MagickTrue;
1671 pattern[MaxTextExtent];
1688 if (strchr(p,']') == (char *) NULL)
1692 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1703 if (LocaleNCompare(pattern,"filename:",9) != 0)
1705 value=(const char *) NULL;
1706 if ((image_info != (const ImageInfo *) NULL) &&
1707 (image != (const Image *) NULL))
1708 value=GetMagickProperty(image_info,image,pattern,exception);
1710 if (image != (Image *) NULL)
1711 value=GetImageProperty(image,pattern,exception);
1713 if (image_info != (ImageInfo *) NULL)
1714 value=GetImageOption(image_info,pattern);
1715 if (value == (const char *) NULL)
1720 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1721 (MaxTextExtent-(p-format-length)));
1722 length+=strlen(pattern)-1;
1724 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1725 canonical=MagickTrue;
1735 for (q=filename; *q != '\0'; q++)
1736 if ((*q == '%') && (*(q+1) == '%'))
1738 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1739 canonical=MagickTrue;
1741 if (canonical == MagickFalse)
1742 (void) CopyMagickString(filename,format,MaxTextExtent);
1743 return(strlen(filename));
1747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1751 % I s H i g h D y n a m i c R a n g e I m a g e %
1755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1757 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1758 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1761 % The format of the IsHighDynamicRangeImage method is:
1763 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1764 % ExceptionInfo *exception)
1766 % A description of each parameter follows:
1768 % o image: the image.
1770 % o exception: return any errors or warnings in this structure.
1773 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1774 ExceptionInfo *exception)
1776 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1779 return(MagickFalse);
1790 assert(image != (Image *) NULL);
1791 assert(image->signature == MagickSignature);
1792 if (image->debug != MagickFalse)
1793 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1795 image_view=AcquireCacheView(image);
1796 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1797 #pragma omp parallel for schedule(static,4) shared(status)
1799 for (y=0; y < (ssize_t) image->rows; y++)
1804 register const Quantum
1810 if (status == MagickFalse)
1812 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1813 if (p == (const Quantum *) NULL)
1818 for (x=0; x < (ssize_t) image->columns; x++)
1826 if (GetPixelMask(image,p) != 0)
1828 p+=GetPixelChannels(image);
1831 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1836 traits=GetPixelChannelMapTraits(image,i);
1837 if (traits == UndefinedPixelTrait)
1839 pixel=(MagickRealType) p[i];
1840 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1841 (pixel != (QuantumAny) pixel))
1844 p+=GetPixelChannels(image);
1845 if (i < (ssize_t) GetPixelChannels(image))
1848 if (x < (ssize_t) image->columns)
1851 image_view=DestroyCacheView(image_view);
1852 return(status != MagickFalse ? MagickFalse : MagickTrue);
1857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1861 % I s I m a g e O b j e c t %
1865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1867 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1868 % set of image objects.
1870 % The format of the IsImageObject method is:
1872 % MagickBooleanType IsImageObject(const Image *image)
1874 % A description of each parameter follows:
1876 % o image: the image.
1879 MagickExport MagickBooleanType IsImageObject(const Image *image)
1881 register const Image
1884 assert(image != (Image *) NULL);
1885 if (image->debug != MagickFalse)
1886 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1887 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1888 if (p->signature != MagickSignature)
1889 return(MagickFalse);
1894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1898 % I s T a i n t I m a g e %
1902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1904 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1905 % since it was first constituted.
1907 % The format of the IsTaintImage method is:
1909 % MagickBooleanType IsTaintImage(const Image *image)
1911 % A description of each parameter follows:
1913 % o image: the image.
1916 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1919 magick[MaxTextExtent],
1920 filename[MaxTextExtent];
1922 register const Image
1925 assert(image != (Image *) NULL);
1926 if (image->debug != MagickFalse)
1927 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1928 assert(image->signature == MagickSignature);
1929 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1930 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1931 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1933 if (p->taint != MagickFalse)
1935 if (LocaleCompare(p->magick,magick) != 0)
1937 if (LocaleCompare(p->filename,filename) != 0)
1940 return(MagickFalse);
1944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1948 % M o d i f y I m a g e %
1952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1954 % ModifyImage() ensures that there is only a single reference to the image
1955 % to be modified, updating the provided image pointer to point to a clone of
1956 % the original image if necessary.
1958 % The format of the ModifyImage method is:
1960 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1962 % A description of each parameter follows:
1964 % o image: the image.
1966 % o exception: return any errors or warnings in this structure.
1969 MagickExport MagickBooleanType ModifyImage(Image **image,
1970 ExceptionInfo *exception)
1975 assert(image != (Image **) NULL);
1976 assert(*image != (Image *) NULL);
1977 assert((*image)->signature == MagickSignature);
1978 if ((*image)->debug != MagickFalse)
1979 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1980 if (GetImageReferenceCount(*image) <= 1)
1982 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1983 LockSemaphoreInfo((*image)->semaphore);
1984 (*image)->reference_count--;
1985 UnlockSemaphoreInfo((*image)->semaphore);
1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1995 % N e w M a g i c k I m a g e %
1999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2001 % NewMagickImage() creates a blank image canvas of the specified size and
2004 % The format of the NewMagickImage method is:
2006 % Image *NewMagickImage(const ImageInfo *image_info,
2007 % const size_t width,const size_t height,const PixelInfo *background,
2008 % ExceptionInfo *exception)
2010 % A description of each parameter follows:
2012 % o image: the image.
2014 % o width: the image width.
2016 % o height: the image height.
2018 % o background: the image color.
2020 % o exception: return any errors or warnings in this structure.
2023 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2024 const size_t width,const size_t height,const PixelInfo *background,
2025 ExceptionInfo *exception)
2039 assert(image_info != (const ImageInfo *) NULL);
2040 if (image_info->debug != MagickFalse)
2041 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2042 assert(image_info->signature == MagickSignature);
2043 assert(background != (const PixelInfo *) NULL);
2044 image=AcquireImage(image_info,exception);
2045 image->columns=width;
2047 image->colorspace=background->colorspace;
2048 image->matte=background->matte;
2049 image->fuzz=background->fuzz;
2050 image->depth=background->depth;
2052 image_view=AcquireCacheView(image);
2053 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2054 #pragma omp parallel for schedule(static,4) shared(status)
2056 for (y=0; y < (ssize_t) image->rows; y++)
2064 if (status == MagickFalse)
2066 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2067 if (q == (Quantum *) NULL)
2072 for (x=0; x < (ssize_t) image->columns; x++)
2074 SetPixelInfoPixel(image,background,q);
2075 q+=GetPixelChannels(image);
2077 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2080 image_view=DestroyCacheView(image_view);
2081 if (status == MagickFalse)
2082 image=DestroyImage(image);
2087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2091 % R e f e r e n c e I m a g e %
2095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2097 % ReferenceImage() increments the reference count associated with an image
2098 % returning a pointer to the image.
2100 % The format of the ReferenceImage method is:
2102 % Image *ReferenceImage(Image *image)
2104 % A description of each parameter follows:
2106 % o image: the image.
2109 MagickExport Image *ReferenceImage(Image *image)
2111 assert(image != (Image *) NULL);
2112 if (image->debug != MagickFalse)
2113 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2114 assert(image->signature == MagickSignature);
2115 LockSemaphoreInfo(image->semaphore);
2116 image->reference_count++;
2117 UnlockSemaphoreInfo(image->semaphore);
2122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2126 % R e s e t I m a g e P a g e %
2130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2132 % ResetImagePage() resets the image page canvas and position.
2134 % The format of the ResetImagePage method is:
2136 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2138 % A description of each parameter follows:
2140 % o image: the image.
2142 % o page: the relative page specification.
2145 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2153 assert(image != (Image *) NULL);
2154 assert(image->signature == MagickSignature);
2155 if (image->debug != MagickFalse)
2156 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2157 flags=ParseAbsoluteGeometry(page,&geometry);
2158 if ((flags & WidthValue) != 0)
2160 if ((flags & HeightValue) == 0)
2161 geometry.height=geometry.width;
2162 image->page.width=geometry.width;
2163 image->page.height=geometry.height;
2165 if ((flags & AspectValue) != 0)
2167 if ((flags & XValue) != 0)
2168 image->page.x+=geometry.x;
2169 if ((flags & YValue) != 0)
2170 image->page.y+=geometry.y;
2174 if ((flags & XValue) != 0)
2176 image->page.x=geometry.x;
2177 if ((image->page.width == 0) && (geometry.x > 0))
2178 image->page.width=image->columns+geometry.x;
2180 if ((flags & YValue) != 0)
2182 image->page.y=geometry.y;
2183 if ((image->page.height == 0) && (geometry.y > 0))
2184 image->page.height=image->rows+geometry.y;
2191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2195 % S e p a r a t e I m a g e %
2199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2201 % SeparateImage() separates a channel from the image and returns it as a
2204 % The format of the SeparateImage method is:
2206 % Image *SeparateImage(const Image *image,const ChannelType channel,
2207 % ExceptionInfo *exception)
2209 % A description of each parameter follows:
2211 % o image: the image.
2213 % o channel: the image channel.
2215 % o exception: return any errors or warnings in this structure.
2218 MagickExport Image *SeparateImage(const Image *image,
2219 const ChannelType channel_type,ExceptionInfo *exception)
2221 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
2222 #define SeparateImageTag "Separate/Image"
2241 Initialize spread image attributes.
2243 assert(image != (Image *) NULL);
2244 assert(image->signature == MagickSignature);
2245 if (image->debug != MagickFalse)
2246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2247 assert(exception != (ExceptionInfo *) NULL);
2248 assert(exception->signature == MagickSignature);
2249 separate_image=CloneImage(image,image->columns,image->rows,MagickTrue,
2251 if (separate_image == (Image *) NULL)
2252 return((Image *) NULL);
2253 if (SetImageStorageClass(separate_image,DirectClass,exception) == MagickFalse)
2255 separate_image=DestroyImage(separate_image);
2256 return((Image *) NULL);
2258 separate_image->colorspace=GRAYColorspace;
2264 image_view=AcquireCacheView(image);
2265 separate_view=AcquireCacheView(separate_image);
2266 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2267 #pragma omp parallel for schedule(static) shared(progress,status)
2269 for (y=0; y < (ssize_t) image->rows; y++)
2271 register const Quantum
2280 if (status == MagickFalse)
2282 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2283 q=QueueCacheViewAuthenticPixels(separate_view,0,y,separate_image->columns,1,
2285 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2290 for (x=0; x < (ssize_t) image->columns; x++)
2295 if (GetPixelMask(image,p) != 0)
2297 p+=GetPixelChannels(image);
2298 q+=GetPixelChannels(separate_image);
2301 SetPixelChannel(separate_image,GrayPixelChannel,0,q);
2302 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2310 channel=GetPixelChannelMapChannel(image,i);
2311 traits=GetPixelChannelMapTraits(image,channel);
2312 if ((traits == UndefinedPixelTrait) ||
2313 (GetChannelBit(channel_type,channel) == 0))
2315 SetPixelChannel(separate_image,GrayPixelChannel,p[i],q);
2317 p+=GetPixelChannels(image);
2318 q+=GetPixelChannels(separate_image);
2320 if (SyncCacheViewAuthenticPixels(separate_view,exception) == MagickFalse)
2322 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2327 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2328 #pragma omp critical (MagickCore_SeparateImage)
2330 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2331 if (proceed == MagickFalse)
2335 separate_view=DestroyCacheView(separate_view);
2336 image_view=DestroyCacheView(image_view);
2337 return(separate_image);
2341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2345 % S e p a r a t e I m a g e s %
2349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2351 % SeparateImages() returns a separate grayscale image for each channel
2354 % The format of the SeparateImages method is:
2356 % MagickBooleanType SeparateImages(const Image *image,
2357 % ExceptionInfo *exception)
2359 % A description of each parameter follows:
2361 % o image: the image.
2363 % o exception: return any errors or warnings in this structure.
2366 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2375 assert(image != (Image *) NULL);
2376 assert(image->signature == MagickSignature);
2377 if (image->debug != MagickFalse)
2378 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2379 images=NewImageList();
2380 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2388 channel=GetPixelChannelMapChannel(image,i);
2389 traits=GetPixelChannelMapTraits(image,channel);
2390 if ((traits == UndefinedPixelTrait) ||
2391 ((traits & UpdatePixelTrait) == 0))
2393 separate_image=SeparateImage(image,(ChannelType) (1 << channel),exception);
2394 if (separate_image != (Image *) NULL)
2395 AppendImageToList(&images,separate_image);
2401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2405 % S e t I m a g e A l p h a C h a n n e l %
2409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2411 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2414 % The format of the SetImageAlphaChannel method is:
2416 % MagickBooleanType SetImageAlphaChannel(Image *image,
2417 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2419 % A description of each parameter follows:
2421 % o image: the image.
2423 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2424 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2425 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2426 % TransparentAlphaChannel.
2428 % o exception: return any errors or warnings in this structure.
2432 static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
2433 const MagickRealType alpha,const Quantum *q,const MagickRealType beta,
2445 Compose pixel p over pixel q with the given alpha.
2447 Sa=QuantumScale*alpha;
2448 Da=QuantumScale*beta,
2449 gamma=Sa*(-Da)+Sa+Da;
2450 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
2451 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2459 channel=GetPixelChannelMapChannel(image,i);
2460 traits=GetPixelChannelMapTraits(image,channel);
2461 if (traits == UndefinedPixelTrait)
2465 case RedPixelChannel:
2467 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2468 beta,(MagickRealType) p->red,alpha));
2471 case GreenPixelChannel:
2473 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2474 beta,(MagickRealType) p->green,alpha));
2477 case BluePixelChannel:
2479 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2480 beta,(MagickRealType) p->blue,alpha));
2483 case BlackPixelChannel:
2485 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2486 beta,(MagickRealType) p->black,alpha));
2489 case AlphaPixelChannel:
2491 composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
2500 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2501 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2506 assert(image != (Image *) NULL);
2507 if (image->debug != MagickFalse)
2508 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2509 assert(image->signature == MagickSignature);
2513 case ActivateAlphaChannel:
2515 image->matte=MagickTrue;
2518 case BackgroundAlphaChannel:
2527 Set transparent pixels to background color.
2529 if (image->matte == MagickFalse)
2531 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2533 image_view=AcquireCacheView(image);
2534 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2535 #pragma omp parallel for schedule(static,4) shared(status)
2537 for (y=0; y < (ssize_t) image->rows; y++)
2545 if (status == MagickFalse)
2547 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2549 if (q == (Quantum *) NULL)
2554 for (x=0; x < (ssize_t) image->columns; x++)
2556 if (GetPixelAlpha(image,q) == TransparentAlpha)
2557 SetPixelInfoPixel(image,&image->background_color,q);
2558 q+=GetPixelChannels(image);
2560 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2563 image_view=DestroyCacheView(image_view);
2566 case CopyAlphaChannel:
2567 case ShapeAlphaChannel:
2570 Copy pixel intensity to the alpha channel.
2572 status=CompositeImage(image,IntensityCompositeOp,image,0,0,exception);
2573 if (alpha_type == ShapeAlphaChannel)
2574 (void) LevelImageColors(image,&image->background_color,
2575 &image->background_color,MagickTrue,exception);
2578 case DeactivateAlphaChannel:
2580 image->matte=MagickFalse;
2583 case ExtractAlphaChannel:
2585 status=CompositeImage(image,AlphaCompositeOp,image,0,0,exception);
2586 image->matte=MagickFalse;
2589 case OpaqueAlphaChannel:
2591 status=SetImageAlpha(image,OpaqueAlpha,exception);
2594 case RemoveAlphaChannel:
2603 Flatten image pixels over the background pixels.
2605 if (image->matte == MagickFalse)
2607 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2609 image_view=AcquireCacheView(image);
2610 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2611 #pragma omp parallel for schedule(static,4) shared(status)
2613 for (y=0; y < (ssize_t) image->rows; y++)
2621 if (status == MagickFalse)
2623 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2625 if (q == (Quantum *) NULL)
2630 for (x=0; x < (ssize_t) image->columns; x++)
2632 FlattenPixelInfo(image,&image->background_color,
2633 image->background_color.alpha,q,(MagickRealType)
2634 GetPixelAlpha(image,q),q);
2635 q+=GetPixelChannels(image);
2637 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2640 image_view=DestroyCacheView(image_view);
2643 case SetAlphaChannel:
2645 if (image->matte == MagickFalse)
2646 status=SetImageAlpha(image,OpaqueAlpha,exception);
2649 case TransparentAlphaChannel:
2651 status=SetImageAlpha(image,TransparentAlpha,exception);
2654 case UndefinedAlphaChannel:
2657 if (status == MagickFalse)
2659 return(SyncImagePixelCache(image,exception));
2663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2667 % S e t I m a g e B a c k g r o u n d C o l o r %
2671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2673 % SetImageBackgroundColor() initializes the image pixels to the image
2674 % background color. The background color is defined by the background_color
2675 % member of the image structure.
2677 % The format of the SetImage method is:
2679 % MagickBooleanType SetImageBackgroundColor(Image *image,
2680 % ExceptionInfo *exception)
2682 % A description of each parameter follows:
2684 % o image: the image.
2686 % o exception: return any errors or warnings in this structure.
2689 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2690 ExceptionInfo *exception)
2701 assert(image != (Image *) NULL);
2702 if (image->debug != MagickFalse)
2703 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2704 assert(image->signature == MagickSignature);
2705 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2706 return(MagickFalse);
2707 if (image->background_color.matte != MagickFalse)
2708 image->matte=MagickTrue;
2710 Set image background color.
2713 image_view=AcquireCacheView(image);
2714 for (y=0; y < (ssize_t) image->rows; y++)
2722 if (status == MagickFalse)
2724 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2725 if (q == (Quantum *) NULL)
2730 for (x=0; x < (ssize_t) image->columns; x++)
2732 SetPixelInfoPixel(image,&image->background_color,q);
2733 q+=GetPixelChannels(image);
2735 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2738 image_view=DestroyCacheView(image_view);
2743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2747 % S e t I m a g e C o l o r %
2751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2753 % SetImageColor() set the entire image canvas to the specified color.
2755 % The format of the SetImageColor method is:
2757 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2758 % ExeptionInfo *exception)
2760 % A description of each parameter follows:
2762 % o image: the image.
2764 % o background: the image color.
2766 % o exception: return any errors or warnings in this structure.
2769 MagickExport MagickBooleanType SetImageColor(Image *image,
2770 const PixelInfo *color,ExceptionInfo *exception)
2781 assert(image != (Image *) NULL);
2782 if (image->debug != MagickFalse)
2783 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2784 assert(image->signature == MagickSignature);
2785 assert(color != (const PixelInfo *) NULL);
2786 image->colorspace=color->colorspace;
2787 image->matte=color->matte;
2788 image->fuzz=color->fuzz;
2789 image->depth=color->depth;
2791 image_view=AcquireCacheView(image);
2792 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2793 #pragma omp parallel for schedule(static,4) shared(status)
2795 for (y=0; y < (ssize_t) image->rows; y++)
2803 if (status == MagickFalse)
2805 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2806 if (q == (Quantum *) NULL)
2811 for (x=0; x < (ssize_t) image->columns; x++)
2813 SetPixelInfoPixel(image,color,q);
2814 q+=GetPixelChannels(image);
2816 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2819 image_view=DestroyCacheView(image_view);
2824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2828 % S e t I m a g e S t o r a g e C l a s s %
2832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2834 % SetImageStorageClass() sets the image class: DirectClass for true color
2835 % images or PseudoClass for colormapped images.
2837 % The format of the SetImageStorageClass method is:
2839 % MagickBooleanType SetImageStorageClass(Image *image,
2840 % const ClassType storage_class,ExceptionInfo *exception)
2842 % A description of each parameter follows:
2844 % o image: the image.
2846 % o storage_class: The image class.
2848 % o exception: return any errors or warnings in this structure.
2851 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2852 const ClassType storage_class,ExceptionInfo *exception)
2854 image->storage_class=storage_class;
2855 return(SyncImagePixelCache(image,exception));
2859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2863 % S e t I m a g e E x t e n t %
2867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2869 % SetImageExtent() sets the image size (i.e. columns & rows).
2871 % The format of the SetImageExtent method is:
2873 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2874 % const size_t rows,ExceptionInfo *exception)
2876 % A description of each parameter follows:
2878 % o image: the image.
2880 % o columns: The image width in pixels.
2882 % o rows: The image height in pixels.
2884 % o exception: return any errors or warnings in this structure.
2887 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2888 const size_t rows,ExceptionInfo *exception)
2890 if ((columns == 0) || (rows == 0))
2891 return(MagickFalse);
2892 image->columns=columns;
2894 return(SyncImagePixelCache(image,exception));
2898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2902 + S e t I m a g e I n f o %
2906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2908 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2909 % It is set to a type of image format based on the prefix or suffix of the
2910 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2911 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2912 % precendence over the suffix. Use an optional index enclosed in brackets
2913 % after a file name to specify a desired scene of a multi-resolution image
2914 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2915 % indicates success.
2917 % The format of the SetImageInfo method is:
2919 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2920 % const unsigned int frames,ExceptionInfo *exception)
2922 % A description of each parameter follows:
2924 % o image_info: the image info.
2926 % o frames: the number of images you intend to write.
2928 % o exception: return any errors or warnings in this structure.
2931 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2932 const unsigned int frames,ExceptionInfo *exception)
2935 extension[MaxTextExtent],
2936 filename[MaxTextExtent],
2937 magic[MaxTextExtent],
2939 subimage[MaxTextExtent];
2963 magick[2*MaxTextExtent];
2966 Look for 'image.format' in filename.
2968 assert(image_info != (ImageInfo *) NULL);
2969 assert(image_info->signature == MagickSignature);
2970 if (image_info->debug != MagickFalse)
2971 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2972 image_info->filename);
2976 GetPathComponent(image_info->filename,SubimagePath,subimage);
2977 if (*subimage != '\0')
2980 Look for scene specification (e.g. img0001.pcd[4]).
2982 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2984 if (IsGeometry(subimage) != MagickFalse)
2985 (void) CloneString(&image_info->extract,subimage);
2993 (void) CloneString(&image_info->scenes,subimage);
2994 image_info->scene=StringToUnsignedLong(image_info->scenes);
2995 image_info->number_scenes=image_info->scene;
2996 p=image_info->scenes;
2997 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2999 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3002 first=(size_t) strtol(p,&q,10);
3004 while (isspace((int) ((unsigned char) *q)) != 0)
3007 last=(size_t) strtol(q+1,&q,10);
3010 if (first < image_info->scene)
3011 image_info->scene=first;
3012 if (last > image_info->number_scenes)
3013 image_info->number_scenes=last;
3016 image_info->number_scenes-=image_info->scene-1;
3021 GetPathComponent(image_info->filename,ExtensionPath,extension);
3022 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3023 if (*extension != '\0')
3024 if ((LocaleCompare(extension,"gz") == 0) ||
3025 (LocaleCompare(extension,"Z") == 0) ||
3026 (LocaleCompare(extension,"wmz") == 0))
3029 path[MaxTextExtent];
3031 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3032 path[strlen(path)-strlen(extension)-1]='\0';
3033 GetPathComponent(path,ExtensionPath,extension);
3036 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3037 if (*extension != '\0')
3038 if (LocaleCompare(extension,"bz2") == 0)
3041 path[MaxTextExtent];
3043 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3044 path[strlen(path)-strlen(extension)-1]='\0';
3045 GetPathComponent(path,ExtensionPath,extension);
3048 image_info->affirm=MagickFalse;
3049 sans_exception=AcquireExceptionInfo();
3050 if (*extension != '\0')
3059 *format_type_formats[] =
3082 User specified image format.
3084 (void) CopyMagickString(magic,extension,MaxTextExtent);
3087 Look for explicit image formats.
3089 format_type=UndefinedFormatType;
3091 while ((format_type == UndefinedFormatType) &&
3092 (format_type_formats[i] != (char *) NULL))
3094 if ((*magic == *format_type_formats[i]) &&
3095 (LocaleCompare(magic,format_type_formats[i]) == 0))
3096 format_type=ExplicitFormatType;
3099 magick_info=GetMagickInfo(magic,sans_exception);
3100 if ((magick_info != (const MagickInfo *) NULL) &&
3101 (magick_info->format_type != UndefinedFormatType))
3102 format_type=magick_info->format_type;
3103 if (format_type == UndefinedFormatType)
3104 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3106 if (format_type == ExplicitFormatType)
3108 image_info->affirm=MagickTrue;
3109 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3111 if (LocaleCompare(magic,"RGB") == 0)
3112 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3115 Look for explicit 'format:image' in filename.
3118 GetPathComponent(image_info->filename,MagickPath,magic);
3120 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3124 User specified image format.
3127 if (IsMagickConflict(magic) == MagickFalse)
3129 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3130 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3131 image_info->affirm=MagickTrue;
3133 image_info->temporary=MagickTrue;
3136 magick_info=GetMagickInfo(magic,sans_exception);
3137 sans_exception=DestroyExceptionInfo(sans_exception);
3138 if ((magick_info == (const MagickInfo *) NULL) ||
3139 (GetMagickEndianSupport(magick_info) == MagickFalse))
3140 image_info->endian=UndefinedEndian;
3141 GetPathComponent(image_info->filename,CanonicalPath,filename);
3142 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3143 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3146 Test for multiple image support (e.g. image%02d.png).
3148 (void) InterpretImageFilename(image_info,(Image *) NULL,
3149 image_info->filename,(int) image_info->scene,filename,exception);
3150 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3151 (strchr(filename,'%') == (char *) NULL))
3152 image_info->adjoin=MagickFalse;
3154 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3157 Some image formats do not support multiple frames per file.
3159 magick_info=GetMagickInfo(magic,exception);
3160 if (magick_info != (const MagickInfo *) NULL)
3161 if (GetMagickAdjoin(magick_info) == MagickFalse)
3162 image_info->adjoin=MagickFalse;
3164 if (image_info->affirm != MagickFalse)
3169 Determine the image format from the first few bytes of the file.
3171 image=AcquireImage(image_info,exception);
3172 (void) CopyMagickString(image->filename,image_info->filename,
3174 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3175 if (status == MagickFalse)
3177 image=DestroyImage(image);
3178 return(MagickFalse);
3180 if ((IsBlobSeekable(image) == MagickFalse) ||
3181 (IsBlobExempt(image) != MagickFalse))
3184 Copy standard input or pipe to temporary file.
3187 status=ImageToFile(image,filename,exception);
3188 (void) CloseBlob(image);
3189 if (status == MagickFalse)
3191 image=DestroyImage(image);
3192 return(MagickFalse);
3194 SetImageInfoFile(image_info,(FILE *) NULL);
3195 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3196 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3197 if (status == MagickFalse)
3199 image=DestroyImage(image);
3200 return(MagickFalse);
3202 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3203 image_info->temporary=MagickTrue;
3205 (void) ResetMagickMemory(magick,0,sizeof(magick));
3206 count=ReadBlob(image,2*MaxTextExtent,magick);
3207 (void) CloseBlob(image);
3208 image=DestroyImage(image);
3210 Check magic.xml configuration file.
3212 sans_exception=AcquireExceptionInfo();
3213 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3214 if ((magic_info != (const MagicInfo *) NULL) &&
3215 (GetMagicName(magic_info) != (char *) NULL))
3217 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3219 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3220 if ((magick_info == (const MagickInfo *) NULL) ||
3221 (GetMagickEndianSupport(magick_info) == MagickFalse))
3222 image_info->endian=UndefinedEndian;
3223 sans_exception=DestroyExceptionInfo(sans_exception);
3226 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3227 if ((magick_info == (const MagickInfo *) NULL) ||
3228 (GetMagickEndianSupport(magick_info) == MagickFalse))
3229 image_info->endian=UndefinedEndian;
3230 sans_exception=DestroyExceptionInfo(sans_exception);
3236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3240 % S e t I m a g e I n f o B l o b %
3244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3246 % SetImageInfoBlob() sets the image info blob member.
3248 % The format of the SetImageInfoBlob method is:
3250 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3251 % const size_t length)
3253 % A description of each parameter follows:
3255 % o image_info: the image info.
3259 % o length: the blob length.
3262 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3263 const size_t length)
3265 assert(image_info != (ImageInfo *) NULL);
3266 assert(image_info->signature == MagickSignature);
3267 if (image_info->debug != MagickFalse)
3268 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3269 image_info->filename);
3270 image_info->blob=(void *) blob;
3271 image_info->length=length;
3275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3279 % S e t I m a g e I n f o F i l e %
3283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3285 % SetImageInfoFile() sets the image info file member.
3287 % The format of the SetImageInfoFile method is:
3289 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3291 % A description of each parameter follows:
3293 % o image_info: the image info.
3298 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3300 assert(image_info != (ImageInfo *) NULL);
3301 assert(image_info->signature == MagickSignature);
3302 if (image_info->debug != MagickFalse)
3303 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3304 image_info->filename);
3305 image_info->file=file;
3309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3313 % S e t I m a g e M a s k %
3317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3319 % SetImageMask() associates a mask with the image. The mask must be the same
3320 % dimensions as the image.
3322 % The format of the SetImageMask method is:
3324 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3325 % ExceptionInfo *exception)
3327 % A description of each parameter follows:
3329 % o image: the image.
3331 % o mask: the image mask.
3333 % o exception: return any errors or warnings in this structure.
3336 MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
3337 ExceptionInfo *exception)
3352 assert(image != (Image *) NULL);
3353 if (image->debug != MagickFalse)
3354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3355 assert(image->signature == MagickSignature);
3356 if (mask == (const Image *) NULL)
3358 image->mask=MagickFalse;
3361 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3362 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3364 image->mask=MagickTrue;
3365 image_view=AcquireCacheView(image);
3366 mask_view=AcquireCacheView(mask);
3367 for (y=0; y < (ssize_t) image->rows; y++)
3369 register const Quantum
3378 if (status == MagickFalse)
3380 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3381 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3382 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3387 for (x=0; x < (ssize_t) image->columns; x++)
3389 SetPixelMask(image,GetPixelGray(mask,p),q);
3390 p+=GetPixelChannels(mask);
3391 q+=GetPixelChannels(image);
3393 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3396 mask_view=DestroyCacheView(mask_view);
3397 image_view=DestroyCacheView(image_view);
3402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3406 % S e t I m a g e A l p h a %
3410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3412 % SetImageAlpha() sets the alpha levels of the image.
3414 % The format of the SetImageAlpha method is:
3416 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3417 % ExceptionInfo *exception)
3419 % A description of each parameter follows:
3421 % o image: the image.
3423 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3424 % fully transparent.
3427 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3428 ExceptionInfo *exception)
3439 assert(image != (Image *) NULL);
3440 if (image->debug != MagickFalse)
3441 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3442 assert(image->signature == MagickSignature);
3443 image->matte=MagickTrue;
3445 image_view=AcquireCacheView(image);
3446 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3447 #pragma omp parallel for schedule(static,4) shared(status)
3449 for (y=0; y < (ssize_t) image->rows; y++)
3457 if (status == MagickFalse)
3459 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3460 if (q == (Quantum *) NULL)
3465 for (x=0; x < (ssize_t) image->columns; x++)
3467 SetPixelAlpha(image,alpha,q);
3468 q+=GetPixelChannels(image);
3470 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3473 image_view=DestroyCacheView(image_view);
3478 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3482 % S e t I m a g e T y p e %
3486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3488 % SetImageType() sets the type of image. Choose from these types:
3490 % Bilevel Grayscale GrayscaleMatte
3491 % Palette PaletteMatte TrueColor
3492 % TrueColorMatte ColorSeparation ColorSeparationMatte
3495 % The format of the SetImageType method is:
3497 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3498 % ExceptionInfo *exception)
3500 % A description of each parameter follows:
3502 % o image: the image.
3504 % o type: Image type.
3506 % o exception: return any errors or warnings in this structure.
3509 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3510 ExceptionInfo *exception)
3524 assert(image != (Image *) NULL);
3525 if (image->debug != MagickFalse)
3526 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3527 assert(image->signature == MagickSignature);
3529 image_info=AcquireImageInfo();
3530 image_info->dither=image->dither;
3531 artifact=GetImageArtifact(image,"dither");
3532 if (artifact != (const char *) NULL)
3533 (void) SetImageOption(image_info,"dither",artifact);
3538 if (IsImageMonochrome(image,exception) == MagickFalse)
3540 quantize_info=AcquireQuantizeInfo(image_info);
3541 quantize_info->number_colors=2;
3542 quantize_info->colorspace=GRAYColorspace;
3543 status=QuantizeImage(quantize_info,image,exception);
3544 quantize_info=DestroyQuantizeInfo(quantize_info);
3546 image->matte=MagickFalse;
3551 if (IsImageGray(image,exception) == MagickFalse)
3552 status=TransformImageColorspace(image,GRAYColorspace,exception);
3553 image->matte=MagickFalse;
3556 case GrayscaleMatteType:
3558 if (IsImageGray(image,exception) == MagickFalse)
3559 status=TransformImageColorspace(image,GRAYColorspace,exception);
3560 if (image->matte == MagickFalse)
3561 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3566 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3567 status=TransformImageColorspace(image,RGBColorspace,exception);
3568 if ((image->storage_class == DirectClass) || (image->colors > 256))
3570 quantize_info=AcquireQuantizeInfo(image_info);
3571 quantize_info->number_colors=256;
3572 status=QuantizeImage(quantize_info,image,exception);
3573 quantize_info=DestroyQuantizeInfo(quantize_info);
3575 image->matte=MagickFalse;
3578 case PaletteBilevelMatteType:
3583 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3584 status=TransformImageColorspace(image,RGBColorspace,exception);
3585 if (image->matte == MagickFalse)
3586 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3587 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3588 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
3589 (void) SetPixelChannelMask(image,channel_mask);
3590 quantize_info=AcquireQuantizeInfo(image_info);
3591 status=QuantizeImage(quantize_info,image,exception);
3592 quantize_info=DestroyQuantizeInfo(quantize_info);
3595 case PaletteMatteType:
3597 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3598 status=TransformImageColorspace(image,RGBColorspace,exception);
3599 if (image->matte == MagickFalse)
3600 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3601 quantize_info=AcquireQuantizeInfo(image_info);
3602 quantize_info->colorspace=TransparentColorspace;
3603 status=QuantizeImage(quantize_info,image,exception);
3604 quantize_info=DestroyQuantizeInfo(quantize_info);
3609 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3610 status=TransformImageColorspace(image,RGBColorspace,exception);
3611 if (image->storage_class != DirectClass)
3612 status=SetImageStorageClass(image,DirectClass,exception);
3613 image->matte=MagickFalse;
3616 case TrueColorMatteType:
3618 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3619 status=TransformImageColorspace(image,RGBColorspace,exception);
3620 if (image->storage_class != DirectClass)
3621 status=SetImageStorageClass(image,DirectClass,exception);
3622 if (image->matte == MagickFalse)
3623 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3626 case ColorSeparationType:
3628 if (image->colorspace != CMYKColorspace)
3630 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3631 status=TransformImageColorspace(image,RGBColorspace,exception);
3632 status=TransformImageColorspace(image,CMYKColorspace,exception);
3634 if (image->storage_class != DirectClass)
3635 status=SetImageStorageClass(image,DirectClass,exception);
3636 image->matte=MagickFalse;
3639 case ColorSeparationMatteType:
3641 if (image->colorspace != CMYKColorspace)
3643 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3644 status=TransformImageColorspace(image,RGBColorspace,exception);
3645 status=TransformImageColorspace(image,CMYKColorspace,exception);
3647 if (image->storage_class != DirectClass)
3648 status=SetImageStorageClass(image,DirectClass,exception);
3649 if (image->matte == MagickFalse)
3650 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3658 image_info=DestroyImageInfo(image_info);
3663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3667 % 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 %
3671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3673 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3674 % image and returns the previous setting. A virtual pixel is any pixel access
3675 % that is outside the boundaries of the image cache.
3677 % The format of the SetImageVirtualPixelMethod() method is:
3679 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3680 % const VirtualPixelMethod virtual_pixel_method)
3682 % A description of each parameter follows:
3684 % o image: the image.
3686 % o virtual_pixel_method: choose the type of virtual pixel.
3689 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3690 const VirtualPixelMethod virtual_pixel_method)
3692 assert(image != (const Image *) NULL);
3693 assert(image->signature == MagickSignature);
3694 if (image->debug != MagickFalse)
3695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3696 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3704 % S m u s h I m a g e s %
3708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3710 % SmushImages() takes all images from the current image pointer to the end
3711 % of the image list and smushes them to each other top-to-bottom if the
3712 % stack parameter is true, otherwise left-to-right.
3714 % The current gravity setting now effects how the image is justified in the
3717 % The format of the SmushImages method is:
3719 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3720 % ExceptionInfo *exception)
3722 % A description of each parameter follows:
3724 % o images: the image sequence.
3726 % o stack: A value other than 0 stacks the images top-to-bottom.
3728 % o offset: minimum distance in pixels between images.
3730 % o exception: return any errors or warnings in this structure.
3734 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3735 const ssize_t offset,ExceptionInfo *exception)
3749 register const Quantum
3762 if (images->previous == (Image *) NULL)
3765 SetGeometry(smush_image,&right_geometry);
3766 GravityAdjustGeometry(right_image->columns,right_image->rows,
3767 right_image->gravity,&right_geometry);
3768 left_image=images->previous;
3769 SetGeometry(smush_image,&left_geometry);
3770 GravityAdjustGeometry(left_image->columns,left_image->rows,
3771 left_image->gravity,&left_geometry);
3772 gap=right_image->columns;
3773 left_view=AcquireCacheView(left_image);
3774 right_view=AcquireCacheView(right_image);
3775 for (y=0; y < (ssize_t) smush_image->rows; y++)
3777 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3779 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3780 if ((p == (const Quantum *) NULL) ||
3781 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3782 ((left_image->columns-x-1) >= gap))
3785 i=(ssize_t) left_image->columns-x-1;
3786 for (x=0; x < (ssize_t) right_image->columns; x++)
3788 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3790 if ((p == (const Quantum *) NULL) ||
3791 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3792 ((x+i) >= (ssize_t) gap))
3795 if ((x+i) < (ssize_t) gap)
3798 right_view=DestroyCacheView(right_view);
3799 left_view=DestroyCacheView(left_view);
3800 if (y < (ssize_t) smush_image->rows)
3802 return((ssize_t) gap-offset);
3805 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3806 const ssize_t offset,ExceptionInfo *exception)
3820 register const Quantum
3833 if (images->previous == (Image *) NULL)
3835 bottom_image=images;
3836 SetGeometry(smush_image,&bottom_geometry);
3837 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3838 bottom_image->gravity,&bottom_geometry);
3839 top_image=images->previous;
3840 SetGeometry(smush_image,&top_geometry);
3841 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3843 gap=bottom_image->rows;
3844 top_view=AcquireCacheView(top_image);
3845 bottom_view=AcquireCacheView(bottom_image);
3846 for (x=0; x < (ssize_t) smush_image->columns; x++)
3848 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3850 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3851 if ((p == (const Quantum *) NULL) ||
3852 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3853 ((top_image->rows-y-1) >= gap))
3856 i=(ssize_t) top_image->rows-y-1;
3857 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3859 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3861 if ((p == (const Quantum *) NULL) ||
3862 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3863 ((y+i) >= (ssize_t) gap))
3866 if ((y+i) < (ssize_t) gap)
3869 bottom_view=DestroyCacheView(bottom_view);
3870 top_view=DestroyCacheView(top_view);
3871 if (x < (ssize_t) smush_image->columns)
3873 return((ssize_t) gap-offset);
3876 MagickExport Image *SmushImages(const Image *images,
3877 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3879 #define SmushImageTag "Smush/Image"
3901 register const Image
3914 Compute maximum area of smushed area.
3916 assert(images != (Image *) NULL);
3917 assert(images->signature == MagickSignature);
3918 if (images->debug != MagickFalse)
3919 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3920 assert(exception != (ExceptionInfo *) NULL);
3921 assert(exception->signature == MagickSignature);
3925 width=image->columns;
3927 next=GetNextImageInList(image);
3928 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3930 if (next->matte != MagickFalse)
3933 if (stack != MagickFalse)
3935 if (next->columns > width)
3936 width=next->columns;
3938 if (next->previous != (Image *) NULL)
3942 width+=next->columns;
3943 if (next->previous != (Image *) NULL)
3945 if (next->rows > height)
3951 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3952 if (smush_image == (Image *) NULL)
3953 return((Image *) NULL);
3954 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3956 smush_image=DestroyImage(smush_image);
3957 return((Image *) NULL);
3959 smush_image->matte=matte;
3960 (void) SetImageBackgroundColor(smush_image,exception);
3964 smush_view=AcquireCacheView(smush_image);
3965 for (n=0; n < (MagickOffsetType) number_images; n++)
3967 SetGeometry(smush_image,&geometry);
3968 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3969 if (stack != MagickFalse)
3971 x_offset-=geometry.x;
3972 y_offset-=SmushYGap(smush_image,image,offset,exception);
3976 x_offset-=SmushXGap(smush_image,image,offset,exception);
3977 y_offset-=geometry.y;
3979 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
3981 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3982 if (proceed == MagickFalse)
3984 if (stack == MagickFalse)
3986 x_offset+=(ssize_t) image->columns;
3992 y_offset+=(ssize_t) image->rows;
3994 image=GetNextImageInList(image);
3996 if (stack == MagickFalse)
3997 smush_image->columns=(size_t) x_offset;
3999 smush_image->rows=(size_t) y_offset;
4000 smush_view=DestroyCacheView(smush_view);
4001 if (status == MagickFalse)
4002 smush_image=DestroyImage(smush_image);
4003 return(smush_image);
4007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4011 % S t r i p I m a g e %
4015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4017 % StripImage() strips an image of all profiles and comments.
4019 % The format of the StripImage method is:
4021 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
4023 % A description of each parameter follows:
4025 % o image: the image.
4027 % o exception: return any errors or warnings in this structure.
4030 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
4035 assert(image != (Image *) NULL);
4036 if (image->debug != MagickFalse)
4037 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4039 DestroyImageProfiles(image);
4040 (void) DeleteImageProperty(image,"comment");
4041 (void) DeleteImageProperty(image,"date:create");
4042 (void) DeleteImageProperty(image,"date:modify");
4043 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4052 + S y n c I m a g e %
4056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4058 % SyncImage() initializes the red, green, and blue intensities of each pixel
4059 % as defined by the colormap index.
4061 % The format of the SyncImage method is:
4063 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4065 % A description of each parameter follows:
4067 % o image: the image.
4069 % o exception: return any errors or warnings in this structure.
4073 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
4074 MagickBooleanType *range_exception)
4076 if ((size_t) index < image->colors)
4078 *range_exception=MagickTrue;
4082 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4094 assert(image != (Image *) NULL);
4095 if (image->debug != MagickFalse)
4096 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4097 assert(image->signature == MagickSignature);
4098 if (image->storage_class == DirectClass)
4099 return(MagickFalse);
4100 range_exception=MagickFalse;
4102 image_view=AcquireCacheView(image);
4103 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4104 #pragma omp parallel for schedule(static,4) shared(range_exception,status)
4106 for (y=0; y < (ssize_t) image->rows; y++)
4117 if (status == MagickFalse)
4119 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4120 if (q == (Quantum *) NULL)
4125 for (x=0; x < (ssize_t) image->columns; x++)
4127 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4128 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
4129 q+=GetPixelChannels(image);
4131 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4134 image_view=DestroyCacheView(image_view);
4135 if (range_exception != MagickFalse)
4136 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
4137 "InvalidColormapIndex","`%s'",image->filename);
4142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4146 % S y n c I m a g e S e t t i n g s %
4150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4152 % SyncImageSettings() syncs the image_info options into per-image attributes.
4154 % The format of the SyncImageSettings method is:
4156 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4157 % Image *image,ExceptionInfo *exception)
4158 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4159 % Image *image,ExceptionInfo *exception)
4161 % A description of each parameter follows:
4163 % o image_info: the image info.
4165 % o image: the image.
4167 % o exception: return any errors or warnings in this structure.
4171 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4172 Image *images,ExceptionInfo *exception)
4177 assert(image_info != (const ImageInfo *) NULL);
4178 assert(image_info->signature == MagickSignature);
4179 assert(images != (Image *) NULL);
4180 assert(images->signature == MagickSignature);
4181 if (images->debug != MagickFalse)
4182 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4184 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4185 (void) SyncImageSettings(image_info,image,exception);
4186 (void) DeleteImageOption(image_info,"page");
4190 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4191 Image *image,ExceptionInfo *exception)
4194 property[MaxTextExtent];
4212 assert(image_info != (const ImageInfo *) NULL);
4213 assert(image_info->signature == MagickSignature);
4214 assert(image != (Image *) NULL);
4215 assert(image->signature == MagickSignature);
4216 if (image->debug != MagickFalse)
4217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4218 option=GetImageOption(image_info,"background");
4219 if (option != (const char *) NULL)
4220 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4222 option=GetImageOption(image_info,"bias");
4223 if (option != (const char *) NULL)
4224 image->bias=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4225 option=GetImageOption(image_info,"black-point-compensation");
4226 if (option != (const char *) NULL)
4227 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4228 MagickBooleanOptions,MagickFalse,option);
4229 option=GetImageOption(image_info,"blue-primary");
4230 if (option != (const char *) NULL)
4232 flags=ParseGeometry(option,&geometry_info);
4233 image->chromaticity.blue_primary.x=geometry_info.rho;
4234 image->chromaticity.blue_primary.y=geometry_info.sigma;
4235 if ((flags & SigmaValue) == 0)
4236 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4238 option=GetImageOption(image_info,"bordercolor");
4239 if (option != (const char *) NULL)
4240 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4242 /* FUTURE: do not sync compose to per-image compose setting here */
4243 option=GetImageOption(image_info,"compose");
4244 if (option != (const char *) NULL)
4245 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4246 MagickFalse,option);
4248 option=GetImageOption(image_info,"compress");
4249 if (option != (const char *) NULL)
4250 image->compression=(CompressionType) ParseCommandOption(
4251 MagickCompressOptions,MagickFalse,option);
4252 option=GetImageOption(image_info,"debug");
4253 if (option != (const char *) NULL)
4254 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4255 MagickFalse,option);
4256 option=GetImageOption(image_info,"density");
4257 if (option != (const char *) NULL)
4262 flags=ParseGeometry(option,&geometry_info);
4263 image->resolution.x=geometry_info.rho;
4264 image->resolution.y=geometry_info.sigma;
4265 if ((flags & SigmaValue) == 0)
4266 image->resolution.y=image->resolution.x;
4268 option=GetImageOption(image_info,"depth");
4269 if (option != (const char *) NULL)
4270 image->depth=StringToUnsignedLong(option);
4271 option=GetImageOption(image_info,"endian");
4272 if (option != (const char *) NULL)
4273 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4274 MagickFalse,option);
4275 option=GetImageOption(image_info,"filter");
4276 if (option != (const char *) NULL)
4277 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4278 MagickFalse,option);
4279 option=GetImageOption(image_info,"fuzz");
4280 if (option != (const char *) NULL)
4281 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4282 option=GetImageOption(image_info,"gravity");
4283 if (option != (const char *) NULL)
4284 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4285 MagickFalse,option);
4286 option=GetImageOption(image_info,"green-primary");
4287 if (option != (const char *) NULL)
4289 flags=ParseGeometry(option,&geometry_info);
4290 image->chromaticity.green_primary.x=geometry_info.rho;
4291 image->chromaticity.green_primary.y=geometry_info.sigma;
4292 if ((flags & SigmaValue) == 0)
4293 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4295 option=GetImageOption(image_info,"intent");
4296 if (option != (const char *) NULL)
4297 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4298 MagickIntentOptions,MagickFalse,option);
4299 option=GetImageOption(image_info,"interlace");
4300 if (option != (const char *) NULL)
4301 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4302 MagickFalse,option);
4303 option=GetImageOption(image_info,"interpolate");
4304 if (option != (const char *) NULL)
4305 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4306 MagickInterpolateOptions,MagickFalse,option);
4307 option=GetImageOption(image_info,"loop");
4308 if (option != (const char *) NULL)
4309 image->iterations=StringToUnsignedLong(option);
4310 option=GetImageOption(image_info,"mattecolor");
4311 if (option != (const char *) NULL)
4312 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4314 option=GetImageOption(image_info,"orient");
4315 if (option != (const char *) NULL)
4316 image->orientation=(OrientationType) ParseCommandOption(
4317 MagickOrientationOptions,MagickFalse,option);
4318 option=GetImageOption(image_info,"page");
4319 if (option != (const char *) NULL)
4324 geometry=GetPageGeometry(option);
4325 flags=ParseAbsoluteGeometry(geometry,&image->page);
4326 geometry=DestroyString(geometry);
4328 option=GetImageOption(image_info,"quality");
4329 if (option != (const char *) NULL)
4330 image->quality=StringToUnsignedLong(option);
4331 option=GetImageOption(image_info,"red-primary");
4332 if (option != (const char *) NULL)
4334 flags=ParseGeometry(option,&geometry_info);
4335 image->chromaticity.red_primary.x=geometry_info.rho;
4336 image->chromaticity.red_primary.y=geometry_info.sigma;
4337 if ((flags & SigmaValue) == 0)
4338 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4340 if (image_info->quality != UndefinedCompressionQuality)
4341 image->quality=image_info->quality;
4342 option=GetImageOption(image_info,"scene");
4343 if (option != (const char *) NULL)
4344 image->scene=StringToUnsignedLong(option);
4345 option=GetImageOption(image_info,"taint");
4346 if (option != (const char *) NULL)
4347 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4348 MagickFalse,option);
4349 option=GetImageOption(image_info,"tile-offset");
4350 if (option != (const char *) NULL)
4355 geometry=GetPageGeometry(option);
4356 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4357 geometry=DestroyString(geometry);
4359 option=GetImageOption(image_info,"transparent-color");
4360 if (option != (const char *) NULL)
4361 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4363 option=GetImageOption(image_info,"type");
4364 if (option != (const char *) NULL)
4365 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4367 option=GetImageOption(image_info,"units");
4368 units=image_info->units;
4369 if (option != (const char *) NULL)
4370 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4371 MagickFalse,option);
4372 if (units != UndefinedResolution)
4374 if (image->units != units)
4375 switch (image->units)
4377 case PixelsPerInchResolution:
4379 if (units == PixelsPerCentimeterResolution)
4381 image->resolution.x/=2.54;
4382 image->resolution.y/=2.54;
4386 case PixelsPerCentimeterResolution:
4388 if (units == PixelsPerInchResolution)
4390 image->resolution.x=(double) ((size_t) (100.0*2.54*
4391 image->resolution.x+0.5))/100.0;
4392 image->resolution.y=(double) ((size_t) (100.0*2.54*
4393 image->resolution.y+0.5))/100.0;
4402 option=GetImageOption(image_info,"virtual-pixel");
4403 if (option != (const char *) NULL)
4404 (void) SetImageVirtualPixelMethod(image, (VirtualPixelMethod)
4405 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option));
4406 option=GetImageOption(image_info,"white-point");
4407 if (option != (const char *) NULL)
4409 flags=ParseGeometry(option,&geometry_info);
4410 image->chromaticity.white_point.x=geometry_info.rho;
4411 image->chromaticity.white_point.y=geometry_info.sigma;
4412 if ((flags & SigmaValue) == 0)
4413 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4415 ResetImageOptionIterator(image_info);
4416 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4418 value=GetImageOption(image_info,option);
4419 if (value != (const char *) NULL)
4421 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4422 (void) SetImageArtifact(image,property,value);
4424 option=GetNextImageOption(image_info);