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=sRGBColorspace;
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 Remove transparency.
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);
2641 image->matte=image->background_color.matte;
2644 case SetAlphaChannel:
2646 if (image->matte == MagickFalse)
2647 status=SetImageAlpha(image,OpaqueAlpha,exception);
2650 case TransparentAlphaChannel:
2652 status=SetImageAlpha(image,TransparentAlpha,exception);
2655 case UndefinedAlphaChannel:
2658 if (status == MagickFalse)
2660 return(SyncImagePixelCache(image,exception));
2664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2668 % S e t I m a g e B a c k g r o u n d C o l o r %
2672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2674 % SetImageBackgroundColor() initializes the image pixels to the image
2675 % background color. The background color is defined by the background_color
2676 % member of the image structure.
2678 % The format of the SetImage method is:
2680 % MagickBooleanType SetImageBackgroundColor(Image *image,
2681 % ExceptionInfo *exception)
2683 % A description of each parameter follows:
2685 % o image: the image.
2687 % o exception: return any errors or warnings in this structure.
2690 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2691 ExceptionInfo *exception)
2702 assert(image != (Image *) NULL);
2703 if (image->debug != MagickFalse)
2704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2705 assert(image->signature == MagickSignature);
2706 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2707 return(MagickFalse);
2708 if ((image->border_color.matte != MagickFalse) &&
2709 (image->matte == MagickFalse))
2710 (void) SetImageAlpha(image,OpaqueAlpha,exception);
2712 Set image background color.
2715 image_view=AcquireCacheView(image);
2716 for (y=0; y < (ssize_t) image->rows; y++)
2724 if (status == MagickFalse)
2726 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2727 if (q == (Quantum *) NULL)
2732 for (x=0; x < (ssize_t) image->columns; x++)
2734 SetPixelInfoPixel(image,&image->background_color,q);
2735 q+=GetPixelChannels(image);
2737 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2740 image_view=DestroyCacheView(image_view);
2745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2749 % S e t I m a g e C o l o r %
2753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2755 % SetImageColor() set the entire image canvas to the specified color.
2757 % The format of the SetImageColor method is:
2759 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2760 % ExeptionInfo *exception)
2762 % A description of each parameter follows:
2764 % o image: the image.
2766 % o background: the image color.
2768 % o exception: return any errors or warnings in this structure.
2771 MagickExport MagickBooleanType SetImageColor(Image *image,
2772 const PixelInfo *color,ExceptionInfo *exception)
2783 assert(image != (Image *) NULL);
2784 if (image->debug != MagickFalse)
2785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2786 assert(image->signature == MagickSignature);
2787 assert(color != (const PixelInfo *) NULL);
2788 image->colorspace=color->colorspace;
2789 image->matte=color->matte;
2790 image->fuzz=color->fuzz;
2791 image->depth=color->depth;
2793 image_view=AcquireCacheView(image);
2794 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2795 #pragma omp parallel for schedule(static,4) shared(status)
2797 for (y=0; y < (ssize_t) image->rows; y++)
2805 if (status == MagickFalse)
2807 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2808 if (q == (Quantum *) NULL)
2813 for (x=0; x < (ssize_t) image->columns; x++)
2815 SetPixelInfoPixel(image,color,q);
2816 q+=GetPixelChannels(image);
2818 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2821 image_view=DestroyCacheView(image_view);
2826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2830 % S e t I m a g e S t o r a g e C l a s s %
2834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2836 % SetImageStorageClass() sets the image class: DirectClass for true color
2837 % images or PseudoClass for colormapped images.
2839 % The format of the SetImageStorageClass method is:
2841 % MagickBooleanType SetImageStorageClass(Image *image,
2842 % const ClassType storage_class,ExceptionInfo *exception)
2844 % A description of each parameter follows:
2846 % o image: the image.
2848 % o storage_class: The image class.
2850 % o exception: return any errors or warnings in this structure.
2853 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2854 const ClassType storage_class,ExceptionInfo *exception)
2856 image->storage_class=storage_class;
2857 return(SyncImagePixelCache(image,exception));
2861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2865 % S e t I m a g e E x t e n t %
2869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2871 % SetImageExtent() sets the image size (i.e. columns & rows).
2873 % The format of the SetImageExtent method is:
2875 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2876 % const size_t rows,ExceptionInfo *exception)
2878 % A description of each parameter follows:
2880 % o image: the image.
2882 % o columns: The image width in pixels.
2884 % o rows: The image height in pixels.
2886 % o exception: return any errors or warnings in this structure.
2889 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2890 const size_t rows,ExceptionInfo *exception)
2892 if ((columns == 0) || (rows == 0))
2893 return(MagickFalse);
2894 image->columns=columns;
2896 return(SyncImagePixelCache(image,exception));
2900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2904 + S e t I m a g e I n f o %
2908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2910 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2911 % It is set to a type of image format based on the prefix or suffix of the
2912 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2913 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2914 % precendence over the suffix. Use an optional index enclosed in brackets
2915 % after a file name to specify a desired scene of a multi-resolution image
2916 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2917 % indicates success.
2919 % The format of the SetImageInfo method is:
2921 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2922 % const unsigned int frames,ExceptionInfo *exception)
2924 % A description of each parameter follows:
2926 % o image_info: the image info.
2928 % o frames: the number of images you intend to write.
2930 % o exception: return any errors or warnings in this structure.
2933 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2934 const unsigned int frames,ExceptionInfo *exception)
2937 extension[MaxTextExtent],
2938 filename[MaxTextExtent],
2939 magic[MaxTextExtent],
2941 subimage[MaxTextExtent];
2965 magick[2*MaxTextExtent];
2968 Look for 'image.format' in filename.
2970 assert(image_info != (ImageInfo *) NULL);
2971 assert(image_info->signature == MagickSignature);
2972 if (image_info->debug != MagickFalse)
2973 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2974 image_info->filename);
2978 GetPathComponent(image_info->filename,SubimagePath,subimage);
2979 if (*subimage != '\0')
2982 Look for scene specification (e.g. img0001.pcd[4]).
2984 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2986 if (IsGeometry(subimage) != MagickFalse)
2987 (void) CloneString(&image_info->extract,subimage);
2995 (void) CloneString(&image_info->scenes,subimage);
2996 image_info->scene=StringToUnsignedLong(image_info->scenes);
2997 image_info->number_scenes=image_info->scene;
2998 p=image_info->scenes;
2999 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3001 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3004 first=(size_t) strtol(p,&q,10);
3006 while (isspace((int) ((unsigned char) *q)) != 0)
3009 last=(size_t) strtol(q+1,&q,10);
3012 if (first < image_info->scene)
3013 image_info->scene=first;
3014 if (last > image_info->number_scenes)
3015 image_info->number_scenes=last;
3018 image_info->number_scenes-=image_info->scene-1;
3023 GetPathComponent(image_info->filename,ExtensionPath,extension);
3024 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3025 if (*extension != '\0')
3026 if ((LocaleCompare(extension,"gz") == 0) ||
3027 (LocaleCompare(extension,"Z") == 0) ||
3028 (LocaleCompare(extension,"svgz") == 0) ||
3029 (LocaleCompare(extension,"wmz") == 0))
3032 path[MaxTextExtent];
3034 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3035 path[strlen(path)-strlen(extension)-1]='\0';
3036 GetPathComponent(path,ExtensionPath,extension);
3039 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3040 if (*extension != '\0')
3041 if (LocaleCompare(extension,"bz2") == 0)
3044 path[MaxTextExtent];
3046 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3047 path[strlen(path)-strlen(extension)-1]='\0';
3048 GetPathComponent(path,ExtensionPath,extension);
3051 image_info->affirm=MagickFalse;
3052 sans_exception=AcquireExceptionInfo();
3053 if (*extension != '\0')
3062 *format_type_formats[] =
3085 User specified image format.
3087 (void) CopyMagickString(magic,extension,MaxTextExtent);
3090 Look for explicit image formats.
3092 format_type=UndefinedFormatType;
3094 while ((format_type == UndefinedFormatType) &&
3095 (format_type_formats[i] != (char *) NULL))
3097 if ((*magic == *format_type_formats[i]) &&
3098 (LocaleCompare(magic,format_type_formats[i]) == 0))
3099 format_type=ExplicitFormatType;
3102 magick_info=GetMagickInfo(magic,sans_exception);
3103 if ((magick_info != (const MagickInfo *) NULL) &&
3104 (magick_info->format_type != UndefinedFormatType))
3105 format_type=magick_info->format_type;
3106 if (format_type == UndefinedFormatType)
3107 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3109 if (format_type == ExplicitFormatType)
3111 image_info->affirm=MagickTrue;
3112 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3114 if (LocaleCompare(magic,"RGB") == 0)
3115 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3118 Look for explicit 'format:image' in filename.
3121 GetPathComponent(image_info->filename,MagickPath,magic);
3123 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3127 User specified image format.
3130 if (IsMagickConflict(magic) == MagickFalse)
3132 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3133 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3134 image_info->affirm=MagickTrue;
3136 image_info->temporary=MagickTrue;
3139 magick_info=GetMagickInfo(magic,sans_exception);
3140 sans_exception=DestroyExceptionInfo(sans_exception);
3141 if ((magick_info == (const MagickInfo *) NULL) ||
3142 (GetMagickEndianSupport(magick_info) == MagickFalse))
3143 image_info->endian=UndefinedEndian;
3144 GetPathComponent(image_info->filename,CanonicalPath,filename);
3145 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3146 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3149 Test for multiple image support (e.g. image%02d.png).
3151 (void) InterpretImageFilename(image_info,(Image *) NULL,
3152 image_info->filename,(int) image_info->scene,filename,exception);
3153 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3154 (strchr(filename,'%') == (char *) NULL))
3155 image_info->adjoin=MagickFalse;
3157 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3160 Some image formats do not support multiple frames per file.
3162 magick_info=GetMagickInfo(magic,exception);
3163 if (magick_info != (const MagickInfo *) NULL)
3164 if (GetMagickAdjoin(magick_info) == MagickFalse)
3165 image_info->adjoin=MagickFalse;
3167 if (image_info->affirm != MagickFalse)
3172 Determine the image format from the first few bytes of the file.
3174 image=AcquireImage(image_info,exception);
3175 (void) CopyMagickString(image->filename,image_info->filename,
3177 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3178 if (status == MagickFalse)
3180 image=DestroyImage(image);
3181 return(MagickFalse);
3183 if ((IsBlobSeekable(image) == MagickFalse) ||
3184 (IsBlobExempt(image) != MagickFalse))
3187 Copy standard input or pipe to temporary file.
3190 status=ImageToFile(image,filename,exception);
3191 (void) CloseBlob(image);
3192 if (status == MagickFalse)
3194 image=DestroyImage(image);
3195 return(MagickFalse);
3197 SetImageInfoFile(image_info,(FILE *) NULL);
3198 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3199 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3200 if (status == MagickFalse)
3202 image=DestroyImage(image);
3203 return(MagickFalse);
3205 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3206 image_info->temporary=MagickTrue;
3208 (void) ResetMagickMemory(magick,0,sizeof(magick));
3209 count=ReadBlob(image,2*MaxTextExtent,magick);
3210 (void) CloseBlob(image);
3211 image=DestroyImage(image);
3213 Check magic.xml configuration file.
3215 sans_exception=AcquireExceptionInfo();
3216 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3217 if ((magic_info != (const MagicInfo *) NULL) &&
3218 (GetMagicName(magic_info) != (char *) NULL))
3220 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3222 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3223 if ((magick_info == (const MagickInfo *) NULL) ||
3224 (GetMagickEndianSupport(magick_info) == MagickFalse))
3225 image_info->endian=UndefinedEndian;
3226 sans_exception=DestroyExceptionInfo(sans_exception);
3229 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3230 if ((magick_info == (const MagickInfo *) NULL) ||
3231 (GetMagickEndianSupport(magick_info) == MagickFalse))
3232 image_info->endian=UndefinedEndian;
3233 sans_exception=DestroyExceptionInfo(sans_exception);
3239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3243 % S e t I m a g e I n f o B l o b %
3247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3249 % SetImageInfoBlob() sets the image info blob member.
3251 % The format of the SetImageInfoBlob method is:
3253 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3254 % const size_t length)
3256 % A description of each parameter follows:
3258 % o image_info: the image info.
3262 % o length: the blob length.
3265 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3266 const size_t length)
3268 assert(image_info != (ImageInfo *) NULL);
3269 assert(image_info->signature == MagickSignature);
3270 if (image_info->debug != MagickFalse)
3271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3272 image_info->filename);
3273 image_info->blob=(void *) blob;
3274 image_info->length=length;
3278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3282 % S e t I m a g e I n f o F i l e %
3286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3288 % SetImageInfoFile() sets the image info file member.
3290 % The format of the SetImageInfoFile method is:
3292 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3294 % A description of each parameter follows:
3296 % o image_info: the image info.
3301 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3303 assert(image_info != (ImageInfo *) NULL);
3304 assert(image_info->signature == MagickSignature);
3305 if (image_info->debug != MagickFalse)
3306 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3307 image_info->filename);
3308 image_info->file=file;
3312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3316 % S e t I m a g e M a s k %
3320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3322 % SetImageMask() associates a mask with the image. The mask must be the same
3323 % dimensions as the image.
3325 % The format of the SetImageMask method is:
3327 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3328 % ExceptionInfo *exception)
3330 % A description of each parameter follows:
3332 % o image: the image.
3334 % o mask: the image mask.
3336 % o exception: return any errors or warnings in this structure.
3339 MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
3340 ExceptionInfo *exception)
3355 assert(image != (Image *) NULL);
3356 if (image->debug != MagickFalse)
3357 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3358 assert(image->signature == MagickSignature);
3359 if (mask == (const Image *) NULL)
3361 image->mask=MagickFalse;
3365 image->mask=MagickTrue;
3366 image_view=AcquireCacheView(image);
3367 mask_view=AcquireCacheView(mask);
3368 for (y=0; y < (ssize_t) image->rows; y++)
3370 register const Quantum
3379 if (status == MagickFalse)
3381 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3382 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3383 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3388 for (x=0; x < (ssize_t) image->columns; x++)
3390 SetPixelMask(image,GetPixelGray(mask,p),q);
3391 p+=GetPixelChannels(mask);
3392 q+=GetPixelChannels(image);
3394 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3397 mask_view=DestroyCacheView(mask_view);
3398 image_view=DestroyCacheView(image_view);
3403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3407 % S e t I m a g e A l p h a %
3411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3413 % SetImageAlpha() sets the alpha levels of the image.
3415 % The format of the SetImageAlpha method is:
3417 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3418 % ExceptionInfo *exception)
3420 % A description of each parameter follows:
3422 % o image: the image.
3424 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3425 % fully transparent.
3428 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3429 ExceptionInfo *exception)
3440 assert(image != (Image *) NULL);
3441 if (image->debug != MagickFalse)
3442 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3443 assert(image->signature == MagickSignature);
3444 image->matte=MagickTrue;
3446 image_view=AcquireCacheView(image);
3447 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3448 #pragma omp parallel for schedule(static,4) shared(status)
3450 for (y=0; y < (ssize_t) image->rows; y++)
3458 if (status == MagickFalse)
3460 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3461 if (q == (Quantum *) NULL)
3466 for (x=0; x < (ssize_t) image->columns; x++)
3468 SetPixelAlpha(image,alpha,q);
3469 q+=GetPixelChannels(image);
3471 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3474 image_view=DestroyCacheView(image_view);
3479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3483 % S e t I m a g e T y p e %
3487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3489 % SetImageType() sets the type of image. Choose from these types:
3491 % Bilevel Grayscale GrayscaleMatte
3492 % Palette PaletteMatte TrueColor
3493 % TrueColorMatte ColorSeparation ColorSeparationMatte
3496 % The format of the SetImageType method is:
3498 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3499 % ExceptionInfo *exception)
3501 % A description of each parameter follows:
3503 % o image: the image.
3505 % o type: Image type.
3507 % o exception: return any errors or warnings in this structure.
3510 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3511 ExceptionInfo *exception)
3525 assert(image != (Image *) NULL);
3526 if (image->debug != MagickFalse)
3527 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3528 assert(image->signature == MagickSignature);
3530 image_info=AcquireImageInfo();
3531 image_info->dither=image->dither;
3532 artifact=GetImageArtifact(image,"dither");
3533 if (artifact != (const char *) NULL)
3534 (void) SetImageOption(image_info,"dither",artifact);
3539 if (IsImageMonochrome(image,exception) == MagickFalse)
3541 quantize_info=AcquireQuantizeInfo(image_info);
3542 quantize_info->number_colors=2;
3543 quantize_info->colorspace=GRAYColorspace;
3544 status=QuantizeImage(quantize_info,image,exception);
3545 quantize_info=DestroyQuantizeInfo(quantize_info);
3547 image->matte=MagickFalse;
3552 if (IsImageGray(image,exception) == MagickFalse)
3553 status=TransformImageColorspace(image,GRAYColorspace,exception);
3554 image->matte=MagickFalse;
3557 case GrayscaleMatteType:
3559 if (IsImageGray(image,exception) == MagickFalse)
3560 status=TransformImageColorspace(image,GRAYColorspace,exception);
3561 if (image->matte == MagickFalse)
3562 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3567 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3568 status=TransformImageColorspace(image,sRGBColorspace,exception);
3569 if ((image->storage_class == DirectClass) || (image->colors > 256))
3571 quantize_info=AcquireQuantizeInfo(image_info);
3572 quantize_info->number_colors=256;
3573 status=QuantizeImage(quantize_info,image,exception);
3574 quantize_info=DestroyQuantizeInfo(quantize_info);
3576 image->matte=MagickFalse;
3579 case PaletteBilevelMatteType:
3584 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3585 status=TransformImageColorspace(image,sRGBColorspace,exception);
3586 if (image->matte == MagickFalse)
3587 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3588 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3589 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
3590 (void) SetPixelChannelMask(image,channel_mask);
3591 quantize_info=AcquireQuantizeInfo(image_info);
3592 status=QuantizeImage(quantize_info,image,exception);
3593 quantize_info=DestroyQuantizeInfo(quantize_info);
3596 case PaletteMatteType:
3598 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3599 status=TransformImageColorspace(image,sRGBColorspace,exception);
3600 if (image->matte == MagickFalse)
3601 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3602 quantize_info=AcquireQuantizeInfo(image_info);
3603 quantize_info->colorspace=TransparentColorspace;
3604 status=QuantizeImage(quantize_info,image,exception);
3605 quantize_info=DestroyQuantizeInfo(quantize_info);
3610 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3611 status=TransformImageColorspace(image,sRGBColorspace,exception);
3612 if (image->storage_class != DirectClass)
3613 status=SetImageStorageClass(image,DirectClass,exception);
3614 image->matte=MagickFalse;
3617 case TrueColorMatteType:
3619 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3620 status=TransformImageColorspace(image,sRGBColorspace,exception);
3621 if (image->storage_class != DirectClass)
3622 status=SetImageStorageClass(image,DirectClass,exception);
3623 if (image->matte == MagickFalse)
3624 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3627 case ColorSeparationType:
3629 if (image->colorspace != CMYKColorspace)
3631 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3632 status=TransformImageColorspace(image,sRGBColorspace,exception);
3633 status=TransformImageColorspace(image,CMYKColorspace,exception);
3635 if (image->storage_class != DirectClass)
3636 status=SetImageStorageClass(image,DirectClass,exception);
3637 image->matte=MagickFalse;
3640 case ColorSeparationMatteType:
3642 if (image->colorspace != CMYKColorspace)
3644 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3645 status=TransformImageColorspace(image,sRGBColorspace,exception);
3646 status=TransformImageColorspace(image,CMYKColorspace,exception);
3648 if (image->storage_class != DirectClass)
3649 status=SetImageStorageClass(image,DirectClass,exception);
3650 if (image->matte == MagickFalse)
3651 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3659 image_info=DestroyImageInfo(image_info);
3664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3668 % 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 %
3672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3674 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3675 % image and returns the previous setting. A virtual pixel is any pixel access
3676 % that is outside the boundaries of the image cache.
3678 % The format of the SetImageVirtualPixelMethod() method is:
3680 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3681 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3683 % A description of each parameter follows:
3685 % o image: the image.
3687 % o virtual_pixel_method: choose the type of virtual pixel.
3689 % o exception: return any errors or warnings in this structure.
3692 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3693 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3695 assert(image != (const Image *) NULL);
3696 assert(image->signature == MagickSignature);
3697 if (image->debug != MagickFalse)
3698 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3699 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3707 % S m u s h I m a g e s %
3711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3713 % SmushImages() takes all images from the current image pointer to the end
3714 % of the image list and smushes them to each other top-to-bottom if the
3715 % stack parameter is true, otherwise left-to-right.
3717 % The current gravity setting now effects how the image is justified in the
3720 % The format of the SmushImages method is:
3722 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3723 % ExceptionInfo *exception)
3725 % A description of each parameter follows:
3727 % o images: the image sequence.
3729 % o stack: A value other than 0 stacks the images top-to-bottom.
3731 % o offset: minimum distance in pixels between images.
3733 % o exception: return any errors or warnings in this structure.
3737 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3738 const ssize_t offset,ExceptionInfo *exception)
3752 register const Quantum
3765 if (images->previous == (Image *) NULL)
3768 SetGeometry(smush_image,&right_geometry);
3769 GravityAdjustGeometry(right_image->columns,right_image->rows,
3770 right_image->gravity,&right_geometry);
3771 left_image=images->previous;
3772 SetGeometry(smush_image,&left_geometry);
3773 GravityAdjustGeometry(left_image->columns,left_image->rows,
3774 left_image->gravity,&left_geometry);
3775 gap=right_image->columns;
3776 left_view=AcquireCacheView(left_image);
3777 right_view=AcquireCacheView(right_image);
3778 for (y=0; y < (ssize_t) smush_image->rows; y++)
3780 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3782 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3783 if ((p == (const Quantum *) NULL) ||
3784 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3785 ((left_image->columns-x-1) >= gap))
3788 i=(ssize_t) left_image->columns-x-1;
3789 for (x=0; x < (ssize_t) right_image->columns; x++)
3791 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3793 if ((p == (const Quantum *) NULL) ||
3794 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3795 ((x+i) >= (ssize_t) gap))
3798 if ((x+i) < (ssize_t) gap)
3801 right_view=DestroyCacheView(right_view);
3802 left_view=DestroyCacheView(left_view);
3803 if (y < (ssize_t) smush_image->rows)
3805 return((ssize_t) gap-offset);
3808 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3809 const ssize_t offset,ExceptionInfo *exception)
3823 register const Quantum
3836 if (images->previous == (Image *) NULL)
3838 bottom_image=images;
3839 SetGeometry(smush_image,&bottom_geometry);
3840 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3841 bottom_image->gravity,&bottom_geometry);
3842 top_image=images->previous;
3843 SetGeometry(smush_image,&top_geometry);
3844 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3846 gap=bottom_image->rows;
3847 top_view=AcquireCacheView(top_image);
3848 bottom_view=AcquireCacheView(bottom_image);
3849 for (x=0; x < (ssize_t) smush_image->columns; x++)
3851 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3853 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3854 if ((p == (const Quantum *) NULL) ||
3855 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3856 ((top_image->rows-y-1) >= gap))
3859 i=(ssize_t) top_image->rows-y-1;
3860 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3862 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3864 if ((p == (const Quantum *) NULL) ||
3865 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3866 ((y+i) >= (ssize_t) gap))
3869 if ((y+i) < (ssize_t) gap)
3872 bottom_view=DestroyCacheView(bottom_view);
3873 top_view=DestroyCacheView(top_view);
3874 if (x < (ssize_t) smush_image->columns)
3876 return((ssize_t) gap-offset);
3879 MagickExport Image *SmushImages(const Image *images,
3880 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3882 #define SmushImageTag "Smush/Image"
3904 register const Image
3917 Compute maximum area of smushed area.
3919 assert(images != (Image *) NULL);
3920 assert(images->signature == MagickSignature);
3921 if (images->debug != MagickFalse)
3922 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3923 assert(exception != (ExceptionInfo *) NULL);
3924 assert(exception->signature == MagickSignature);
3928 width=image->columns;
3930 next=GetNextImageInList(image);
3931 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3933 if (next->matte != MagickFalse)
3936 if (stack != MagickFalse)
3938 if (next->columns > width)
3939 width=next->columns;
3941 if (next->previous != (Image *) NULL)
3945 width+=next->columns;
3946 if (next->previous != (Image *) NULL)
3948 if (next->rows > height)
3954 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3955 if (smush_image == (Image *) NULL)
3956 return((Image *) NULL);
3957 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3959 smush_image=DestroyImage(smush_image);
3960 return((Image *) NULL);
3962 smush_image->matte=matte;
3963 (void) SetImageBackgroundColor(smush_image,exception);
3967 smush_view=AcquireCacheView(smush_image);
3968 for (n=0; n < (MagickOffsetType) number_images; n++)
3970 SetGeometry(smush_image,&geometry);
3971 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3972 if (stack != MagickFalse)
3974 x_offset-=geometry.x;
3975 y_offset-=SmushYGap(smush_image,image,offset,exception);
3979 x_offset-=SmushXGap(smush_image,image,offset,exception);
3980 y_offset-=geometry.y;
3982 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
3984 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3985 if (proceed == MagickFalse)
3987 if (stack == MagickFalse)
3989 x_offset+=(ssize_t) image->columns;
3995 y_offset+=(ssize_t) image->rows;
3997 image=GetNextImageInList(image);
3999 if (stack == MagickFalse)
4000 smush_image->columns=(size_t) x_offset;
4002 smush_image->rows=(size_t) y_offset;
4003 smush_view=DestroyCacheView(smush_view);
4004 if (status == MagickFalse)
4005 smush_image=DestroyImage(smush_image);
4006 return(smush_image);
4010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4014 % S t r i p I m a g e %
4018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4020 % StripImage() strips an image of all profiles and comments.
4022 % The format of the StripImage method is:
4024 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
4026 % A description of each parameter follows:
4028 % o image: the image.
4030 % o exception: return any errors or warnings in this structure.
4033 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
4038 assert(image != (Image *) NULL);
4039 if (image->debug != MagickFalse)
4040 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4042 DestroyImageProfiles(image);
4043 (void) DeleteImageProperty(image,"comment");
4044 (void) DeleteImageProperty(image,"date:create");
4045 (void) DeleteImageProperty(image,"date:modify");
4046 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4055 + S y n c I m a g e %
4059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4061 % SyncImage() initializes the red, green, and blue intensities of each pixel
4062 % as defined by the colormap index.
4064 % The format of the SyncImage method is:
4066 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4068 % A description of each parameter follows:
4070 % o image: the image.
4072 % o exception: return any errors or warnings in this structure.
4076 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
4077 MagickBooleanType *range_exception)
4079 if ((size_t) index < image->colors)
4081 *range_exception=MagickTrue;
4085 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4097 assert(image != (Image *) NULL);
4098 if (image->debug != MagickFalse)
4099 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4100 assert(image->signature == MagickSignature);
4101 if (image->storage_class == DirectClass)
4102 return(MagickFalse);
4103 range_exception=MagickFalse;
4105 image_view=AcquireCacheView(image);
4106 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4107 #pragma omp parallel for schedule(static,4) shared(range_exception,status)
4109 for (y=0; y < (ssize_t) image->rows; y++)
4120 if (status == MagickFalse)
4122 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4123 if (q == (Quantum *) NULL)
4128 for (x=0; x < (ssize_t) image->columns; x++)
4130 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4131 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
4132 q+=GetPixelChannels(image);
4134 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4137 image_view=DestroyCacheView(image_view);
4138 if (range_exception != MagickFalse)
4139 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
4140 "InvalidColormapIndex","`%s'",image->filename);
4145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4149 % S y n c I m a g e S e t t i n g s %
4153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4155 % SyncImageSettings() syncs the image_info options into per-image attributes.
4157 % The format of the SyncImageSettings method is:
4159 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4160 % Image *image,ExceptionInfo *exception)
4161 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4162 % Image *image,ExceptionInfo *exception)
4164 % A description of each parameter follows:
4166 % o image_info: the image info.
4168 % o image: the image.
4170 % o exception: return any errors or warnings in this structure.
4174 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4175 Image *images,ExceptionInfo *exception)
4180 assert(image_info != (const ImageInfo *) NULL);
4181 assert(image_info->signature == MagickSignature);
4182 assert(images != (Image *) NULL);
4183 assert(images->signature == MagickSignature);
4184 if (images->debug != MagickFalse)
4185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4187 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4188 (void) SyncImageSettings(image_info,image,exception);
4189 (void) DeleteImageOption(image_info,"page");
4193 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4194 Image *image,ExceptionInfo *exception)
4197 property[MaxTextExtent];
4215 assert(image_info != (const ImageInfo *) NULL);
4216 assert(image_info->signature == MagickSignature);
4217 assert(image != (Image *) NULL);
4218 assert(image->signature == MagickSignature);
4219 if (image->debug != MagickFalse)
4220 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4221 option=GetImageOption(image_info,"background");
4222 if (option != (const char *) NULL)
4223 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4225 option=GetImageOption(image_info,"bias");
4226 if (option != (const char *) NULL)
4227 image->bias=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4228 option=GetImageOption(image_info,"black-point-compensation");
4229 if (option != (const char *) NULL)
4230 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4231 MagickBooleanOptions,MagickFalse,option);
4232 option=GetImageOption(image_info,"blue-primary");
4233 if (option != (const char *) NULL)
4235 flags=ParseGeometry(option,&geometry_info);
4236 image->chromaticity.blue_primary.x=geometry_info.rho;
4237 image->chromaticity.blue_primary.y=geometry_info.sigma;
4238 if ((flags & SigmaValue) == 0)
4239 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4241 option=GetImageOption(image_info,"bordercolor");
4242 if (option != (const char *) NULL)
4243 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4245 /* FUTURE: do not sync compose to per-image compose setting here */
4246 option=GetImageOption(image_info,"compose");
4247 if (option != (const char *) NULL)
4248 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4249 MagickFalse,option);
4251 option=GetImageOption(image_info,"compress");
4252 if (option != (const char *) NULL)
4253 image->compression=(CompressionType) ParseCommandOption(
4254 MagickCompressOptions,MagickFalse,option);
4255 option=GetImageOption(image_info,"debug");
4256 if (option != (const char *) NULL)
4257 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4258 MagickFalse,option);
4259 option=GetImageOption(image_info,"density");
4260 if (option != (const char *) NULL)
4265 flags=ParseGeometry(option,&geometry_info);
4266 image->resolution.x=geometry_info.rho;
4267 image->resolution.y=geometry_info.sigma;
4268 if ((flags & SigmaValue) == 0)
4269 image->resolution.y=image->resolution.x;
4271 option=GetImageOption(image_info,"depth");
4272 if (option != (const char *) NULL)
4273 image->depth=StringToUnsignedLong(option);
4274 option=GetImageOption(image_info,"endian");
4275 if (option != (const char *) NULL)
4276 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4277 MagickFalse,option);
4278 option=GetImageOption(image_info,"filter");
4279 if (option != (const char *) NULL)
4280 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4281 MagickFalse,option);
4282 option=GetImageOption(image_info,"fuzz");
4283 if (option != (const char *) NULL)
4284 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4285 option=GetImageOption(image_info,"gravity");
4286 if (option != (const char *) NULL)
4287 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4288 MagickFalse,option);
4289 option=GetImageOption(image_info,"green-primary");
4290 if (option != (const char *) NULL)
4292 flags=ParseGeometry(option,&geometry_info);
4293 image->chromaticity.green_primary.x=geometry_info.rho;
4294 image->chromaticity.green_primary.y=geometry_info.sigma;
4295 if ((flags & SigmaValue) == 0)
4296 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4298 option=GetImageOption(image_info,"intent");
4299 if (option != (const char *) NULL)
4300 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4301 MagickIntentOptions,MagickFalse,option);
4302 option=GetImageOption(image_info,"interlace");
4303 if (option != (const char *) NULL)
4304 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4305 MagickFalse,option);
4306 option=GetImageOption(image_info,"interpolate");
4307 if (option != (const char *) NULL)
4308 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4309 MagickInterpolateOptions,MagickFalse,option);
4310 option=GetImageOption(image_info,"loop");
4311 if (option != (const char *) NULL)
4312 image->iterations=StringToUnsignedLong(option);
4313 option=GetImageOption(image_info,"mattecolor");
4314 if (option != (const char *) NULL)
4315 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4317 option=GetImageOption(image_info,"orient");
4318 if (option != (const char *) NULL)
4319 image->orientation=(OrientationType) ParseCommandOption(
4320 MagickOrientationOptions,MagickFalse,option);
4321 option=GetImageOption(image_info,"page");
4322 if (option != (const char *) NULL)
4327 geometry=GetPageGeometry(option);
4328 flags=ParseAbsoluteGeometry(geometry,&image->page);
4329 geometry=DestroyString(geometry);
4331 option=GetImageOption(image_info,"quality");
4332 if (option != (const char *) NULL)
4333 image->quality=StringToUnsignedLong(option);
4334 option=GetImageOption(image_info,"red-primary");
4335 if (option != (const char *) NULL)
4337 flags=ParseGeometry(option,&geometry_info);
4338 image->chromaticity.red_primary.x=geometry_info.rho;
4339 image->chromaticity.red_primary.y=geometry_info.sigma;
4340 if ((flags & SigmaValue) == 0)
4341 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4343 if (image_info->quality != UndefinedCompressionQuality)
4344 image->quality=image_info->quality;
4345 option=GetImageOption(image_info,"scene");
4346 if (option != (const char *) NULL)
4347 image->scene=StringToUnsignedLong(option);
4348 option=GetImageOption(image_info,"taint");
4349 if (option != (const char *) NULL)
4350 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4351 MagickFalse,option);
4352 option=GetImageOption(image_info,"tile-offset");
4353 if (option != (const char *) NULL)
4358 geometry=GetPageGeometry(option);
4359 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4360 geometry=DestroyString(geometry);
4362 option=GetImageOption(image_info,"transparent-color");
4363 if (option != (const char *) NULL)
4364 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4366 option=GetImageOption(image_info,"type");
4367 if (option != (const char *) NULL)
4368 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4370 option=GetImageOption(image_info,"units");
4371 units=image_info->units;
4372 if (option != (const char *) NULL)
4373 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4374 MagickFalse,option);
4375 if (units != UndefinedResolution)
4377 if (image->units != units)
4378 switch (image->units)
4380 case PixelsPerInchResolution:
4382 if (units == PixelsPerCentimeterResolution)
4384 image->resolution.x/=2.54;
4385 image->resolution.y/=2.54;
4389 case PixelsPerCentimeterResolution:
4391 if (units == PixelsPerInchResolution)
4393 image->resolution.x=(double) ((size_t) (100.0*2.54*
4394 image->resolution.x+0.5))/100.0;
4395 image->resolution.y=(double) ((size_t) (100.0*2.54*
4396 image->resolution.y+0.5))/100.0;
4405 option=GetImageOption(image_info,"virtual-pixel");
4406 if (option != (const char *) NULL)
4407 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4408 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4410 option=GetImageOption(image_info,"white-point");
4411 if (option != (const char *) NULL)
4413 flags=ParseGeometry(option,&geometry_info);
4414 image->chromaticity.white_point.x=geometry_info.rho;
4415 image->chromaticity.white_point.y=geometry_info.sigma;
4416 if ((flags & SigmaValue) == 0)
4417 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4419 ResetImageOptionIterator(image_info);
4420 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4422 value=GetImageOption(image_info,option);
4423 if (value != (const char *) NULL)
4425 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4426 (void) SetImageArtifact(image,property,value);
4428 option=GetNextImageOption(image_info);