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->rendering_intent=PerceptualIntent;
177 image->gamma=0.45455;
178 image->chromaticity.red_primary.x=0.6400;
179 image->chromaticity.red_primary.y=0.3300;
180 image->chromaticity.green_primary.x=0.3000;
181 image->chromaticity.green_primary.y=0.6000;
182 image->chromaticity.blue_primary.x=0.1500;
183 image->chromaticity.blue_primary.y=0.0600;
184 image->chromaticity.white_point.x=0.3127;
185 image->chromaticity.white_point.y=0.3290;
186 image->interlace=NoInterlace;
187 image->ticks_per_second=UndefinedTicksPerSecond;
188 image->compose=OverCompositeOp;
190 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
191 &image->background_color,exception);
192 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
194 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
196 (void) QueryColorCompliance(TransparentColor,AllCompliance,
197 &image->transparent_color,exception);
198 image->resolution.x=DefaultResolution;
199 image->resolution.y=DefaultResolution;
200 image->units=PixelsPerInchResolution;
201 GetTimerInfo(&image->timer);
202 image->cache=AcquirePixelCache(0);
203 image->channel_mask=DefaultChannels;
204 image->channel_map=AcquirePixelChannelMap();
205 image->blob=CloneBlobInfo((BlobInfo *) NULL);
206 image->debug=IsEventLogging();
207 image->reference_count=1;
208 image->semaphore=AllocateSemaphoreInfo();
209 image->signature=MagickSignature;
210 if (image_info == (ImageInfo *) NULL)
215 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
217 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
218 (void) CopyMagickString(image->magick_filename,image_info->filename,
220 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
221 if (image_info->size != (char *) NULL)
223 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
224 image->columns=image->extract_info.width;
225 image->rows=image->extract_info.height;
226 image->offset=image->extract_info.x;
227 image->extract_info.x=0;
228 image->extract_info.y=0;
230 if (image_info->extract != (char *) NULL)
235 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
236 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
238 image->extract_info=geometry;
239 Swap(image->columns,image->extract_info.width);
240 Swap(image->rows,image->extract_info.height);
243 image->compression=image_info->compression;
244 image->quality=image_info->quality;
245 image->endian=image_info->endian;
246 image->interlace=image_info->interlace;
247 image->units=image_info->units;
248 if (image_info->density != (char *) NULL)
253 flags=ParseGeometry(image_info->density,&geometry_info);
254 image->resolution.x=geometry_info.rho;
255 image->resolution.y=geometry_info.sigma;
256 if ((flags & SigmaValue) == 0)
257 image->resolution.y=image->resolution.x;
259 if (image_info->page != (char *) NULL)
264 image->page=image->extract_info;
265 geometry=GetPageGeometry(image_info->page);
266 (void) ParseAbsoluteGeometry(geometry,&image->page);
267 geometry=DestroyString(geometry);
269 if (image_info->depth != 0)
270 image->depth=image_info->depth;
271 image->dither=image_info->dither;
272 image->background_color=image_info->background_color;
273 image->border_color=image_info->border_color;
274 image->matte_color=image_info->matte_color;
275 image->transparent_color=image_info->transparent_color;
276 image->ping=image_info->ping;
277 image->progress_monitor=image_info->progress_monitor;
278 image->client_data=image_info->client_data;
279 if (image_info->cache != (void *) NULL)
280 ClonePixelCacheMethods(image->cache,image_info->cache);
281 (void) SyncImageSettings(image_info,image,exception);
282 option=GetImageOption(image_info,"delay");
283 if (option != (const char *) NULL)
288 flags=ParseGeometry(option,&geometry_info);
289 if ((flags & GreaterValue) != 0)
291 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
292 image->delay=(size_t) floor(geometry_info.rho+0.5);
295 if ((flags & LessValue) != 0)
297 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
298 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
301 image->delay=(size_t) floor(geometry_info.rho+0.5);
302 if ((flags & SigmaValue) != 0)
303 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
305 option=GetImageOption(image_info,"dispose");
306 if (option != (const char *) NULL)
307 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 % A c q u i r e I m a g e I n f o %
321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 % AcquireImageInfo() allocates the ImageInfo structure.
325 % The format of the AcquireImageInfo method is:
327 % ImageInfo *AcquireImageInfo(void)
330 MagickExport ImageInfo *AcquireImageInfo(void)
335 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
336 if (image_info == (ImageInfo *) NULL)
337 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
338 GetImageInfo(image_info);
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 % A c q u i r e N e x t I m a g e %
351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 % AcquireNextImage() initializes the next image in a sequence to
354 % default values. The next member of image points to the newly allocated
355 % image. If there is a memory shortage, next is assigned NULL.
357 % The format of the AcquireNextImage method is:
359 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
360 % ExceptionInfo *exception)
362 % A description of each parameter follows:
364 % o image_info: Many of the image default values are set from this
365 % structure. For example, filename, compression, depth, background color,
368 % o image: the image.
370 % o exception: return any errors or warnings in this structure.
373 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
374 ExceptionInfo *exception)
377 Allocate image structure.
379 assert(image != (Image *) NULL);
380 assert(image->signature == MagickSignature);
381 if (image->debug != MagickFalse)
382 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
383 image->next=AcquireImage(image_info,exception);
384 if (GetNextImageInList(image) == (Image *) NULL)
386 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
388 if (image_info != (ImageInfo *) NULL)
389 (void) CopyMagickString(GetNextImageInList(image)->filename,
390 image_info->filename,MaxTextExtent);
391 DestroyBlob(GetNextImageInList(image));
392 image->next->blob=ReferenceBlob(image->blob);
393 image->next->endian=image->endian;
394 image->next->scene=image->scene+1;
395 image->next->previous=image;
399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403 % A p p e n d I m a g e s %
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 % AppendImages() takes all images from the current image pointer to the end
410 % of the image list and appends them to each other top-to-bottom if the
411 % stack parameter is true, otherwise left-to-right.
413 % The current gravity setting now effects how the image is justified in the
416 % The format of the AppendImages method is:
418 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
419 % ExceptionInfo *exception)
421 % A description of each parameter follows:
423 % o images: the image sequence.
425 % o stack: A value other than 0 stacks the images top-to-bottom.
427 % o exception: return any errors or warnings in this structure.
430 MagickExport Image *AppendImages(const Image *images,
431 const MagickBooleanType stack,ExceptionInfo *exception)
433 #define AppendImageTag "Append/Image"
470 Compute maximum area of appended area.
472 assert(images != (Image *) NULL);
473 assert(images->signature == MagickSignature);
474 if (images->debug != MagickFalse)
475 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
476 assert(exception != (ExceptionInfo *) NULL);
477 assert(exception->signature == MagickSignature);
481 width=image->columns;
483 next=GetNextImageInList(image);
484 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
486 if (next->matte != MagickFalse)
489 if (stack != MagickFalse)
491 if (next->columns > width)
496 width+=next->columns;
497 if (next->rows > height)
503 append_image=CloneImage(image,width,height,MagickTrue,exception);
504 if (append_image == (Image *) NULL)
505 return((Image *) NULL);
506 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
508 append_image=DestroyImage(append_image);
509 return((Image *) NULL);
511 append_image->matte=matte;
512 (void) SetImageBackgroundColor(append_image,exception);
516 append_view=AcquireCacheView(append_image);
517 for (n=0; n < (MagickOffsetType) number_images; n++)
519 SetGeometry(append_image,&geometry);
520 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
521 if (stack != MagickFalse)
522 x_offset-=geometry.x;
524 y_offset-=geometry.y;
525 image_view=AcquireCacheView(image);
526 #if defined(MAGICKCORE_OPENMP_SUPPORT)
527 #pragma omp parallel for schedule(static) shared(status)
529 for (y=0; y < (ssize_t) image->rows; y++)
534 register const Quantum
543 if (status == MagickFalse)
545 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
546 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
547 image->columns,1,exception);
548 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
553 for (x=0; x < (ssize_t) image->columns; x++)
558 if (GetPixelMask(image,p) != 0)
560 p+=GetPixelChannels(image);
561 q+=GetPixelChannels(append_image);
564 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
573 channel=GetPixelChannelMapChannel(image,i);
574 traits=GetPixelChannelMapTraits(image,channel);
575 append_traits=GetPixelChannelMapTraits(append_image,channel);
576 if ((traits == UndefinedPixelTrait) ||
577 (append_traits == UndefinedPixelTrait))
579 SetPixelChannel(append_image,channel,p[i],q);
581 p+=GetPixelChannels(image);
582 q+=GetPixelChannels(append_image);
584 sync=SyncCacheViewAuthenticPixels(append_view,exception);
585 if (sync == MagickFalse)
588 image_view=DestroyCacheView(image_view);
589 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
590 if (proceed == MagickFalse)
592 if (stack == MagickFalse)
594 x_offset+=(ssize_t) image->columns;
600 y_offset+=(ssize_t) image->rows;
602 image=GetNextImageInList(image);
604 append_view=DestroyCacheView(append_view);
605 if (status == MagickFalse)
606 append_image=DestroyImage(append_image);
607 return(append_image);
611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
615 % C a t c h I m a g e E x c e p t i o n %
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621 % CatchImageException() returns if no exceptions are found in the image
622 % sequence, otherwise it determines the most severe exception and reports
623 % it as a warning or error depending on the severity.
625 % The format of the CatchImageException method is:
627 % ExceptionType CatchImageException(Image *image)
629 % A description of each parameter follows:
631 % o image: An image sequence.
634 MagickExport ExceptionType CatchImageException(Image *image)
642 assert(image != (const Image *) NULL);
643 assert(image->signature == MagickSignature);
644 if (image->debug != MagickFalse)
645 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
646 exception=AcquireExceptionInfo();
647 CatchException(exception);
648 severity=exception->severity;
649 exception=DestroyExceptionInfo(exception);
654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
658 % C l i p I m a g e P a t h %
662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 % ClipImagePath() sets the image clip mask based any clipping path information
667 % The format of the ClipImagePath method is:
669 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
670 % const MagickBooleanType inside,ExceptionInfo *exception)
672 % A description of each parameter follows:
674 % o image: the image.
676 % o pathname: name of clipping path resource. If name is preceded by #, use
677 % clipping path numbered by name.
679 % o inside: if non-zero, later operations take effect inside clipping path.
680 % Otherwise later operations take effect outside clipping path.
682 % o exception: return any errors or warnings in this structure.
686 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
688 return(ClipImagePath(image,"#1",MagickTrue,exception));
691 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
692 const MagickBooleanType inside,ExceptionInfo *exception)
694 #define ClipImagePathTag "ClipPath/Image"
708 assert(image != (const Image *) NULL);
709 assert(image->signature == MagickSignature);
710 if (image->debug != MagickFalse)
711 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
712 assert(pathname != NULL);
713 property=AcquireString(pathname);
714 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
716 value=GetImageProperty(image,property,exception);
717 property=DestroyString(property);
718 if (value == (const char *) NULL)
720 ThrowFileException(exception,OptionError,"NoClipPathDefined",
724 image_info=AcquireImageInfo();
725 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
726 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
727 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
728 image_info=DestroyImageInfo(image_info);
729 if (clip_mask == (Image *) NULL)
731 if (clip_mask->storage_class == PseudoClass)
733 (void) SyncImage(clip_mask,exception);
734 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
737 if (inside == MagickFalse)
738 (void) NegateImage(clip_mask,MagickFalse,exception);
739 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
740 "8BIM:1999,2998:%s\nPS",pathname);
741 (void) SetImageMask(image,clip_mask,exception);
742 clip_mask=DestroyImage(clip_mask);
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 % C l o n e I m a g e %
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 % CloneImage() copies an image and returns the copy as a new image object.
759 % If the specified columns and rows is 0, an exact copy of the image is
760 % returned, otherwise the pixel data is undefined and must be initialized
761 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
762 % failure, a NULL image is returned and exception describes the reason for the
765 % The format of the CloneImage method is:
767 % Image *CloneImage(const Image *image,const size_t columns,
768 % const size_t rows,const MagickBooleanType orphan,
769 % ExceptionInfo *exception)
771 % A description of each parameter follows:
773 % o image: the image.
775 % o columns: the number of columns in the cloned image.
777 % o rows: the number of rows in the cloned image.
779 % o detach: With a value other than 0, the cloned image is detached from
780 % its parent I/O stream.
782 % o exception: return any errors or warnings in this structure.
785 MagickExport Image *CloneImage(const Image *image,const size_t columns,
786 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
800 assert(image != (const Image *) NULL);
801 assert(image->signature == MagickSignature);
802 if (image->debug != MagickFalse)
803 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
804 assert(exception != (ExceptionInfo *) NULL);
805 assert(exception->signature == MagickSignature);
806 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
807 if (clone_image == (Image *) NULL)
808 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
809 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
810 clone_image->signature=MagickSignature;
811 clone_image->storage_class=image->storage_class;
812 clone_image->number_channels=image->number_channels;
813 clone_image->number_meta_channels=image->number_meta_channels;
814 clone_image->metacontent_extent=image->metacontent_extent;
815 clone_image->colorspace=image->colorspace;
816 clone_image->mask=image->mask;
817 clone_image->matte=image->matte;
818 clone_image->columns=image->columns;
819 clone_image->rows=image->rows;
820 clone_image->dither=image->dither;
821 if (image->colormap != (PixelInfo *) NULL)
824 Allocate and copy the image colormap.
826 clone_image->colors=image->colors;
827 length=(size_t) image->colors;
828 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
829 sizeof(*clone_image->colormap));
830 if (clone_image->colormap == (PixelInfo *) NULL)
831 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
832 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
833 sizeof(*clone_image->colormap));
835 (void) CloneImageProfiles(clone_image,image);
836 (void) CloneImageProperties(clone_image,image);
837 (void) CloneImageArtifacts(clone_image,image);
838 GetTimerInfo(&clone_image->timer);
839 if (image->ascii85 != (void *) NULL)
840 Ascii85Initialize(clone_image);
841 clone_image->magick_columns=image->magick_columns;
842 clone_image->magick_rows=image->magick_rows;
843 clone_image->type=image->type;
844 clone_image->channel_mask=image->channel_mask;
845 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
846 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
848 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
849 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
850 clone_image->progress_monitor=image->progress_monitor;
851 clone_image->client_data=image->client_data;
852 clone_image->reference_count=1;
853 clone_image->next=image->next;
854 clone_image->previous=image->previous;
855 clone_image->list=NewImageList();
856 if (detach == MagickFalse)
857 clone_image->blob=ReferenceBlob(image->blob);
860 clone_image->next=NewImageList();
861 clone_image->previous=NewImageList();
862 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
864 clone_image->ping=image->ping;
865 clone_image->debug=IsEventLogging();
866 clone_image->semaphore=AllocateSemaphoreInfo();
867 if ((columns == 0) && (rows == 0))
869 if (image->montage != (char *) NULL)
870 (void) CloneString(&clone_image->montage,image->montage);
871 if (image->directory != (char *) NULL)
872 (void) CloneString(&clone_image->directory,image->directory);
873 clone_image->cache=ReferencePixelCache(image->cache);
876 scale=(MagickRealType) columns/(MagickRealType) image->columns;
877 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
878 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
879 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
880 scale=(MagickRealType) rows/(MagickRealType) image->rows;
881 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
882 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
883 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
884 clone_image->columns=columns;
885 clone_image->rows=rows;
886 clone_image->cache=ClonePixelCache(image->cache);
891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895 % C l o n e I m a g e I n f o %
899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
901 % CloneImageInfo() makes a copy of the given image info structure. If
902 % NULL is specified, a new image info structure is created initialized to
905 % The format of the CloneImageInfo method is:
907 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
909 % A description of each parameter follows:
911 % o image_info: the image info.
914 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
919 clone_info=AcquireImageInfo();
920 if (image_info == (ImageInfo *) NULL)
922 clone_info->compression=image_info->compression;
923 clone_info->temporary=image_info->temporary;
924 clone_info->adjoin=image_info->adjoin;
925 clone_info->antialias=image_info->antialias;
926 clone_info->scene=image_info->scene;
927 clone_info->number_scenes=image_info->number_scenes;
928 clone_info->depth=image_info->depth;
929 (void) CloneString(&clone_info->size,image_info->size);
930 (void) CloneString(&clone_info->extract,image_info->extract);
931 (void) CloneString(&clone_info->scenes,image_info->scenes);
932 (void) CloneString(&clone_info->page,image_info->page);
933 clone_info->interlace=image_info->interlace;
934 clone_info->endian=image_info->endian;
935 clone_info->units=image_info->units;
936 clone_info->quality=image_info->quality;
937 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
938 (void) CloneString(&clone_info->server_name,image_info->server_name);
939 (void) CloneString(&clone_info->font,image_info->font);
940 (void) CloneString(&clone_info->texture,image_info->texture);
941 (void) CloneString(&clone_info->density,image_info->density);
942 clone_info->pointsize=image_info->pointsize;
943 clone_info->fuzz=image_info->fuzz;
944 clone_info->background_color=image_info->background_color;
945 clone_info->border_color=image_info->border_color;
946 clone_info->matte_color=image_info->matte_color;
947 clone_info->transparent_color=image_info->transparent_color;
948 clone_info->dither=image_info->dither;
949 clone_info->monochrome=image_info->monochrome;
950 clone_info->colorspace=image_info->colorspace;
951 clone_info->type=image_info->type;
952 clone_info->orientation=image_info->orientation;
953 clone_info->preview_type=image_info->preview_type;
954 clone_info->group=image_info->group;
955 clone_info->ping=image_info->ping;
956 clone_info->verbose=image_info->verbose;
957 (void) CloneString(&clone_info->view,image_info->view);
958 clone_info->progress_monitor=image_info->progress_monitor;
959 clone_info->client_data=image_info->client_data;
960 clone_info->cache=image_info->cache;
961 if (image_info->cache != (void *) NULL)
962 clone_info->cache=ReferencePixelCache(image_info->cache);
963 if (image_info->profile != (void *) NULL)
964 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
965 image_info->profile);
966 SetImageInfoFile(clone_info,image_info->file);
967 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
968 clone_info->stream=image_info->stream;
969 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
970 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
971 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
972 (void) CopyMagickString(clone_info->filename,image_info->filename,
974 clone_info->channel=image_info->channel;
975 (void) CloneImageOptions(clone_info,image_info);
976 clone_info->debug=IsEventLogging();
977 clone_info->signature=image_info->signature;
982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
986 % C o m b i n e I m a g e s %
990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 % CombineImages() combines one or more images into a single image. The
993 % grayscale value of the pixels of each image in the sequence is assigned in
994 % order to the specified channels of the combined image. The typical
995 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
997 % The format of the CombineImages method is:
999 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
1001 % A description of each parameter follows:
1003 % o image: the image.
1005 % o exception: return any errors or warnings in this structure.
1009 static inline size_t MagickMin(const size_t x,const size_t y)
1016 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1018 #define CombineImageTag "Combine/Image"
1036 Ensure the image are the same size.
1038 assert(image != (const Image *) NULL);
1039 assert(image->signature == MagickSignature);
1040 if (image->debug != MagickFalse)
1041 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1042 assert(exception != (ExceptionInfo *) NULL);
1043 assert(exception->signature == MagickSignature);
1044 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1045 if (combine_image == (Image *) NULL)
1046 return((Image *) NULL);
1047 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1049 combine_image=DestroyImage(combine_image);
1050 return((Image *) NULL);
1052 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1053 combine_image->matte=MagickTrue;
1059 combine_view=AcquireCacheView(combine_image);
1060 for (y=0; y < (ssize_t) combine_image->rows; y++)
1071 register const Quantum
1080 if (status == MagickFalse)
1082 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1084 if (pixels == (Quantum *) NULL)
1090 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1102 if (next == (Image *) NULL)
1104 channel=GetPixelChannelMapChannel(image,i);
1105 traits=GetPixelChannelMapTraits(image,channel);
1106 combine_traits=GetPixelChannelMapTraits(combine_image,channel);
1107 if ((traits == UndefinedPixelTrait) ||
1108 (combine_traits == UndefinedPixelTrait))
1110 image_view=AcquireCacheView(next);
1111 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1112 if (p == (const Quantum *) NULL)
1115 for (x=0; x < (ssize_t) combine_image->columns; x++)
1117 if (x < (ssize_t) image->columns)
1119 q[i]=GetPixelGray(image,p);
1120 p+=GetPixelChannels(image);
1122 q+=GetPixelChannels(combine_image);
1124 image_view=DestroyCacheView(image_view);
1125 next=GetNextImageInList(next);
1126 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1128 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1133 proceed=SetImageProgress(image,CombineImageTag,progress++,
1134 combine_image->rows);
1135 if (proceed == MagickFalse)
1140 combine_view=DestroyCacheView(combine_view);
1141 if (status == MagickFalse)
1142 combine_image=DestroyImage(combine_image);
1143 return(combine_image);
1147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1151 % D e s t r o y I m a g e %
1155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 % DestroyImage() dereferences an image, deallocating memory associated with
1158 % the image if the reference count becomes zero.
1160 % The format of the DestroyImage method is:
1162 % Image *DestroyImage(Image *image)
1164 % A description of each parameter follows:
1166 % o image: the image.
1169 MagickExport Image *DestroyImage(Image *image)
1177 assert(image != (Image *) NULL);
1178 assert(image->signature == MagickSignature);
1179 if (image->debug != MagickFalse)
1180 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1181 destroy=MagickFalse;
1182 LockSemaphoreInfo(image->semaphore);
1183 image->reference_count--;
1184 if (image->reference_count == 0)
1186 UnlockSemaphoreInfo(image->semaphore);
1187 if (destroy == MagickFalse)
1188 return((Image *) NULL);
1192 DestroyImagePixels(image);
1193 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1194 if (image->montage != (char *) NULL)
1195 image->montage=DestroyString(image->montage);
1196 if (image->directory != (char *) NULL)
1197 image->directory=DestroyString(image->directory);
1198 if (image->colormap != (PixelInfo *) NULL)
1199 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1200 if (image->geometry != (char *) NULL)
1201 image->geometry=DestroyString(image->geometry);
1202 DestroyImageProfiles(image);
1203 DestroyImageProperties(image);
1204 DestroyImageArtifacts(image);
1205 if (image->ascii85 != (Ascii85Info*) NULL)
1206 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1208 if (image->semaphore != (SemaphoreInfo *) NULL)
1209 DestroySemaphoreInfo(&image->semaphore);
1210 image->signature=(~MagickSignature);
1211 image=(Image *) RelinquishMagickMemory(image);
1216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1220 % D e s t r o y I m a g e I n f o %
1224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1226 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1229 % The format of the DestroyImageInfo method is:
1231 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1233 % A description of each parameter follows:
1235 % o image_info: the image info.
1238 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1240 assert(image_info != (ImageInfo *) NULL);
1241 assert(image_info->signature == MagickSignature);
1242 if (image_info->debug != MagickFalse)
1243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1244 image_info->filename);
1245 if (image_info->size != (char *) NULL)
1246 image_info->size=DestroyString(image_info->size);
1247 if (image_info->extract != (char *) NULL)
1248 image_info->extract=DestroyString(image_info->extract);
1249 if (image_info->scenes != (char *) NULL)
1250 image_info->scenes=DestroyString(image_info->scenes);
1251 if (image_info->page != (char *) NULL)
1252 image_info->page=DestroyString(image_info->page);
1253 if (image_info->sampling_factor != (char *) NULL)
1254 image_info->sampling_factor=DestroyString(
1255 image_info->sampling_factor);
1256 if (image_info->server_name != (char *) NULL)
1257 image_info->server_name=DestroyString(
1258 image_info->server_name);
1259 if (image_info->font != (char *) NULL)
1260 image_info->font=DestroyString(image_info->font);
1261 if (image_info->texture != (char *) NULL)
1262 image_info->texture=DestroyString(image_info->texture);
1263 if (image_info->density != (char *) NULL)
1264 image_info->density=DestroyString(image_info->density);
1265 if (image_info->view != (char *) NULL)
1266 image_info->view=DestroyString(image_info->view);
1267 if (image_info->cache != (void *) NULL)
1268 image_info->cache=DestroyPixelCache(image_info->cache);
1269 if (image_info->profile != (StringInfo *) NULL)
1270 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1271 image_info->profile);
1272 DestroyImageOptions(image_info);
1273 image_info->signature=(~MagickSignature);
1274 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283 + D i s a s s o c i a t e I m a g e S t r e a m %
1287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1289 % DisassociateImageStream() disassociates the image stream.
1291 % The format of the DisassociateImageStream method is:
1293 % MagickBooleanType DisassociateImageStream(const Image *image)
1295 % A description of each parameter follows:
1297 % o image: the image.
1300 MagickExport void DisassociateImageStream(Image *image)
1302 assert(image != (const Image *) NULL);
1303 assert(image->signature == MagickSignature);
1304 if (image->debug != MagickFalse)
1305 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1306 (void) DetachBlob(image->blob);
1310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1314 % G e t I m a g e A l p h a C h a n n e l %
1318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1320 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1321 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1324 % The format of the GetImageAlphaChannel method is:
1326 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1328 % A description of each parameter follows:
1330 % o image: the image.
1333 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1335 assert(image != (const Image *) NULL);
1336 if (image->debug != MagickFalse)
1337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1338 assert(image->signature == MagickSignature);
1339 return(image->matte);
1343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1347 % G e t I m a g e I n f o %
1351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1353 % GetImageInfo() initializes image_info to default values.
1355 % The format of the GetImageInfo method is:
1357 % void GetImageInfo(ImageInfo *image_info)
1359 % A description of each parameter follows:
1361 % o image_info: the image info.
1364 MagickExport void GetImageInfo(ImageInfo *image_info)
1373 File and image dimension members.
1375 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1376 assert(image_info != (ImageInfo *) NULL);
1377 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1378 image_info->adjoin=MagickTrue;
1379 image_info->interlace=NoInterlace;
1380 image_info->channel=DefaultChannels;
1381 image_info->quality=UndefinedCompressionQuality;
1382 image_info->antialias=MagickTrue;
1383 image_info->dither=MagickTrue;
1384 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1385 if (synchronize != (const char *) NULL)
1386 image_info->synchronize=IsMagickTrue(synchronize);
1387 exception=AcquireExceptionInfo();
1388 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1389 &image_info->background_color,exception);
1390 (void) QueryColorCompliance(BorderColor,AllCompliance,
1391 &image_info->border_color,exception);
1392 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1394 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1395 &image_info->transparent_color,exception);
1396 exception=DestroyExceptionInfo(exception);
1397 image_info->debug=IsEventLogging();
1398 image_info->signature=MagickSignature;
1402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1406 % G e t I m a g e I n f o F i l e %
1410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412 % GetImageInfoFile() returns the image info file member.
1414 % The format of the GetImageInfoFile method is:
1416 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1418 % A description of each parameter follows:
1420 % o image_info: the image info.
1423 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1425 return(image_info->file);
1429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1433 % G e t I m a g e M a s k %
1437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1439 % GetImageMask() returns the mask associated with the image.
1441 % The format of the GetImageMask method is:
1443 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1445 % A description of each parameter follows:
1447 % o image: the image.
1450 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1468 assert(image != (Image *) NULL);
1469 if (image->debug != MagickFalse)
1470 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1471 assert(image->signature == MagickSignature);
1472 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1473 if (mask_image == (Image *) NULL)
1474 return((Image *) NULL);
1476 mask_image->colorspace=GRAYColorspace;
1477 mask_image->mask=MagickFalse;
1478 image_view=AcquireCacheView(image);
1479 mask_view=AcquireCacheView(mask_image);
1480 for (y=0; y < (ssize_t) image->rows; y++)
1482 register const Quantum
1491 if (status == MagickFalse)
1493 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1494 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1496 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1501 for (x=0; x < (ssize_t) image->columns; x++)
1503 SetPixelGray(mask_image,GetPixelMask(image,p),q);
1504 p+=GetPixelChannels(image);
1505 q+=GetPixelChannels(mask_image);
1507 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1510 mask_view=DestroyCacheView(mask_view);
1511 image_view=DestroyCacheView(image_view);
1516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1520 + G e t I m a g e R e f e r e n c e C o u n t %
1524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 % GetImageReferenceCount() returns the image reference count.
1528 % The format of the GetReferenceCount method is:
1530 % ssize_t GetImageReferenceCount(Image *image)
1532 % A description of each parameter follows:
1534 % o image: the image.
1537 MagickExport ssize_t GetImageReferenceCount(Image *image)
1542 assert(image != (Image *) NULL);
1543 assert(image->signature == MagickSignature);
1544 if (image->debug != MagickFalse)
1545 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1546 LockSemaphoreInfo(image->semaphore);
1547 reference_count=image->reference_count;
1548 UnlockSemaphoreInfo(image->semaphore);
1549 return(reference_count);
1553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1557 % 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 %
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1563 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1564 % image. A virtual pixel is any pixel access that is outside the boundaries
1565 % of the image cache.
1567 % The format of the GetImageVirtualPixelMethod() method is:
1569 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1571 % A description of each parameter follows:
1573 % o image: the image.
1576 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1578 assert(image != (Image *) NULL);
1579 assert(image->signature == MagickSignature);
1580 if (image->debug != MagickFalse)
1581 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1582 return(GetPixelCacheVirtualMethod(image));
1586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1590 % I n t e r p r e t I m a g e F i l e n a m e %
1594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1596 % InterpretImageFilename() interprets embedded characters in an image filename.
1597 % The filename length is returned.
1599 % The format of the InterpretImageFilename method is:
1601 % size_t InterpretImageFilename(const ImageInfo *image_info,
1602 % Image *image,const char *format,int value,char *filename,
1603 % ExceptionInfo *exception)
1605 % A description of each parameter follows.
1607 % o image_info: the image info..
1609 % o image: the image.
1611 % o format: A filename describing the format to use to write the numeric
1612 % argument. Only the first numeric format identifier is replaced.
1614 % o value: Numeric value to substitute into format filename.
1616 % o filename: return the formatted filename in this character buffer.
1618 % o exception: return any errors or warnings in this structure.
1621 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1622 Image *image,const char *format,int value,char *filename,
1623 ExceptionInfo *exception)
1640 canonical=MagickFalse;
1642 (void) CopyMagickString(filename,format,MaxTextExtent);
1643 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1656 value=(ssize_t) strtol(q,&q,10);
1668 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1669 (p-format)),p,value);
1671 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1672 canonical=MagickTrue;
1681 pattern[MaxTextExtent];
1698 if (strchr(p,']') == (char *) NULL)
1702 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1713 if (LocaleNCompare(pattern,"filename:",9) != 0)
1715 value=(const char *) NULL;
1716 if ((image_info != (const ImageInfo *) NULL) &&
1717 (image != (const Image *) NULL))
1718 value=GetMagickProperty(image_info,image,pattern,exception);
1720 if (image != (Image *) NULL)
1721 value=GetImageProperty(image,pattern,exception);
1723 if (image_info != (ImageInfo *) NULL)
1724 value=GetImageOption(image_info,pattern);
1725 if (value == (const char *) NULL)
1730 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1731 (MaxTextExtent-(p-format-length)));
1732 length+=strlen(pattern)-1;
1734 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1735 canonical=MagickTrue;
1745 for (q=filename; *q != '\0'; q++)
1746 if ((*q == '%') && (*(q+1) == '%'))
1748 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1749 canonical=MagickTrue;
1751 if (canonical == MagickFalse)
1752 (void) CopyMagickString(filename,format,MaxTextExtent);
1753 return(strlen(filename));
1757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1761 % I s H i g h D y n a m i c R a n g e I m a g e %
1765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1767 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1768 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1771 % The format of the IsHighDynamicRangeImage method is:
1773 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1774 % ExceptionInfo *exception)
1776 % A description of each parameter follows:
1778 % o image: the image.
1780 % o exception: return any errors or warnings in this structure.
1783 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1784 ExceptionInfo *exception)
1786 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1789 return(MagickFalse);
1800 assert(image != (Image *) NULL);
1801 assert(image->signature == MagickSignature);
1802 if (image->debug != MagickFalse)
1803 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1805 image_view=AcquireCacheView(image);
1806 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1807 #pragma omp parallel for schedule(static,4) shared(status)
1809 for (y=0; y < (ssize_t) image->rows; y++)
1811 register const Quantum
1817 if (status == MagickFalse)
1819 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1820 if (p == (const Quantum *) NULL)
1825 for (x=0; x < (ssize_t) image->columns; x++)
1833 if (GetPixelMask(image,p) != 0)
1835 p+=GetPixelChannels(image);
1838 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1843 traits=GetPixelChannelMapTraits(image,i);
1844 if (traits == UndefinedPixelTrait)
1846 pixel=(MagickRealType) p[i];
1847 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1848 (pixel != (QuantumAny) pixel))
1851 p+=GetPixelChannels(image);
1852 if (i < (ssize_t) GetPixelChannels(image))
1855 if (x < (ssize_t) image->columns)
1858 image_view=DestroyCacheView(image_view);
1859 return(status != MagickFalse ? MagickFalse : MagickTrue);
1864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1868 % I s I m a g e O b j e c t %
1872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1874 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1875 % set of image objects.
1877 % The format of the IsImageObject method is:
1879 % MagickBooleanType IsImageObject(const Image *image)
1881 % A description of each parameter follows:
1883 % o image: the image.
1886 MagickExport MagickBooleanType IsImageObject(const Image *image)
1888 register const Image
1891 assert(image != (Image *) NULL);
1892 if (image->debug != MagickFalse)
1893 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1894 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1895 if (p->signature != MagickSignature)
1896 return(MagickFalse);
1901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1905 % I s T a i n t I m a g e %
1909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1911 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1912 % since it was first constituted.
1914 % The format of the IsTaintImage method is:
1916 % MagickBooleanType IsTaintImage(const Image *image)
1918 % A description of each parameter follows:
1920 % o image: the image.
1923 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1926 magick[MaxTextExtent],
1927 filename[MaxTextExtent];
1929 register const Image
1932 assert(image != (Image *) NULL);
1933 if (image->debug != MagickFalse)
1934 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1935 assert(image->signature == MagickSignature);
1936 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1937 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1938 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1940 if (p->taint != MagickFalse)
1942 if (LocaleCompare(p->magick,magick) != 0)
1944 if (LocaleCompare(p->filename,filename) != 0)
1947 return(MagickFalse);
1951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1955 % M o d i f y I m a g e %
1959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1961 % ModifyImage() ensures that there is only a single reference to the image
1962 % to be modified, updating the provided image pointer to point to a clone of
1963 % the original image if necessary.
1965 % The format of the ModifyImage method is:
1967 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1969 % A description of each parameter follows:
1971 % o image: the image.
1973 % o exception: return any errors or warnings in this structure.
1976 MagickExport MagickBooleanType ModifyImage(Image **image,
1977 ExceptionInfo *exception)
1982 assert(image != (Image **) NULL);
1983 assert(*image != (Image *) NULL);
1984 assert((*image)->signature == MagickSignature);
1985 if ((*image)->debug != MagickFalse)
1986 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1987 if (GetImageReferenceCount(*image) <= 1)
1989 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1990 LockSemaphoreInfo((*image)->semaphore);
1991 (*image)->reference_count--;
1992 UnlockSemaphoreInfo((*image)->semaphore);
1998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002 % N e w M a g i c k I m a g e %
2006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2008 % NewMagickImage() creates a blank image canvas of the specified size and
2011 % The format of the NewMagickImage method is:
2013 % Image *NewMagickImage(const ImageInfo *image_info,
2014 % const size_t width,const size_t height,const PixelInfo *background,
2015 % ExceptionInfo *exception)
2017 % A description of each parameter follows:
2019 % o image: the image.
2021 % o width: the image width.
2023 % o height: the image height.
2025 % o background: the image color.
2027 % o exception: return any errors or warnings in this structure.
2030 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2031 const size_t width,const size_t height,const PixelInfo *background,
2032 ExceptionInfo *exception)
2046 assert(image_info != (const ImageInfo *) NULL);
2047 if (image_info->debug != MagickFalse)
2048 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2049 assert(image_info->signature == MagickSignature);
2050 assert(background != (const PixelInfo *) NULL);
2051 image=AcquireImage(image_info,exception);
2052 image->columns=width;
2054 image->colorspace=background->colorspace;
2055 image->matte=background->matte;
2056 image->fuzz=background->fuzz;
2057 image->depth=background->depth;
2059 image_view=AcquireCacheView(image);
2060 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2061 #pragma omp parallel for schedule(static,4) shared(status)
2063 for (y=0; y < (ssize_t) image->rows; y++)
2071 if (status == MagickFalse)
2073 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2074 if (q == (Quantum *) NULL)
2079 for (x=0; x < (ssize_t) image->columns; x++)
2081 SetPixelInfoPixel(image,background,q);
2082 q+=GetPixelChannels(image);
2084 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2087 image_view=DestroyCacheView(image_view);
2088 if (status == MagickFalse)
2089 image=DestroyImage(image);
2094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2098 % R e f e r e n c e I m a g e %
2102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2104 % ReferenceImage() increments the reference count associated with an image
2105 % returning a pointer to the image.
2107 % The format of the ReferenceImage method is:
2109 % Image *ReferenceImage(Image *image)
2111 % A description of each parameter follows:
2113 % o image: the image.
2116 MagickExport Image *ReferenceImage(Image *image)
2118 assert(image != (Image *) NULL);
2119 if (image->debug != MagickFalse)
2120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2121 assert(image->signature == MagickSignature);
2122 LockSemaphoreInfo(image->semaphore);
2123 image->reference_count++;
2124 UnlockSemaphoreInfo(image->semaphore);
2129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2133 % R e s e t I m a g e P a g e %
2137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2139 % ResetImagePage() resets the image page canvas and position.
2141 % The format of the ResetImagePage method is:
2143 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2145 % A description of each parameter follows:
2147 % o image: the image.
2149 % o page: the relative page specification.
2152 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2160 assert(image != (Image *) NULL);
2161 assert(image->signature == MagickSignature);
2162 if (image->debug != MagickFalse)
2163 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2164 flags=ParseAbsoluteGeometry(page,&geometry);
2165 if ((flags & WidthValue) != 0)
2167 if ((flags & HeightValue) == 0)
2168 geometry.height=geometry.width;
2169 image->page.width=geometry.width;
2170 image->page.height=geometry.height;
2172 if ((flags & AspectValue) != 0)
2174 if ((flags & XValue) != 0)
2175 image->page.x+=geometry.x;
2176 if ((flags & YValue) != 0)
2177 image->page.y+=geometry.y;
2181 if ((flags & XValue) != 0)
2183 image->page.x=geometry.x;
2184 if ((image->page.width == 0) && (geometry.x > 0))
2185 image->page.width=image->columns+geometry.x;
2187 if ((flags & YValue) != 0)
2189 image->page.y=geometry.y;
2190 if ((image->page.height == 0) && (geometry.y > 0))
2191 image->page.height=image->rows+geometry.y;
2198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2202 % S e p a r a t e I m a g e %
2206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2208 % SeparateImage() separates a channel from the image and returns it as a
2211 % The format of the SeparateImage method is:
2213 % Image *SeparateImage(const Image *image,const ChannelType channel,
2214 % ExceptionInfo *exception)
2216 % A description of each parameter follows:
2218 % o image: the image.
2220 % o channel: the image channel.
2222 % o exception: return any errors or warnings in this structure.
2225 MagickExport Image *SeparateImage(const Image *image,
2226 const ChannelType channel_type,ExceptionInfo *exception)
2228 #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01)
2229 #define SeparateImageTag "Separate/Image"
2248 Initialize spread image attributes.
2250 assert(image != (Image *) NULL);
2251 assert(image->signature == MagickSignature);
2252 if (image->debug != MagickFalse)
2253 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2254 assert(exception != (ExceptionInfo *) NULL);
2255 assert(exception->signature == MagickSignature);
2256 separate_image=CloneImage(image,image->columns,image->rows,MagickTrue,
2258 if (separate_image == (Image *) NULL)
2259 return((Image *) NULL);
2260 if (SetImageStorageClass(separate_image,DirectClass,exception) == MagickFalse)
2262 separate_image=DestroyImage(separate_image);
2263 return((Image *) NULL);
2265 separate_image->colorspace=GRAYColorspace;
2271 image_view=AcquireCacheView(image);
2272 separate_view=AcquireCacheView(separate_image);
2273 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2274 #pragma omp parallel for schedule(static) shared(progress,status)
2276 for (y=0; y < (ssize_t) image->rows; y++)
2278 register const Quantum
2287 if (status == MagickFalse)
2289 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2290 q=QueueCacheViewAuthenticPixels(separate_view,0,y,separate_image->columns,1,
2292 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2297 for (x=0; x < (ssize_t) image->columns; x++)
2302 if (GetPixelMask(image,p) != 0)
2304 p+=GetPixelChannels(image);
2305 q+=GetPixelChannels(separate_image);
2308 SetPixelChannel(separate_image,GrayPixelChannel,0,q);
2309 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2317 channel=GetPixelChannelMapChannel(image,i);
2318 traits=GetPixelChannelMapTraits(image,channel);
2319 if ((traits == UndefinedPixelTrait) ||
2320 (GetChannelBit(channel_type,channel) == 0))
2322 SetPixelChannel(separate_image,GrayPixelChannel,p[i],q);
2324 p+=GetPixelChannels(image);
2325 q+=GetPixelChannels(separate_image);
2327 if (SyncCacheViewAuthenticPixels(separate_view,exception) == MagickFalse)
2329 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2334 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2335 #pragma omp critical (MagickCore_SeparateImage)
2337 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2338 if (proceed == MagickFalse)
2342 separate_view=DestroyCacheView(separate_view);
2343 image_view=DestroyCacheView(image_view);
2344 return(separate_image);
2348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2352 % S e p a r a t e I m a g e s %
2356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2358 % SeparateImages() returns a separate grayscale image for each channel
2361 % The format of the SeparateImages method is:
2363 % MagickBooleanType SeparateImages(const Image *image,
2364 % ExceptionInfo *exception)
2366 % A description of each parameter follows:
2368 % o image: the image.
2370 % o exception: return any errors or warnings in this structure.
2373 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2382 assert(image != (Image *) NULL);
2383 assert(image->signature == MagickSignature);
2384 if (image->debug != MagickFalse)
2385 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2386 images=NewImageList();
2387 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2395 channel=GetPixelChannelMapChannel(image,i);
2396 traits=GetPixelChannelMapTraits(image,channel);
2397 if ((traits == UndefinedPixelTrait) ||
2398 ((traits & UpdatePixelTrait) == 0))
2400 separate_image=SeparateImage(image,(ChannelType) (1 << channel),exception);
2401 if (separate_image != (Image *) NULL)
2402 AppendImageToList(&images,separate_image);
2408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2412 % S e t I m a g e A l p h a C h a n n e l %
2416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2418 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2421 % The format of the SetImageAlphaChannel method is:
2423 % MagickBooleanType SetImageAlphaChannel(Image *image,
2424 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2426 % A description of each parameter follows:
2428 % o image: the image.
2430 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2431 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2432 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2433 % TransparentAlphaChannel.
2435 % o exception: return any errors or warnings in this structure.
2439 static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
2440 const MagickRealType alpha,const Quantum *q,const MagickRealType beta,
2452 Compose pixel p over pixel q with the given alpha.
2454 Sa=QuantumScale*alpha;
2455 Da=QuantumScale*beta,
2456 gamma=Sa*(-Da)+Sa+Da;
2457 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
2458 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2466 channel=GetPixelChannelMapChannel(image,i);
2467 traits=GetPixelChannelMapTraits(image,channel);
2468 if (traits == UndefinedPixelTrait)
2472 case RedPixelChannel:
2474 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2475 beta,(MagickRealType) p->red,alpha));
2478 case GreenPixelChannel:
2480 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2481 beta,(MagickRealType) p->green,alpha));
2484 case BluePixelChannel:
2486 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2487 beta,(MagickRealType) p->blue,alpha));
2490 case BlackPixelChannel:
2492 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2493 beta,(MagickRealType) p->black,alpha));
2496 case AlphaPixelChannel:
2498 composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
2507 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2508 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2513 assert(image != (Image *) NULL);
2514 if (image->debug != MagickFalse)
2515 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2516 assert(image->signature == MagickSignature);
2520 case ActivateAlphaChannel:
2522 image->matte=MagickTrue;
2525 case BackgroundAlphaChannel:
2534 Set transparent pixels to background color.
2536 if (image->matte == MagickFalse)
2538 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2540 image_view=AcquireCacheView(image);
2541 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2542 #pragma omp parallel for schedule(static,4) shared(status)
2544 for (y=0; y < (ssize_t) image->rows; y++)
2552 if (status == MagickFalse)
2554 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2556 if (q == (Quantum *) NULL)
2561 for (x=0; x < (ssize_t) image->columns; x++)
2563 if (GetPixelAlpha(image,q) == TransparentAlpha)
2564 SetPixelInfoPixel(image,&image->background_color,q);
2565 q+=GetPixelChannels(image);
2567 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2570 image_view=DestroyCacheView(image_view);
2573 case CopyAlphaChannel:
2574 case ShapeAlphaChannel:
2577 Copy pixel intensity to the alpha channel.
2579 status=CompositeImage(image,IntensityCompositeOp,image,0,0,exception);
2580 if (alpha_type == ShapeAlphaChannel)
2581 (void) LevelImageColors(image,&image->background_color,
2582 &image->background_color,MagickTrue,exception);
2585 case DeactivateAlphaChannel:
2587 image->matte=MagickFalse;
2590 case ExtractAlphaChannel:
2592 status=CompositeImage(image,AlphaCompositeOp,image,0,0,exception);
2593 image->matte=MagickFalse;
2596 case OpaqueAlphaChannel:
2598 status=SetImageAlpha(image,OpaqueAlpha,exception);
2601 case RemoveAlphaChannel:
2610 Remove transparency.
2612 if (image->matte == MagickFalse)
2614 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2616 image_view=AcquireCacheView(image);
2617 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2618 #pragma omp parallel for schedule(static,4) shared(status)
2620 for (y=0; y < (ssize_t) image->rows; y++)
2628 if (status == MagickFalse)
2630 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2632 if (q == (Quantum *) NULL)
2637 for (x=0; x < (ssize_t) image->columns; x++)
2639 FlattenPixelInfo(image,&image->background_color,
2640 image->background_color.alpha,q,(MagickRealType)
2641 GetPixelAlpha(image,q),q);
2642 q+=GetPixelChannels(image);
2644 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2647 image_view=DestroyCacheView(image_view);
2648 image->matte=image->background_color.matte;
2651 case SetAlphaChannel:
2653 if (image->matte == MagickFalse)
2654 status=SetImageAlpha(image,OpaqueAlpha,exception);
2657 case TransparentAlphaChannel:
2659 status=SetImageAlpha(image,TransparentAlpha,exception);
2662 case UndefinedAlphaChannel:
2665 if (status == MagickFalse)
2667 return(SyncImagePixelCache(image,exception));
2671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2675 % S e t I m a g e B a c k g r o u n d C o l o r %
2679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2681 % SetImageBackgroundColor() initializes the image pixels to the image
2682 % background color. The background color is defined by the background_color
2683 % member of the image structure.
2685 % The format of the SetImage method is:
2687 % MagickBooleanType SetImageBackgroundColor(Image *image,
2688 % ExceptionInfo *exception)
2690 % A description of each parameter follows:
2692 % o image: the image.
2694 % o exception: return any errors or warnings in this structure.
2697 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2698 ExceptionInfo *exception)
2709 assert(image != (Image *) NULL);
2710 if (image->debug != MagickFalse)
2711 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2712 assert(image->signature == MagickSignature);
2713 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2714 return(MagickFalse);
2715 if ((image->background_color.matte != MagickFalse) &&
2716 (image->matte == MagickFalse))
2717 (void) SetImageAlpha(image,OpaqueAlpha,exception);
2719 Set image background color.
2722 image_view=AcquireCacheView(image);
2723 for (y=0; y < (ssize_t) image->rows; y++)
2731 if (status == MagickFalse)
2733 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2734 if (q == (Quantum *) NULL)
2739 for (x=0; x < (ssize_t) image->columns; x++)
2741 SetPixelInfoPixel(image,&image->background_color,q);
2742 q+=GetPixelChannels(image);
2744 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2747 image_view=DestroyCacheView(image_view);
2752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2756 % S e t I m a g e C o l o r %
2760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2762 % SetImageColor() set the entire image canvas to the specified color.
2764 % The format of the SetImageColor method is:
2766 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2767 % ExeptionInfo *exception)
2769 % A description of each parameter follows:
2771 % o image: the image.
2773 % o background: the image color.
2775 % o exception: return any errors or warnings in this structure.
2778 MagickExport MagickBooleanType SetImageColor(Image *image,
2779 const PixelInfo *color,ExceptionInfo *exception)
2790 assert(image != (Image *) NULL);
2791 if (image->debug != MagickFalse)
2792 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2793 assert(image->signature == MagickSignature);
2794 assert(color != (const PixelInfo *) NULL);
2795 image->colorspace=color->colorspace;
2796 image->matte=color->matte;
2797 image->fuzz=color->fuzz;
2798 image->depth=color->depth;
2800 image_view=AcquireCacheView(image);
2801 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2802 #pragma omp parallel for schedule(static,4) shared(status)
2804 for (y=0; y < (ssize_t) image->rows; y++)
2812 if (status == MagickFalse)
2814 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2815 if (q == (Quantum *) NULL)
2820 for (x=0; x < (ssize_t) image->columns; x++)
2822 SetPixelInfoPixel(image,color,q);
2823 q+=GetPixelChannels(image);
2825 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2828 image_view=DestroyCacheView(image_view);
2833 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2837 % S e t I m a g e S t o r a g e C l a s s %
2841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2843 % SetImageStorageClass() sets the image class: DirectClass for true color
2844 % images or PseudoClass for colormapped images.
2846 % The format of the SetImageStorageClass method is:
2848 % MagickBooleanType SetImageStorageClass(Image *image,
2849 % const ClassType storage_class,ExceptionInfo *exception)
2851 % A description of each parameter follows:
2853 % o image: the image.
2855 % o storage_class: The image class.
2857 % o exception: return any errors or warnings in this structure.
2860 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2861 const ClassType storage_class,ExceptionInfo *exception)
2863 image->storage_class=storage_class;
2864 return(SyncImagePixelCache(image,exception));
2868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2872 % S e t I m a g e E x t e n t %
2876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2878 % SetImageExtent() sets the image size (i.e. columns & rows).
2880 % The format of the SetImageExtent method is:
2882 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2883 % const size_t rows,ExceptionInfo *exception)
2885 % A description of each parameter follows:
2887 % o image: the image.
2889 % o columns: The image width in pixels.
2891 % o rows: The image height in pixels.
2893 % o exception: return any errors or warnings in this structure.
2896 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2897 const size_t rows,ExceptionInfo *exception)
2899 if ((columns == 0) || (rows == 0))
2900 return(MagickFalse);
2901 image->columns=columns;
2903 return(SyncImagePixelCache(image,exception));
2907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2911 + S e t I m a g e I n f o %
2915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2917 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2918 % It is set to a type of image format based on the prefix or suffix of the
2919 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2920 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2921 % precendence over the suffix. Use an optional index enclosed in brackets
2922 % after a file name to specify a desired scene of a multi-resolution image
2923 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2924 % indicates success.
2926 % The format of the SetImageInfo method is:
2928 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2929 % const unsigned int frames,ExceptionInfo *exception)
2931 % A description of each parameter follows:
2933 % o image_info: the image info.
2935 % o frames: the number of images you intend to write.
2937 % o exception: return any errors or warnings in this structure.
2940 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2941 const unsigned int frames,ExceptionInfo *exception)
2944 extension[MaxTextExtent],
2945 filename[MaxTextExtent],
2946 magic[MaxTextExtent],
2948 subimage[MaxTextExtent];
2972 magick[2*MaxTextExtent];
2975 Look for 'image.format' in filename.
2977 assert(image_info != (ImageInfo *) NULL);
2978 assert(image_info->signature == MagickSignature);
2979 if (image_info->debug != MagickFalse)
2980 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2981 image_info->filename);
2985 GetPathComponent(image_info->filename,SubimagePath,subimage);
2986 if (*subimage != '\0')
2989 Look for scene specification (e.g. img0001.pcd[4]).
2991 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2993 if (IsGeometry(subimage) != MagickFalse)
2994 (void) CloneString(&image_info->extract,subimage);
3002 (void) CloneString(&image_info->scenes,subimage);
3003 image_info->scene=StringToUnsignedLong(image_info->scenes);
3004 image_info->number_scenes=image_info->scene;
3005 p=image_info->scenes;
3006 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3008 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3011 first=(size_t) strtol(p,&q,10);
3013 while (isspace((int) ((unsigned char) *q)) != 0)
3016 last=(size_t) strtol(q+1,&q,10);
3019 if (first < image_info->scene)
3020 image_info->scene=first;
3021 if (last > image_info->number_scenes)
3022 image_info->number_scenes=last;
3025 image_info->number_scenes-=image_info->scene-1;
3030 GetPathComponent(image_info->filename,ExtensionPath,extension);
3031 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3032 if (*extension != '\0')
3033 if ((LocaleCompare(extension,"gz") == 0) ||
3034 (LocaleCompare(extension,"Z") == 0) ||
3035 (LocaleCompare(extension,"svgz") == 0) ||
3036 (LocaleCompare(extension,"wmz") == 0))
3039 path[MaxTextExtent];
3041 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3042 path[strlen(path)-strlen(extension)-1]='\0';
3043 GetPathComponent(path,ExtensionPath,extension);
3046 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3047 if (*extension != '\0')
3048 if (LocaleCompare(extension,"bz2") == 0)
3051 path[MaxTextExtent];
3053 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3054 path[strlen(path)-strlen(extension)-1]='\0';
3055 GetPathComponent(path,ExtensionPath,extension);
3058 image_info->affirm=MagickFalse;
3059 sans_exception=AcquireExceptionInfo();
3060 if (*extension != '\0')
3069 *format_type_formats[] =
3092 User specified image format.
3094 (void) CopyMagickString(magic,extension,MaxTextExtent);
3097 Look for explicit image formats.
3099 format_type=UndefinedFormatType;
3101 while ((format_type == UndefinedFormatType) &&
3102 (format_type_formats[i] != (char *) NULL))
3104 if ((*magic == *format_type_formats[i]) &&
3105 (LocaleCompare(magic,format_type_formats[i]) == 0))
3106 format_type=ExplicitFormatType;
3109 magick_info=GetMagickInfo(magic,sans_exception);
3110 if ((magick_info != (const MagickInfo *) NULL) &&
3111 (magick_info->format_type != UndefinedFormatType))
3112 format_type=magick_info->format_type;
3113 if (format_type == UndefinedFormatType)
3114 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3116 if (format_type == ExplicitFormatType)
3118 image_info->affirm=MagickTrue;
3119 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3121 if (LocaleCompare(magic,"RGB") == 0)
3122 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3125 Look for explicit 'format:image' in filename.
3128 GetPathComponent(image_info->filename,MagickPath,magic);
3130 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3134 User specified image format.
3137 if (IsMagickConflict(magic) == MagickFalse)
3139 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3140 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3141 image_info->affirm=MagickTrue;
3143 image_info->temporary=MagickTrue;
3146 magick_info=GetMagickInfo(magic,sans_exception);
3147 sans_exception=DestroyExceptionInfo(sans_exception);
3148 if ((magick_info == (const MagickInfo *) NULL) ||
3149 (GetMagickEndianSupport(magick_info) == MagickFalse))
3150 image_info->endian=UndefinedEndian;
3151 GetPathComponent(image_info->filename,CanonicalPath,filename);
3152 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3153 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3156 Test for multiple image support (e.g. image%02d.png).
3158 (void) InterpretImageFilename(image_info,(Image *) NULL,
3159 image_info->filename,(int) image_info->scene,filename,exception);
3160 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3161 (strchr(filename,'%') == (char *) NULL))
3162 image_info->adjoin=MagickFalse;
3164 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3167 Some image formats do not support multiple frames per file.
3169 magick_info=GetMagickInfo(magic,exception);
3170 if (magick_info != (const MagickInfo *) NULL)
3171 if (GetMagickAdjoin(magick_info) == MagickFalse)
3172 image_info->adjoin=MagickFalse;
3174 if (image_info->affirm != MagickFalse)
3179 Determine the image format from the first few bytes of the file.
3181 image=AcquireImage(image_info,exception);
3182 (void) CopyMagickString(image->filename,image_info->filename,
3184 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3185 if (status == MagickFalse)
3187 image=DestroyImage(image);
3188 return(MagickFalse);
3190 if ((IsBlobSeekable(image) == MagickFalse) ||
3191 (IsBlobExempt(image) != MagickFalse))
3194 Copy standard input or pipe to temporary file.
3197 status=ImageToFile(image,filename,exception);
3198 (void) CloseBlob(image);
3199 if (status == MagickFalse)
3201 image=DestroyImage(image);
3202 return(MagickFalse);
3204 SetImageInfoFile(image_info,(FILE *) NULL);
3205 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3206 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3207 if (status == MagickFalse)
3209 image=DestroyImage(image);
3210 return(MagickFalse);
3212 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3213 image_info->temporary=MagickTrue;
3215 (void) ResetMagickMemory(magick,0,sizeof(magick));
3216 count=ReadBlob(image,2*MaxTextExtent,magick);
3217 (void) CloseBlob(image);
3218 image=DestroyImage(image);
3220 Check magic.xml configuration file.
3222 sans_exception=AcquireExceptionInfo();
3223 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3224 if ((magic_info != (const MagicInfo *) NULL) &&
3225 (GetMagicName(magic_info) != (char *) NULL))
3227 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
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);
3236 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3237 if ((magick_info == (const MagickInfo *) NULL) ||
3238 (GetMagickEndianSupport(magick_info) == MagickFalse))
3239 image_info->endian=UndefinedEndian;
3240 sans_exception=DestroyExceptionInfo(sans_exception);
3246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3250 % S e t I m a g e I n f o B l o b %
3254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3256 % SetImageInfoBlob() sets the image info blob member.
3258 % The format of the SetImageInfoBlob method is:
3260 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3261 % const size_t length)
3263 % A description of each parameter follows:
3265 % o image_info: the image info.
3269 % o length: the blob length.
3272 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3273 const size_t length)
3275 assert(image_info != (ImageInfo *) NULL);
3276 assert(image_info->signature == MagickSignature);
3277 if (image_info->debug != MagickFalse)
3278 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3279 image_info->filename);
3280 image_info->blob=(void *) blob;
3281 image_info->length=length;
3285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3289 % S e t I m a g e I n f o F i l e %
3293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3295 % SetImageInfoFile() sets the image info file member.
3297 % The format of the SetImageInfoFile method is:
3299 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3301 % A description of each parameter follows:
3303 % o image_info: the image info.
3308 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3310 assert(image_info != (ImageInfo *) NULL);
3311 assert(image_info->signature == MagickSignature);
3312 if (image_info->debug != MagickFalse)
3313 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3314 image_info->filename);
3315 image_info->file=file;
3319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3323 % S e t I m a g e M a s k %
3327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3329 % SetImageMask() associates a mask with the image. The mask must be the same
3330 % dimensions as the image.
3332 % The format of the SetImageMask method is:
3334 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3335 % ExceptionInfo *exception)
3337 % A description of each parameter follows:
3339 % o image: the image.
3341 % o mask: the image mask.
3343 % o exception: return any errors or warnings in this structure.
3346 MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
3347 ExceptionInfo *exception)
3362 assert(image != (Image *) NULL);
3363 if (image->debug != MagickFalse)
3364 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3365 assert(image->signature == MagickSignature);
3366 if (mask == (const Image *) NULL)
3368 image->mask=MagickFalse;
3372 image->mask=MagickTrue;
3373 image_view=AcquireCacheView(image);
3374 mask_view=AcquireCacheView(mask);
3375 for (y=0; y < (ssize_t) image->rows; y++)
3377 register const Quantum
3386 if (status == MagickFalse)
3388 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3389 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3390 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3395 for (x=0; x < (ssize_t) image->columns; x++)
3397 SetPixelMask(image,GetPixelGray(mask,p),q);
3398 p+=GetPixelChannels(mask);
3399 q+=GetPixelChannels(image);
3401 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3404 mask_view=DestroyCacheView(mask_view);
3405 image_view=DestroyCacheView(image_view);
3410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3414 % S e t I m a g e A l p h a %
3418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3420 % SetImageAlpha() sets the alpha levels of the image.
3422 % The format of the SetImageAlpha method is:
3424 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3425 % ExceptionInfo *exception)
3427 % A description of each parameter follows:
3429 % o image: the image.
3431 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3432 % fully transparent.
3435 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3436 ExceptionInfo *exception)
3447 assert(image != (Image *) NULL);
3448 if (image->debug != MagickFalse)
3449 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3450 assert(image->signature == MagickSignature);
3451 image->matte=MagickTrue;
3453 image_view=AcquireCacheView(image);
3454 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3455 #pragma omp parallel for schedule(static,4) shared(status)
3457 for (y=0; y < (ssize_t) image->rows; y++)
3465 if (status == MagickFalse)
3467 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3468 if (q == (Quantum *) NULL)
3473 for (x=0; x < (ssize_t) image->columns; x++)
3475 SetPixelAlpha(image,alpha,q);
3476 q+=GetPixelChannels(image);
3478 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3481 image_view=DestroyCacheView(image_view);
3486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3490 % S e t I m a g e T y p e %
3494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3496 % SetImageType() sets the type of image. Choose from these types:
3498 % Bilevel Grayscale GrayscaleMatte
3499 % Palette PaletteMatte TrueColor
3500 % TrueColorMatte ColorSeparation ColorSeparationMatte
3503 % The format of the SetImageType method is:
3505 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3506 % ExceptionInfo *exception)
3508 % A description of each parameter follows:
3510 % o image: the image.
3512 % o type: Image type.
3514 % o exception: return any errors or warnings in this structure.
3517 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3518 ExceptionInfo *exception)
3532 assert(image != (Image *) NULL);
3533 if (image->debug != MagickFalse)
3534 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3535 assert(image->signature == MagickSignature);
3537 image_info=AcquireImageInfo();
3538 image_info->dither=image->dither;
3539 artifact=GetImageArtifact(image,"dither");
3540 if (artifact != (const char *) NULL)
3541 (void) SetImageOption(image_info,"dither",artifact);
3546 if (IsImageMonochrome(image,exception) == MagickFalse)
3548 quantize_info=AcquireQuantizeInfo(image_info);
3549 quantize_info->number_colors=2;
3550 quantize_info->colorspace=GRAYColorspace;
3551 status=QuantizeImage(quantize_info,image,exception);
3552 quantize_info=DestroyQuantizeInfo(quantize_info);
3554 image->matte=MagickFalse;
3559 if (IsImageGray(image,exception) == MagickFalse)
3560 status=TransformImageColorspace(image,GRAYColorspace,exception);
3561 image->matte=MagickFalse;
3564 case GrayscaleMatteType:
3566 if (IsImageGray(image,exception) == MagickFalse)
3567 status=TransformImageColorspace(image,GRAYColorspace,exception);
3568 if (image->matte == MagickFalse)
3569 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3574 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3575 status=TransformImageColorspace(image,sRGBColorspace,exception);
3576 if ((image->storage_class == DirectClass) || (image->colors > 256))
3578 quantize_info=AcquireQuantizeInfo(image_info);
3579 quantize_info->number_colors=256;
3580 status=QuantizeImage(quantize_info,image,exception);
3581 quantize_info=DestroyQuantizeInfo(quantize_info);
3583 image->matte=MagickFalse;
3586 case PaletteBilevelMatteType:
3591 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3592 status=TransformImageColorspace(image,sRGBColorspace,exception);
3593 if (image->matte == MagickFalse)
3594 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3595 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3596 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
3597 (void) SetPixelChannelMask(image,channel_mask);
3598 quantize_info=AcquireQuantizeInfo(image_info);
3599 status=QuantizeImage(quantize_info,image,exception);
3600 quantize_info=DestroyQuantizeInfo(quantize_info);
3603 case PaletteMatteType:
3605 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3606 status=TransformImageColorspace(image,sRGBColorspace,exception);
3607 if (image->matte == MagickFalse)
3608 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3609 quantize_info=AcquireQuantizeInfo(image_info);
3610 quantize_info->colorspace=TransparentColorspace;
3611 status=QuantizeImage(quantize_info,image,exception);
3612 quantize_info=DestroyQuantizeInfo(quantize_info);
3617 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3618 status=TransformImageColorspace(image,sRGBColorspace,exception);
3619 if (image->storage_class != DirectClass)
3620 status=SetImageStorageClass(image,DirectClass,exception);
3621 image->matte=MagickFalse;
3624 case TrueColorMatteType:
3626 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3627 status=TransformImageColorspace(image,sRGBColorspace,exception);
3628 if (image->storage_class != DirectClass)
3629 status=SetImageStorageClass(image,DirectClass,exception);
3630 if (image->matte == MagickFalse)
3631 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3634 case ColorSeparationType:
3636 if (image->colorspace != CMYKColorspace)
3638 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3639 status=TransformImageColorspace(image,sRGBColorspace,exception);
3640 status=TransformImageColorspace(image,CMYKColorspace,exception);
3642 if (image->storage_class != DirectClass)
3643 status=SetImageStorageClass(image,DirectClass,exception);
3644 image->matte=MagickFalse;
3647 case ColorSeparationMatteType:
3649 if (image->colorspace != CMYKColorspace)
3651 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3652 status=TransformImageColorspace(image,sRGBColorspace,exception);
3653 status=TransformImageColorspace(image,CMYKColorspace,exception);
3655 if (image->storage_class != DirectClass)
3656 status=SetImageStorageClass(image,DirectClass,exception);
3657 if (image->matte == MagickFalse)
3658 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3666 image_info=DestroyImageInfo(image_info);
3671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3675 % 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 %
3679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3681 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3682 % image and returns the previous setting. A virtual pixel is any pixel access
3683 % that is outside the boundaries of the image cache.
3685 % The format of the SetImageVirtualPixelMethod() method is:
3687 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3688 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3690 % A description of each parameter follows:
3692 % o image: the image.
3694 % o virtual_pixel_method: choose the type of virtual pixel.
3696 % o exception: return any errors or warnings in this structure.
3699 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3700 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3702 assert(image != (const Image *) NULL);
3703 assert(image->signature == MagickSignature);
3704 if (image->debug != MagickFalse)
3705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3706 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3714 % S m u s h I m a g e s %
3718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3720 % SmushImages() takes all images from the current image pointer to the end
3721 % of the image list and smushes them to each other top-to-bottom if the
3722 % stack parameter is true, otherwise left-to-right.
3724 % The current gravity setting now effects how the image is justified in the
3727 % The format of the SmushImages method is:
3729 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3730 % ExceptionInfo *exception)
3732 % A description of each parameter follows:
3734 % o images: the image sequence.
3736 % o stack: A value other than 0 stacks the images top-to-bottom.
3738 % o offset: minimum distance in pixels between images.
3740 % o exception: return any errors or warnings in this structure.
3744 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3745 const ssize_t offset,ExceptionInfo *exception)
3759 register const Quantum
3772 if (images->previous == (Image *) NULL)
3775 SetGeometry(smush_image,&right_geometry);
3776 GravityAdjustGeometry(right_image->columns,right_image->rows,
3777 right_image->gravity,&right_geometry);
3778 left_image=images->previous;
3779 SetGeometry(smush_image,&left_geometry);
3780 GravityAdjustGeometry(left_image->columns,left_image->rows,
3781 left_image->gravity,&left_geometry);
3782 gap=right_image->columns;
3783 left_view=AcquireCacheView(left_image);
3784 right_view=AcquireCacheView(right_image);
3785 for (y=0; y < (ssize_t) smush_image->rows; y++)
3787 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3789 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3790 if ((p == (const Quantum *) NULL) ||
3791 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3792 ((left_image->columns-x-1) >= gap))
3795 i=(ssize_t) left_image->columns-x-1;
3796 for (x=0; x < (ssize_t) right_image->columns; x++)
3798 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3800 if ((p == (const Quantum *) NULL) ||
3801 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3802 ((x+i) >= (ssize_t) gap))
3805 if ((x+i) < (ssize_t) gap)
3808 right_view=DestroyCacheView(right_view);
3809 left_view=DestroyCacheView(left_view);
3810 if (y < (ssize_t) smush_image->rows)
3812 return((ssize_t) gap-offset);
3815 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3816 const ssize_t offset,ExceptionInfo *exception)
3830 register const Quantum
3843 if (images->previous == (Image *) NULL)
3845 bottom_image=images;
3846 SetGeometry(smush_image,&bottom_geometry);
3847 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3848 bottom_image->gravity,&bottom_geometry);
3849 top_image=images->previous;
3850 SetGeometry(smush_image,&top_geometry);
3851 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3853 gap=bottom_image->rows;
3854 top_view=AcquireCacheView(top_image);
3855 bottom_view=AcquireCacheView(bottom_image);
3856 for (x=0; x < (ssize_t) smush_image->columns; x++)
3858 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3860 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3861 if ((p == (const Quantum *) NULL) ||
3862 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3863 ((top_image->rows-y-1) >= gap))
3866 i=(ssize_t) top_image->rows-y-1;
3867 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3869 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3871 if ((p == (const Quantum *) NULL) ||
3872 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3873 ((y+i) >= (ssize_t) gap))
3876 if ((y+i) < (ssize_t) gap)
3879 bottom_view=DestroyCacheView(bottom_view);
3880 top_view=DestroyCacheView(top_view);
3881 if (x < (ssize_t) smush_image->columns)
3883 return((ssize_t) gap-offset);
3886 MagickExport Image *SmushImages(const Image *images,
3887 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3889 #define SmushImageTag "Smush/Image"
3911 register const Image
3924 Compute maximum area of smushed area.
3926 assert(images != (Image *) NULL);
3927 assert(images->signature == MagickSignature);
3928 if (images->debug != MagickFalse)
3929 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3930 assert(exception != (ExceptionInfo *) NULL);
3931 assert(exception->signature == MagickSignature);
3935 width=image->columns;
3937 next=GetNextImageInList(image);
3938 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3940 if (next->matte != MagickFalse)
3943 if (stack != MagickFalse)
3945 if (next->columns > width)
3946 width=next->columns;
3948 if (next->previous != (Image *) NULL)
3952 width+=next->columns;
3953 if (next->previous != (Image *) NULL)
3955 if (next->rows > height)
3961 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3962 if (smush_image == (Image *) NULL)
3963 return((Image *) NULL);
3964 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3966 smush_image=DestroyImage(smush_image);
3967 return((Image *) NULL);
3969 smush_image->matte=matte;
3970 (void) SetImageBackgroundColor(smush_image,exception);
3974 smush_view=AcquireCacheView(smush_image);
3975 for (n=0; n < (MagickOffsetType) number_images; n++)
3977 SetGeometry(smush_image,&geometry);
3978 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3979 if (stack != MagickFalse)
3981 x_offset-=geometry.x;
3982 y_offset-=SmushYGap(smush_image,image,offset,exception);
3986 x_offset-=SmushXGap(smush_image,image,offset,exception);
3987 y_offset-=geometry.y;
3989 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
3991 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3992 if (proceed == MagickFalse)
3994 if (stack == MagickFalse)
3996 x_offset+=(ssize_t) image->columns;
4002 y_offset+=(ssize_t) image->rows;
4004 image=GetNextImageInList(image);
4006 if (stack == MagickFalse)
4007 smush_image->columns=(size_t) x_offset;
4009 smush_image->rows=(size_t) y_offset;
4010 smush_view=DestroyCacheView(smush_view);
4011 if (status == MagickFalse)
4012 smush_image=DestroyImage(smush_image);
4013 return(smush_image);
4017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4021 % S t r i p I m a g e %
4025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4027 % StripImage() strips an image of all profiles and comments.
4029 % The format of the StripImage method is:
4031 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
4033 % A description of each parameter follows:
4035 % o image: the image.
4037 % o exception: return any errors or warnings in this structure.
4040 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
4045 assert(image != (Image *) NULL);
4046 if (image->debug != MagickFalse)
4047 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4049 DestroyImageProfiles(image);
4050 (void) DeleteImageProperty(image,"comment");
4051 (void) DeleteImageProperty(image,"date:create");
4052 (void) DeleteImageProperty(image,"date:modify");
4053 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4062 + S y n c I m a g e %
4066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4068 % SyncImage() initializes the red, green, and blue intensities of each pixel
4069 % as defined by the colormap index.
4071 % The format of the SyncImage method is:
4073 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4075 % A description of each parameter follows:
4077 % o image: the image.
4079 % o exception: return any errors or warnings in this structure.
4083 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
4084 MagickBooleanType *range_exception)
4086 if ((size_t) index < image->colors)
4088 *range_exception=MagickTrue;
4092 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4104 assert(image != (Image *) NULL);
4105 if (image->debug != MagickFalse)
4106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4107 assert(image->signature == MagickSignature);
4108 if (image->storage_class == DirectClass)
4109 return(MagickFalse);
4110 range_exception=MagickFalse;
4112 image_view=AcquireCacheView(image);
4113 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4114 #pragma omp parallel for schedule(static,4) shared(range_exception,status)
4116 for (y=0; y < (ssize_t) image->rows; y++)
4127 if (status == MagickFalse)
4129 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4130 if (q == (Quantum *) NULL)
4135 for (x=0; x < (ssize_t) image->columns; x++)
4137 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4138 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
4139 q+=GetPixelChannels(image);
4141 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4144 image_view=DestroyCacheView(image_view);
4145 if (range_exception != MagickFalse)
4146 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
4147 "InvalidColormapIndex","`%s'",image->filename);
4152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4156 % S y n c I m a g e S e t t i n g s %
4160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4162 % SyncImageSettings() syncs the image_info options into per-image attributes.
4164 % The format of the SyncImageSettings method is:
4166 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4167 % Image *image,ExceptionInfo *exception)
4168 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4169 % Image *image,ExceptionInfo *exception)
4171 % A description of each parameter follows:
4173 % o image_info: the image info.
4175 % o image: the image.
4177 % o exception: return any errors or warnings in this structure.
4181 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4182 Image *images,ExceptionInfo *exception)
4187 assert(image_info != (const ImageInfo *) NULL);
4188 assert(image_info->signature == MagickSignature);
4189 assert(images != (Image *) NULL);
4190 assert(images->signature == MagickSignature);
4191 if (images->debug != MagickFalse)
4192 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4194 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4195 (void) SyncImageSettings(image_info,image,exception);
4196 (void) DeleteImageOption(image_info,"page");
4200 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4201 Image *image,ExceptionInfo *exception)
4204 property[MaxTextExtent];
4222 assert(image_info != (const ImageInfo *) NULL);
4223 assert(image_info->signature == MagickSignature);
4224 assert(image != (Image *) NULL);
4225 assert(image->signature == MagickSignature);
4226 if (image->debug != MagickFalse)
4227 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4228 option=GetImageOption(image_info,"background");
4229 if (option != (const char *) NULL)
4230 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4232 option=GetImageOption(image_info,"bias");
4233 if (option != (const char *) NULL)
4234 image->bias=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4235 option=GetImageOption(image_info,"black-point-compensation");
4236 if (option != (const char *) NULL)
4237 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4238 MagickBooleanOptions,MagickFalse,option);
4239 option=GetImageOption(image_info,"blue-primary");
4240 if (option != (const char *) NULL)
4242 flags=ParseGeometry(option,&geometry_info);
4243 image->chromaticity.blue_primary.x=geometry_info.rho;
4244 image->chromaticity.blue_primary.y=geometry_info.sigma;
4245 if ((flags & SigmaValue) == 0)
4246 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4248 option=GetImageOption(image_info,"bordercolor");
4249 if (option != (const char *) NULL)
4250 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4252 /* FUTURE: do not sync compose to per-image compose setting here */
4253 option=GetImageOption(image_info,"compose");
4254 if (option != (const char *) NULL)
4255 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4256 MagickFalse,option);
4258 option=GetImageOption(image_info,"compress");
4259 if (option != (const char *) NULL)
4260 image->compression=(CompressionType) ParseCommandOption(
4261 MagickCompressOptions,MagickFalse,option);
4262 option=GetImageOption(image_info,"debug");
4263 if (option != (const char *) NULL)
4264 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4265 MagickFalse,option);
4266 option=GetImageOption(image_info,"density");
4267 if (option != (const char *) NULL)
4272 flags=ParseGeometry(option,&geometry_info);
4273 image->resolution.x=geometry_info.rho;
4274 image->resolution.y=geometry_info.sigma;
4275 if ((flags & SigmaValue) == 0)
4276 image->resolution.y=image->resolution.x;
4278 option=GetImageOption(image_info,"depth");
4279 if (option != (const char *) NULL)
4280 image->depth=StringToUnsignedLong(option);
4281 option=GetImageOption(image_info,"endian");
4282 if (option != (const char *) NULL)
4283 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4284 MagickFalse,option);
4285 option=GetImageOption(image_info,"filter");
4286 if (option != (const char *) NULL)
4287 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4288 MagickFalse,option);
4289 option=GetImageOption(image_info,"fuzz");
4290 if (option != (const char *) NULL)
4291 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4292 option=GetImageOption(image_info,"gravity");
4293 if (option != (const char *) NULL)
4294 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4295 MagickFalse,option);
4296 option=GetImageOption(image_info,"green-primary");
4297 if (option != (const char *) NULL)
4299 flags=ParseGeometry(option,&geometry_info);
4300 image->chromaticity.green_primary.x=geometry_info.rho;
4301 image->chromaticity.green_primary.y=geometry_info.sigma;
4302 if ((flags & SigmaValue) == 0)
4303 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4305 option=GetImageOption(image_info,"intent");
4306 if (option != (const char *) NULL)
4307 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4308 MagickIntentOptions,MagickFalse,option);
4309 option=GetImageOption(image_info,"interlace");
4310 if (option != (const char *) NULL)
4311 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4312 MagickFalse,option);
4313 option=GetImageOption(image_info,"interpolate");
4314 if (option != (const char *) NULL)
4315 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4316 MagickInterpolateOptions,MagickFalse,option);
4317 option=GetImageOption(image_info,"loop");
4318 if (option != (const char *) NULL)
4319 image->iterations=StringToUnsignedLong(option);
4320 option=GetImageOption(image_info,"mattecolor");
4321 if (option != (const char *) NULL)
4322 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4324 option=GetImageOption(image_info,"orient");
4325 if (option != (const char *) NULL)
4326 image->orientation=(OrientationType) ParseCommandOption(
4327 MagickOrientationOptions,MagickFalse,option);
4328 option=GetImageOption(image_info,"page");
4329 if (option != (const char *) NULL)
4334 geometry=GetPageGeometry(option);
4335 flags=ParseAbsoluteGeometry(geometry,&image->page);
4336 geometry=DestroyString(geometry);
4338 option=GetImageOption(image_info,"quality");
4339 if (option != (const char *) NULL)
4340 image->quality=StringToUnsignedLong(option);
4341 option=GetImageOption(image_info,"red-primary");
4342 if (option != (const char *) NULL)
4344 flags=ParseGeometry(option,&geometry_info);
4345 image->chromaticity.red_primary.x=geometry_info.rho;
4346 image->chromaticity.red_primary.y=geometry_info.sigma;
4347 if ((flags & SigmaValue) == 0)
4348 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4350 if (image_info->quality != UndefinedCompressionQuality)
4351 image->quality=image_info->quality;
4352 option=GetImageOption(image_info,"scene");
4353 if (option != (const char *) NULL)
4354 image->scene=StringToUnsignedLong(option);
4355 option=GetImageOption(image_info,"taint");
4356 if (option != (const char *) NULL)
4357 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4358 MagickFalse,option);
4359 option=GetImageOption(image_info,"tile-offset");
4360 if (option != (const char *) NULL)
4365 geometry=GetPageGeometry(option);
4366 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4367 geometry=DestroyString(geometry);
4369 option=GetImageOption(image_info,"transparent-color");
4370 if (option != (const char *) NULL)
4371 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4373 option=GetImageOption(image_info,"type");
4374 if (option != (const char *) NULL)
4375 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4377 option=GetImageOption(image_info,"units");
4378 units=image_info->units;
4379 if (option != (const char *) NULL)
4380 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4381 MagickFalse,option);
4382 if (units != UndefinedResolution)
4384 if (image->units != units)
4385 switch (image->units)
4387 case PixelsPerInchResolution:
4389 if (units == PixelsPerCentimeterResolution)
4391 image->resolution.x/=2.54;
4392 image->resolution.y/=2.54;
4396 case PixelsPerCentimeterResolution:
4398 if (units == PixelsPerInchResolution)
4400 image->resolution.x=(double) ((size_t) (100.0*2.54*
4401 image->resolution.x+0.5))/100.0;
4402 image->resolution.y=(double) ((size_t) (100.0*2.54*
4403 image->resolution.y+0.5))/100.0;
4412 option=GetImageOption(image_info,"virtual-pixel");
4413 if (option != (const char *) NULL)
4414 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4415 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4417 option=GetImageOption(image_info,"white-point");
4418 if (option != (const char *) NULL)
4420 flags=ParseGeometry(option,&geometry_info);
4421 image->chromaticity.white_point.x=geometry_info.rho;
4422 image->chromaticity.white_point.y=geometry_info.sigma;
4423 if ((flags & SigmaValue) == 0)
4424 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4426 ResetImageOptionIterator(image_info);
4427 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4429 value=GetImageOption(image_info,option);
4430 if (value != (const char *) NULL)
4432 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4433 (void) SetImageArtifact(image,property,value);
4435 option=GetNextImageOption(image_info);