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-2011 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/memory_.h"
75 #include "MagickCore/module.h"
76 #include "MagickCore/monitor.h"
77 #include "MagickCore/monitor-private.h"
78 #include "MagickCore/option.h"
79 #include "MagickCore/paint.h"
80 #include "MagickCore/pixel-accessor.h"
81 #include "MagickCore/profile.h"
82 #include "MagickCore/property.h"
83 #include "MagickCore/quantize.h"
84 #include "MagickCore/random_.h"
85 #include "MagickCore/segment.h"
86 #include "MagickCore/semaphore.h"
87 #include "MagickCore/signature-private.h"
88 #include "MagickCore/statistic.h"
89 #include "MagickCore/string_.h"
90 #include "MagickCore/string-private.h"
91 #include "MagickCore/thread-private.h"
92 #include "MagickCore/threshold.h"
93 #include "MagickCore/timer.h"
94 #include "MagickCore/utility.h"
95 #include "MagickCore/version.h"
96 #include "MagickCore/xwindow-private.h"
102 BackgroundColor[] = "#ffffff", /* white */
103 BorderColor[] = "#dfdfdf", /* gray */
104 DefaultTileFrame[] = "15x15+3+3",
105 DefaultTileGeometry[] = "120x120+4+3>",
106 DefaultTileLabel[] = "%f\n%G\n%b",
107 ForegroundColor[] = "#000", /* black */
108 LoadImageTag[] = "Load/Image",
109 LoadImagesTag[] = "Load/Images",
110 MatteColor[] = "#bdbdbd", /* gray */
111 PSDensityGeometry[] = "72.0x72.0",
112 PSPageGeometry[] = "612x792",
113 SaveImageTag[] = "Save/Image",
114 SaveImagesTag[] = "Save/Images",
115 TransparentColor[] = "#00000000"; /* transparent black */
118 DefaultResolution = 72.0;
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 % A c q u i r e I m a g e %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % AcquireImage() returns a pointer to an image structure initialized to
134 % The format of the AcquireImage method is:
136 % Image *AcquireImage(const ImageInfo *image_info)
138 % A description of each parameter follows:
140 % o image_info: Many of the image default values are set from this
141 % structure. For example, filename, compression, depth, background color,
145 MagickExport Image *AcquireImage(const ImageInfo *image_info)
157 Allocate image structure.
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
160 image=(Image *) AcquireMagickMemory(sizeof(*image));
161 if (image == (Image *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 (void) ResetMagickMemory(image,0,sizeof(*image));
165 Initialize Image structure.
167 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
168 image->storage_class=DirectClass;
169 image->depth=MAGICKCORE_QUANTUM_DEPTH;
170 image->colorspace=RGBColorspace;
171 image->interlace=NoInterlace;
172 image->ticks_per_second=UndefinedTicksPerSecond;
173 image->compose=OverCompositeOp;
175 GetExceptionInfo(&image->exception);
176 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
178 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
179 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
180 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
182 image->x_resolution=DefaultResolution;
183 image->y_resolution=DefaultResolution;
184 image->units=PixelsPerInchResolution;
185 GetTimerInfo(&image->timer);
186 image->ping=MagickFalse;
187 image->cache=AcquirePixelCache(0);
188 image->channel_mask=DefaultChannels;
189 image->channel_map=AcquirePixelChannelMap();
190 image->blob=CloneBlobInfo((BlobInfo *) NULL);
191 image->debug=IsEventLogging();
192 image->reference_count=1;
193 image->semaphore=AllocateSemaphoreInfo();
194 image->signature=MagickSignature;
195 if (image_info == (ImageInfo *) NULL)
200 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
202 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
203 (void) CopyMagickString(image->magick_filename,image_info->filename,
205 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
206 if (image_info->size != (char *) NULL)
208 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
209 image->columns=image->extract_info.width;
210 image->rows=image->extract_info.height;
211 image->offset=image->extract_info.x;
212 image->extract_info.x=0;
213 image->extract_info.y=0;
215 if (image_info->extract != (char *) NULL)
220 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
221 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
223 image->extract_info=geometry;
224 Swap(image->columns,image->extract_info.width);
225 Swap(image->rows,image->extract_info.height);
228 image->compression=image_info->compression;
229 image->quality=image_info->quality;
230 image->endian=image_info->endian;
231 image->interlace=image_info->interlace;
232 image->units=image_info->units;
233 if (image_info->density != (char *) NULL)
238 flags=ParseGeometry(image_info->density,&geometry_info);
239 image->x_resolution=geometry_info.rho;
240 image->y_resolution=geometry_info.sigma;
241 if ((flags & SigmaValue) == 0)
242 image->y_resolution=image->x_resolution;
244 if (image_info->page != (char *) NULL)
249 image->page=image->extract_info;
250 geometry=GetPageGeometry(image_info->page);
251 (void) ParseAbsoluteGeometry(geometry,&image->page);
252 geometry=DestroyString(geometry);
254 if (image_info->depth != 0)
255 image->depth=image_info->depth;
256 image->dither=image_info->dither;
257 image->background_color=image_info->background_color;
258 image->border_color=image_info->border_color;
259 image->matte_color=image_info->matte_color;
260 image->transparent_color=image_info->transparent_color;
261 image->ping=image_info->ping;
262 image->progress_monitor=image_info->progress_monitor;
263 image->client_data=image_info->client_data;
264 if (image_info->cache != (void *) NULL)
265 ClonePixelCacheMethods(image->cache,image_info->cache);
266 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
267 (void) SyncImageSettings(image_info,image);
268 option=GetImageOption(image_info,"delay");
269 if (option != (const char *) NULL)
274 flags=ParseGeometry(option,&geometry_info);
275 if ((flags & GreaterValue) != 0)
277 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
278 image->delay=(size_t) floor(geometry_info.rho+0.5);
281 if ((flags & LessValue) != 0)
283 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
284 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
287 image->delay=(size_t) floor(geometry_info.rho+0.5);
288 if ((flags & SigmaValue) != 0)
289 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
291 option=GetImageOption(image_info,"dispose");
292 if (option != (const char *) NULL)
293 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % A c q u i r e I m a g e I n f o %
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % AcquireImageInfo() allocates the ImageInfo structure.
311 % The format of the AcquireImageInfo method is:
313 % ImageInfo *AcquireImageInfo(void)
316 MagickExport ImageInfo *AcquireImageInfo(void)
321 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
322 if (image_info == (ImageInfo *) NULL)
323 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
324 GetImageInfo(image_info);
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 % A c q u i r e N e x t I m a g e %
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 % AcquireNextImage() initializes the next image in a sequence to
340 % default values. The next member of image points to the newly allocated
341 % image. If there is a memory shortage, next is assigned NULL.
343 % The format of the AcquireNextImage method is:
345 % void AcquireNextImage(const ImageInfo *image_info,Image *image)
347 % A description of each parameter follows:
349 % o image_info: Many of the image default values are set from this
350 % structure. For example, filename, compression, depth, background color,
353 % o image: the image.
356 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
359 Allocate image structure.
361 assert(image != (Image *) NULL);
362 assert(image->signature == MagickSignature);
363 if (image->debug != MagickFalse)
364 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
365 image->next=AcquireImage(image_info);
366 if (GetNextImageInList(image) == (Image *) NULL)
368 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
370 if (image_info != (ImageInfo *) NULL)
371 (void) CopyMagickString(GetNextImageInList(image)->filename,
372 image_info->filename,MaxTextExtent);
373 DestroyBlob(GetNextImageInList(image));
374 image->next->blob=ReferenceBlob(image->blob);
375 image->next->endian=image->endian;
376 image->next->scene=image->scene+1;
377 image->next->previous=image;
381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 % A p p e n d I m a g e s %
389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
391 % AppendImages() takes all images from the current image pointer to the end
392 % of the image list and appends them to each other top-to-bottom if the
393 % stack parameter is true, otherwise left-to-right.
395 % The current gravity setting now effects how the image is justified in the
398 % The format of the AppendImages method is:
400 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
401 % ExceptionInfo *exception)
403 % A description of each parameter follows:
405 % o images: the image sequence.
407 % o stack: A value other than 0 stacks the images top-to-bottom.
409 % o exception: return any errors or warnings in this structure.
412 MagickExport Image *AppendImages(const Image *images,
413 const MagickBooleanType stack,ExceptionInfo *exception)
415 #define AppendImageTag "Append/Image"
452 Compute maximum area of appended area.
454 assert(images != (Image *) NULL);
455 assert(images->signature == MagickSignature);
456 if (images->debug != MagickFalse)
457 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
458 assert(exception != (ExceptionInfo *) NULL);
459 assert(exception->signature == MagickSignature);
463 width=image->columns;
465 next=GetNextImageInList(image);
466 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
468 if (next->matte != MagickFalse)
471 if (stack != MagickFalse)
473 if (next->columns > width)
478 width+=next->columns;
479 if (next->rows > height)
485 append_image=CloneImage(image,width,height,MagickTrue,exception);
486 if (append_image == (Image *) NULL)
487 return((Image *) NULL);
488 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
490 append_image=DestroyImage(append_image);
491 return((Image *) NULL);
493 append_image->matte=matte;
494 (void) SetImageBackgroundColor(append_image);
498 append_view=AcquireCacheView(append_image);
499 for (n=0; n < (MagickOffsetType) number_images; n++)
501 SetGeometry(append_image,&geometry);
502 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
503 if (stack != MagickFalse)
504 x_offset-=geometry.x;
506 y_offset-=geometry.y;
507 image_view=AcquireCacheView(image);
508 #if defined(MAGICKCORE_OPENMP_SUPPORT)
509 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
511 for (y=0; y < (ssize_t) image->rows; y++)
516 register const Quantum
525 if (status == MagickFalse)
527 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
528 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
529 image->columns,1,exception);
530 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
535 for (x=0; x < (ssize_t) image->columns; x++)
537 SetPixelRed(append_image,GetPixelRed(image,p),q);
538 SetPixelGreen(append_image,GetPixelGreen(image,p),q);
539 SetPixelBlue(append_image,GetPixelBlue(image,p),q);
540 if ((image->colorspace == CMYKColorspace) &&
541 (append_image->colorspace == CMYKColorspace))
542 SetPixelBlack(append_image,GetPixelBlack(image,p),q);
543 SetPixelAlpha(append_image,OpaqueAlpha,q);
544 if (image->matte != MagickFalse)
545 SetPixelAlpha(append_image,GetPixelAlpha(image,p),q);
546 p+=GetPixelChannels(image);
547 q+=GetPixelChannels(append_image);
549 sync=SyncCacheViewAuthenticPixels(append_view,exception);
550 if (sync == MagickFalse)
553 image_view=DestroyCacheView(image_view);
554 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
555 if (proceed == MagickFalse)
557 if (stack == MagickFalse)
559 x_offset+=(ssize_t) image->columns;
565 y_offset+=(ssize_t) image->rows;
567 image=GetNextImageInList(image);
569 append_view=DestroyCacheView(append_view);
570 if (status == MagickFalse)
571 append_image=DestroyImage(append_image);
572 return(append_image);
576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
580 % C a t c h I m a g e E x c e p t i o n %
584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
586 % CatchImageException() returns if no exceptions are found in the image
587 % sequence, otherwise it determines the most severe exception and reports
588 % it as a warning or error depending on the severity.
590 % The format of the CatchImageException method is:
592 % ExceptionType CatchImageException(Image *image)
594 % A description of each parameter follows:
596 % o image: An image sequence.
599 MagickExport ExceptionType CatchImageException(Image *image)
607 assert(image != (const Image *) NULL);
608 assert(image->signature == MagickSignature);
609 if (image->debug != MagickFalse)
610 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
611 exception=AcquireExceptionInfo();
612 GetImageException(image,exception);
613 CatchException(exception);
614 severity=exception->severity;
615 exception=DestroyExceptionInfo(exception);
620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624 % C l i p I m a g e P a t h %
628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 % ClipImagePath() sets the image clip mask based any clipping path information
633 % The format of the ClipImagePath method is:
635 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
636 % const MagickBooleanType inside)
638 % A description of each parameter follows:
640 % o image: the image.
642 % o pathname: name of clipping path resource. If name is preceded by #, use
643 % clipping path numbered by name.
645 % o inside: if non-zero, later operations take effect inside clipping path.
646 % Otherwise later operations take effect outside clipping path.
650 MagickExport MagickBooleanType ClipImage(Image *image)
652 return(ClipImagePath(image,"#1",MagickTrue));
655 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
656 const MagickBooleanType inside)
658 #define ClipImagePathTag "ClipPath/Image"
672 assert(image != (const Image *) NULL);
673 assert(image->signature == MagickSignature);
674 if (image->debug != MagickFalse)
675 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
676 assert(pathname != NULL);
677 property=AcquireString(pathname);
678 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
680 value=GetImageProperty(image,property);
681 property=DestroyString(property);
682 if (value == (const char *) NULL)
684 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
688 image_info=AcquireImageInfo();
689 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
690 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
691 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
692 image_info=DestroyImageInfo(image_info);
693 if (clip_mask == (Image *) NULL)
695 if (clip_mask->storage_class == PseudoClass)
697 (void) SyncImage(clip_mask);
698 if (SetImageStorageClass(clip_mask,DirectClass,&image->exception) == MagickFalse)
701 if (inside == MagickFalse)
702 (void) NegateImage(clip_mask,MagickFalse,&image->exception);
703 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
704 "8BIM:1999,2998:%s\nPS",pathname);
705 (void) SetImageClipMask(image,clip_mask);
706 clip_mask=DestroyImage(clip_mask);
711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
715 % C l o n e I m a g e %
719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
721 % CloneImage() copies an image and returns the copy as a new image object.
723 % If the specified columns and rows is 0, an exact copy of the image is
724 % returned, otherwise the pixel data is undefined and must be initialized
725 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
726 % failure, a NULL image is returned and exception describes the reason for the
729 % The format of the CloneImage method is:
731 % Image *CloneImage(const Image *image,const size_t columns,
732 % const size_t rows,const MagickBooleanType orphan,
733 % ExceptionInfo *exception)
735 % A description of each parameter follows:
737 % o image: the image.
739 % o columns: the number of columns in the cloned image.
741 % o rows: the number of rows in the cloned image.
743 % o detach: With a value other than 0, the cloned image is detached from
744 % its parent I/O stream.
746 % o exception: return any errors or warnings in this structure.
749 MagickExport Image *CloneImage(const Image *image,const size_t columns,
750 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
764 assert(image != (const Image *) NULL);
765 assert(image->signature == MagickSignature);
766 if (image->debug != MagickFalse)
767 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
768 assert(exception != (ExceptionInfo *) NULL);
769 assert(exception->signature == MagickSignature);
770 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
771 if (clone_image == (Image *) NULL)
772 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
773 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
774 clone_image->signature=MagickSignature;
775 clone_image->storage_class=image->storage_class;
776 clone_image->number_channels=image->number_channels;
777 clone_image->number_meta_channels=image->number_meta_channels;
778 clone_image->metacontent_extent=image->metacontent_extent;
779 clone_image->colorspace=image->colorspace;
780 clone_image->matte=image->matte;
781 clone_image->columns=image->columns;
782 clone_image->rows=image->rows;
783 clone_image->dither=image->dither;
784 if (image->colormap != (PixelPacket *) NULL)
787 Allocate and copy the image colormap.
789 clone_image->colors=image->colors;
790 length=(size_t) image->colors;
791 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
792 sizeof(*clone_image->colormap));
793 if (clone_image->colormap == (PixelPacket *) NULL)
794 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
795 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
796 sizeof(*clone_image->colormap));
798 (void) CloneImageProfiles(clone_image,image);
799 (void) CloneImageProperties(clone_image,image);
800 (void) CloneImageArtifacts(clone_image,image);
801 GetTimerInfo(&clone_image->timer);
802 GetExceptionInfo(&clone_image->exception);
803 InheritException(&clone_image->exception,&image->exception);
804 if (image->ascii85 != (void *) NULL)
805 Ascii85Initialize(clone_image);
806 clone_image->magick_columns=image->magick_columns;
807 clone_image->magick_rows=image->magick_rows;
808 clone_image->type=image->type;
809 clone_image->sync=image->sync;
810 clone_image->channel_mask=image->channel_mask;
811 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
812 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
814 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
815 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
816 clone_image->progress_monitor=image->progress_monitor;
817 clone_image->client_data=image->client_data;
818 clone_image->reference_count=1;
819 clone_image->next=image->next;
820 clone_image->previous=image->previous;
821 clone_image->list=NewImageList();
822 clone_image->clip_mask=NewImageList();
823 clone_image->mask=NewImageList();
824 if (detach == MagickFalse)
825 clone_image->blob=ReferenceBlob(image->blob);
828 clone_image->next=NewImageList();
829 clone_image->previous=NewImageList();
830 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
832 clone_image->ping=image->ping;
833 clone_image->debug=IsEventLogging();
834 clone_image->semaphore=AllocateSemaphoreInfo();
835 if ((columns == 0) && (rows == 0))
837 if (image->montage != (char *) NULL)
838 (void) CloneString(&clone_image->montage,image->montage);
839 if (image->directory != (char *) NULL)
840 (void) CloneString(&clone_image->directory,image->directory);
841 if (image->clip_mask != (Image *) NULL)
842 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
844 if (image->mask != (Image *) NULL)
845 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
846 clone_image->cache=ReferencePixelCache(image->cache);
849 if ((columns == image->columns) && (rows == image->rows))
851 if (image->clip_mask != (Image *) NULL)
852 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
854 if (image->mask != (Image *) NULL)
855 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
857 scale=(MagickRealType) columns/(MagickRealType) image->columns;
858 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
859 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
860 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
861 scale=(MagickRealType) rows/(MagickRealType) image->rows;
862 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
863 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
864 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
865 clone_image->columns=columns;
866 clone_image->rows=rows;
867 clone_image->cache=ClonePixelCache(image->cache);
872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876 % C l o n e I m a g e I n f o %
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 % CloneImageInfo() makes a copy of the given image info structure. If
883 % NULL is specified, a new image info structure is created initialized to
886 % The format of the CloneImageInfo method is:
888 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
890 % A description of each parameter follows:
892 % o image_info: the image info.
895 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
900 clone_info=AcquireImageInfo();
901 if (image_info == (ImageInfo *) NULL)
903 clone_info->compression=image_info->compression;
904 clone_info->temporary=image_info->temporary;
905 clone_info->adjoin=image_info->adjoin;
906 clone_info->antialias=image_info->antialias;
907 clone_info->scene=image_info->scene;
908 clone_info->number_scenes=image_info->number_scenes;
909 clone_info->depth=image_info->depth;
910 if (image_info->size != (char *) NULL)
911 (void) CloneString(&clone_info->size,image_info->size);
912 if (image_info->extract != (char *) NULL)
913 (void) CloneString(&clone_info->extract,image_info->extract);
914 if (image_info->scenes != (char *) NULL)
915 (void) CloneString(&clone_info->scenes,image_info->scenes);
916 if (image_info->page != (char *) NULL)
917 (void) CloneString(&clone_info->page,image_info->page);
918 clone_info->interlace=image_info->interlace;
919 clone_info->endian=image_info->endian;
920 clone_info->units=image_info->units;
921 clone_info->quality=image_info->quality;
922 if (image_info->sampling_factor != (char *) NULL)
923 (void) CloneString(&clone_info->sampling_factor,
924 image_info->sampling_factor);
925 if (image_info->server_name != (char *) NULL)
926 (void) CloneString(&clone_info->server_name,image_info->server_name);
927 if (image_info->font != (char *) NULL)
928 (void) CloneString(&clone_info->font,image_info->font);
929 if (image_info->texture != (char *) NULL)
930 (void) CloneString(&clone_info->texture,image_info->texture);
931 if (image_info->density != (char *) NULL)
932 (void) CloneString(&clone_info->density,image_info->density);
933 clone_info->pointsize=image_info->pointsize;
934 clone_info->fuzz=image_info->fuzz;
935 clone_info->background_color=image_info->background_color;
936 clone_info->border_color=image_info->border_color;
937 clone_info->matte_color=image_info->matte_color;
938 clone_info->transparent_color=image_info->transparent_color;
939 clone_info->dither=image_info->dither;
940 clone_info->monochrome=image_info->monochrome;
941 clone_info->colors=image_info->colors;
942 clone_info->colorspace=image_info->colorspace;
943 clone_info->type=image_info->type;
944 clone_info->orientation=image_info->orientation;
945 clone_info->preview_type=image_info->preview_type;
946 clone_info->group=image_info->group;
947 clone_info->ping=image_info->ping;
948 clone_info->verbose=image_info->verbose;
949 if (image_info->view != (char *) NULL)
950 (void) CloneString(&clone_info->view,image_info->view);
951 if (image_info->authenticate != (char *) NULL)
952 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
953 (void) CloneImageOptions(clone_info,image_info);
954 clone_info->progress_monitor=image_info->progress_monitor;
955 clone_info->client_data=image_info->client_data;
956 clone_info->cache=image_info->cache;
957 if (image_info->cache != (void *) NULL)
958 clone_info->cache=ReferencePixelCache(image_info->cache);
959 if (image_info->profile != (void *) NULL)
960 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
961 image_info->profile);
962 SetImageInfoFile(clone_info,image_info->file);
963 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
964 clone_info->stream=image_info->stream;
965 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
966 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
967 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
968 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
969 (void) CopyMagickString(clone_info->filename,image_info->filename,
971 clone_info->channel=image_info->channel;
972 clone_info->debug=IsEventLogging();
973 clone_info->signature=image_info->signature;
978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
982 % C o m b i n e I m a g e s %
986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
988 % CombineImages() combines one or more images into a single image. The
989 % grayscale value of the pixels of each image in the sequence is assigned in
990 % order to the specified channels of the combined image. The typical
991 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
993 % The format of the CombineImages method is:
995 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
997 % A description of each parameter follows:
999 % o image: the image.
1001 % o exception: return any errors or warnings in this structure.
1004 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1006 #define CombineImageTag "Combine/Image"
1027 Ensure the image are the same size.
1029 assert(image != (const Image *) NULL);
1030 assert(image->signature == MagickSignature);
1031 if (image->debug != MagickFalse)
1032 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1033 assert(exception != (ExceptionInfo *) NULL);
1034 assert(exception->signature == MagickSignature);
1035 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1037 if ((next->columns != image->columns) || (next->rows != image->rows))
1038 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1040 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1041 if (combine_image == (Image *) NULL)
1042 return((Image *) NULL);
1043 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1045 combine_image=DestroyImage(combine_image);
1046 return((Image *) NULL);
1048 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1049 combine_image->matte=MagickTrue;
1050 (void) SetImageBackgroundColor(combine_image);
1056 combine_view=AcquireCacheView(combine_image);
1057 for (y=0; y < (ssize_t) combine_image->rows; y++)
1068 register const Quantum
1077 if (status == MagickFalse)
1079 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1081 if (pixels == (Quantum *) NULL)
1087 if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) &&
1088 (next != (Image *) NULL))
1090 image_view=AcquireCacheView(next);
1091 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1092 if (p == (const Quantum *) NULL)
1095 for (x=0; x < (ssize_t) combine_image->columns; x++)
1097 SetPixelRed(image,GetPixelIntensity(image,p),q);
1098 p+=GetPixelChannels(image);
1099 q+=GetPixelChannels(combine_image);
1101 image_view=DestroyCacheView(image_view);
1102 next=GetNextImageInList(next);
1104 if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) &&
1105 (next != (Image *) NULL))
1107 image_view=AcquireCacheView(next);
1108 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1109 if (p == (const Quantum *) NULL)
1112 for (x=0; x < (ssize_t) combine_image->columns; x++)
1114 SetPixelGreen(image,GetPixelIntensity(image,p),q);
1115 p+=GetPixelChannels(image);
1116 q+=GetPixelChannels(combine_image);
1118 image_view=DestroyCacheView(image_view);
1119 next=GetNextImageInList(next);
1121 if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) &&
1122 (next != (Image *) NULL))
1124 image_view=AcquireCacheView(next);
1125 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1126 if (p == (const Quantum *) NULL)
1129 for (x=0; x < (ssize_t) combine_image->columns; x++)
1131 SetPixelBlue(image,GetPixelIntensity(image,p),q);
1132 p+=GetPixelChannels(image);
1133 q+=GetPixelChannels(combine_image);
1135 image_view=DestroyCacheView(image_view);
1136 next=GetNextImageInList(next);
1138 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
1139 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1141 image_view=AcquireCacheView(next);
1142 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1143 if (p == (const Quantum *) NULL)
1146 for (x=0; x < (ssize_t) combine_image->columns; x++)
1148 SetPixelBlack(image,GetPixelIntensity(image,p),q);
1149 p+=GetPixelChannels(image);
1150 q+=GetPixelChannels(combine_image);
1152 image_view=DestroyCacheView(image_view);
1153 next=GetNextImageInList(next);
1155 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
1156 (next != (Image *) NULL))
1158 image_view=AcquireCacheView(next);
1159 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1160 if (p == (const Quantum *) NULL)
1163 for (x=0; x < (ssize_t) combine_image->columns; x++)
1165 SetPixelAlpha(image,GetPixelIntensity(image,p),q);
1166 p+=GetPixelChannels(image);
1167 q+=GetPixelChannels(combine_image);
1169 image_view=DestroyCacheView(image_view);
1170 next=GetNextImageInList(next);
1172 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1174 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1179 proceed=SetImageProgress(image,CombineImageTag,progress++,
1180 combine_image->rows);
1181 if (proceed == MagickFalse)
1185 combine_view=DestroyCacheView(combine_view);
1186 if (status == MagickFalse)
1187 combine_image=DestroyImage(combine_image);
1188 return(combine_image);
1192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1196 % D e s t r o y I m a g e %
1200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1202 % DestroyImage() dereferences an image, deallocating memory associated with
1203 % the image if the reference count becomes zero.
1205 % The format of the DestroyImage method is:
1207 % Image *DestroyImage(Image *image)
1209 % A description of each parameter follows:
1211 % o image: the image.
1214 MagickExport Image *DestroyImage(Image *image)
1222 assert(image != (Image *) NULL);
1223 assert(image->signature == MagickSignature);
1224 if (image->debug != MagickFalse)
1225 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1226 destroy=MagickFalse;
1227 LockSemaphoreInfo(image->semaphore);
1228 image->reference_count--;
1229 if (image->reference_count == 0)
1231 UnlockSemaphoreInfo(image->semaphore);
1232 if (destroy == MagickFalse)
1233 return((Image *) NULL);
1237 DestroyImagePixels(image);
1238 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1239 if (image->clip_mask != (Image *) NULL)
1240 image->clip_mask=DestroyImage(image->clip_mask);
1241 if (image->mask != (Image *) NULL)
1242 image->mask=DestroyImage(image->mask);
1243 if (image->montage != (char *) NULL)
1244 image->montage=DestroyString(image->montage);
1245 if (image->directory != (char *) NULL)
1246 image->directory=DestroyString(image->directory);
1247 if (image->colormap != (PixelPacket *) NULL)
1248 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1249 if (image->geometry != (char *) NULL)
1250 image->geometry=DestroyString(image->geometry);
1251 DestroyImageProfiles(image);
1252 DestroyImageProperties(image);
1253 DestroyImageArtifacts(image);
1254 if (image->ascii85 != (Ascii85Info*) NULL)
1255 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1257 (void) DestroyExceptionInfo(&image->exception);
1258 if (image->semaphore != (SemaphoreInfo *) NULL)
1259 DestroySemaphoreInfo(&image->semaphore);
1260 image->signature=(~MagickSignature);
1261 image=(Image *) RelinquishMagickMemory(image);
1266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1270 % D e s t r o y I m a g e I n f o %
1274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1276 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1279 % The format of the DestroyImageInfo method is:
1281 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1283 % A description of each parameter follows:
1285 % o image_info: the image info.
1288 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1290 assert(image_info != (ImageInfo *) NULL);
1291 assert(image_info->signature == MagickSignature);
1292 if (image_info->debug != MagickFalse)
1293 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1294 image_info->filename);
1295 if (image_info->size != (char *) NULL)
1296 image_info->size=DestroyString(image_info->size);
1297 if (image_info->extract != (char *) NULL)
1298 image_info->extract=DestroyString(image_info->extract);
1299 if (image_info->scenes != (char *) NULL)
1300 image_info->scenes=DestroyString(image_info->scenes);
1301 if (image_info->page != (char *) NULL)
1302 image_info->page=DestroyString(image_info->page);
1303 if (image_info->sampling_factor != (char *) NULL)
1304 image_info->sampling_factor=DestroyString(
1305 image_info->sampling_factor);
1306 if (image_info->server_name != (char *) NULL)
1307 image_info->server_name=DestroyString(
1308 image_info->server_name);
1309 if (image_info->font != (char *) NULL)
1310 image_info->font=DestroyString(image_info->font);
1311 if (image_info->texture != (char *) NULL)
1312 image_info->texture=DestroyString(image_info->texture);
1313 if (image_info->density != (char *) NULL)
1314 image_info->density=DestroyString(image_info->density);
1315 if (image_info->view != (char *) NULL)
1316 image_info->view=DestroyString(image_info->view);
1317 if (image_info->authenticate != (char *) NULL)
1318 image_info->authenticate=DestroyString(
1319 image_info->authenticate);
1320 DestroyImageOptions(image_info);
1321 if (image_info->cache != (void *) NULL)
1322 image_info->cache=DestroyPixelCache(image_info->cache);
1323 if (image_info->profile != (StringInfo *) NULL)
1324 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1325 image_info->profile);
1326 image_info->signature=(~MagickSignature);
1327 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1336 + D i s a s s o c i a t e I m a g e S t r e a m %
1340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342 % DisassociateImageStream() disassociates the image stream.
1344 % The format of the DisassociateImageStream method is:
1346 % MagickBooleanType DisassociateImageStream(const Image *image)
1348 % A description of each parameter follows:
1350 % o image: the image.
1353 MagickExport void DisassociateImageStream(Image *image)
1355 assert(image != (const Image *) NULL);
1356 assert(image->signature == MagickSignature);
1357 if (image->debug != MagickFalse)
1358 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1359 (void) DetachBlob(image->blob);
1363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1367 % G e t I m a g e A l p h a C h a n n e l %
1371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1373 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1374 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1377 % The format of the GetImageAlphaChannel method is:
1379 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1381 % A description of each parameter follows:
1383 % o image: the image.
1386 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1388 assert(image != (const Image *) NULL);
1389 if (image->debug != MagickFalse)
1390 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1391 assert(image->signature == MagickSignature);
1392 return(image->matte);
1396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1400 % G e t I m a g e C l i p M a s k %
1404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1406 % GetImageClipMask() returns the clip path associated with the image.
1408 % The format of the GetImageClipMask method is:
1410 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1412 % A description of each parameter follows:
1414 % o image: the image.
1417 MagickExport Image *GetImageClipMask(const Image *image,
1418 ExceptionInfo *exception)
1420 assert(image != (const Image *) NULL);
1421 if (image->debug != MagickFalse)
1422 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1423 assert(image->signature == MagickSignature);
1424 if (image->clip_mask == (Image *) NULL)
1425 return((Image *) NULL);
1426 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1434 % G e t I m a g e E x c e p t i o n %
1438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1440 % GetImageException() traverses an image sequence and returns any
1441 % error more severe than noted by the exception parameter.
1443 % The format of the GetImageException method is:
1445 % void GetImageException(Image *image,ExceptionInfo *exception)
1447 % A description of each parameter follows:
1449 % o image: Specifies a pointer to a list of one or more images.
1451 % o exception: return the highest severity exception.
1454 MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1459 assert(image != (Image *) NULL);
1460 assert(image->signature == MagickSignature);
1461 if (image->debug != MagickFalse)
1462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1463 assert(exception != (ExceptionInfo *) NULL);
1464 assert(exception->signature == MagickSignature);
1465 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1467 if (next->exception.severity == UndefinedException)
1469 if (next->exception.severity > exception->severity)
1470 InheritException(exception,&next->exception);
1471 next->exception.severity=UndefinedException;
1476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1480 % G e t I m a g e I n f o %
1484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1486 % GetImageInfo() initializes image_info to default values.
1488 % The format of the GetImageInfo method is:
1490 % void GetImageInfo(ImageInfo *image_info)
1492 % A description of each parameter follows:
1494 % o image_info: the image info.
1497 MagickExport void GetImageInfo(ImageInfo *image_info)
1506 File and image dimension members.
1508 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1509 assert(image_info != (ImageInfo *) NULL);
1510 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1511 image_info->adjoin=MagickTrue;
1512 image_info->interlace=NoInterlace;
1513 image_info->channel=DefaultChannels;
1514 image_info->quality=UndefinedCompressionQuality;
1515 image_info->antialias=MagickTrue;
1516 image_info->dither=MagickTrue;
1517 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1518 if (synchronize != (const char *) NULL)
1519 image_info->synchronize=IsMagickTrue(synchronize);
1520 exception=AcquireExceptionInfo();
1521 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1523 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1524 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1525 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1527 exception=DestroyExceptionInfo(exception);
1528 image_info->debug=IsEventLogging();
1529 image_info->signature=MagickSignature;
1533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 % G e t I m a g e I n f o F i l e %
1541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1543 % GetImageInfoFile() returns the image info file member.
1545 % The format of the GetImageInfoFile method is:
1547 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1549 % A description of each parameter follows:
1551 % o image_info: the image info.
1554 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1556 return(image_info->file);
1560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1564 % G e t I m a g e M a s k %
1568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1570 % GetImageMask() returns the mask associated with the image.
1572 % The format of the GetImageMask method is:
1574 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1576 % A description of each parameter follows:
1578 % o image: the image.
1581 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1583 assert(image != (const Image *) NULL);
1584 if (image->debug != MagickFalse)
1585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1586 assert(image->signature == MagickSignature);
1587 if (image->mask == (Image *) NULL)
1588 return((Image *) NULL);
1589 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1597 + G e t I m a g e R e f e r e n c e C o u n t %
1601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1603 % GetImageReferenceCount() returns the image reference count.
1605 % The format of the GetReferenceCount method is:
1607 % ssize_t GetImageReferenceCount(Image *image)
1609 % A description of each parameter follows:
1611 % o image: the image.
1614 MagickExport ssize_t GetImageReferenceCount(Image *image)
1619 assert(image != (Image *) NULL);
1620 assert(image->signature == MagickSignature);
1621 if (image->debug != MagickFalse)
1622 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1623 LockSemaphoreInfo(image->semaphore);
1624 reference_count=image->reference_count;
1625 UnlockSemaphoreInfo(image->semaphore);
1626 return(reference_count);
1630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1634 % 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 %
1638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1641 % image. A virtual pixel is any pixel access that is outside the boundaries
1642 % of the image cache.
1644 % The format of the GetImageVirtualPixelMethod() method is:
1646 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1648 % A description of each parameter follows:
1650 % o image: the image.
1653 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1655 assert(image != (Image *) NULL);
1656 assert(image->signature == MagickSignature);
1657 if (image->debug != MagickFalse)
1658 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1659 return(GetPixelCacheVirtualMethod(image));
1663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1667 % I n t e r p r e t I m a g e F i l e n a m e %
1671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1673 % InterpretImageFilename() interprets embedded characters in an image filename.
1674 % The filename length is returned.
1676 % The format of the InterpretImageFilename method is:
1678 % size_t InterpretImageFilename(const ImageInfo *image_info,
1679 % Image *image,const char *format,int value,char *filename)
1681 % A description of each parameter follows.
1683 % o image_info: the image info..
1685 % o image: the image.
1687 % o format: A filename describing the format to use to write the numeric
1688 % argument. Only the first numeric format identifier is replaced.
1690 % o value: Numeric value to substitute into format filename.
1692 % o filename: return the formatted filename in this character buffer.
1695 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1696 Image *image,const char *format,int value,char *filename)
1713 canonical=MagickFalse;
1715 (void) CopyMagickString(filename,format,MaxTextExtent);
1716 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1729 value=(ssize_t) strtol(q,&q,10);
1741 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1742 (p-format)),p,value);
1744 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1745 canonical=MagickTrue;
1754 pattern[MaxTextExtent];
1771 if (strchr(p,']') == (char *) NULL)
1775 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1786 if (LocaleNCompare(pattern,"filename:",9) != 0)
1788 value=(const char *) NULL;
1789 if ((image_info != (const ImageInfo *) NULL) &&
1790 (image != (const Image *) NULL))
1791 value=GetMagickProperty(image_info,image,pattern);
1793 if (image != (Image *) NULL)
1794 value=GetImageProperty(image,pattern);
1796 if (image_info != (ImageInfo *) NULL)
1797 value=GetImageOption(image_info,pattern);
1798 if (value == (const char *) NULL)
1803 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1804 (MaxTextExtent-(p-format-length)));
1805 length+=strlen(pattern)-1;
1807 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1808 canonical=MagickTrue;
1818 for (q=filename; *q != '\0'; q++)
1819 if ((*q == '%') && (*(q+1) == '%'))
1821 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1822 canonical=MagickTrue;
1824 if (canonical == MagickFalse)
1825 (void) CopyMagickString(filename,format,MaxTextExtent);
1826 return(strlen(filename));
1830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1834 % I s H i g h D y n a m i c R a n g e I m a g e %
1838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1840 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1841 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1844 % The format of the IsHighDynamicRangeImage method is:
1846 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1847 % ExceptionInfo *exception)
1849 % A description of each parameter follows:
1851 % o image: the image.
1853 % o exception: return any errors or warnings in this structure.
1856 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1857 ExceptionInfo *exception)
1859 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1862 return(MagickFalse);
1876 assert(image != (Image *) NULL);
1877 assert(image->signature == MagickSignature);
1878 if (image->debug != MagickFalse)
1879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1881 GetPixelInfo(image,&zero);
1882 image_view=AcquireCacheView(image);
1883 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1884 #pragma omp parallel for schedule(dynamic,4) shared(status)
1886 for (y=0; y < (ssize_t) image->rows; y++)
1891 register const Quantum
1897 if (status == MagickFalse)
1899 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1900 if (p == (const Quantum *) NULL)
1906 for (x=0; x < (ssize_t) image->columns; x++)
1908 SetPixelInfo(image,p,&pixel);
1909 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1910 (pixel.red != (QuantumAny) pixel.red))
1912 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1913 (pixel.green != (QuantumAny) pixel.green))
1915 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1916 (pixel.blue != (QuantumAny) pixel.blue))
1918 if (pixel.colorspace == CMYKColorspace)
1920 if ((pixel.black < 0.0) || (pixel.black > QuantumRange) ||
1921 (pixel.black != (QuantumAny) pixel.black))
1924 if (pixel.matte != MagickFalse)
1926 if ((pixel.alpha < 0.0) || (pixel.alpha > QuantumRange) ||
1927 (pixel.alpha != (QuantumAny) pixel.alpha))
1930 p+=GetPixelChannels(image);
1932 if (x < (ssize_t) image->columns)
1935 image_view=DestroyCacheView(image_view);
1936 return(status != MagickFalse ? MagickFalse : MagickTrue);
1941 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1945 % I s I m a g e O b j e c t %
1949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1951 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1952 % set of image objects.
1954 % The format of the IsImageObject method is:
1956 % MagickBooleanType IsImageObject(const Image *image)
1958 % A description of each parameter follows:
1960 % o image: the image.
1963 MagickExport MagickBooleanType IsImageObject(const Image *image)
1965 register const Image
1968 assert(image != (Image *) NULL);
1969 if (image->debug != MagickFalse)
1970 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1971 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1972 if (p->signature != MagickSignature)
1973 return(MagickFalse);
1978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1982 % I s T a i n t I m a g e %
1986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1988 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1989 % since it was first constituted.
1991 % The format of the IsTaintImage method is:
1993 % MagickBooleanType IsTaintImage(const Image *image)
1995 % A description of each parameter follows:
1997 % o image: the image.
2000 MagickExport MagickBooleanType IsTaintImage(const Image *image)
2003 magick[MaxTextExtent],
2004 filename[MaxTextExtent];
2006 register const Image
2009 assert(image != (Image *) NULL);
2010 if (image->debug != MagickFalse)
2011 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2012 assert(image->signature == MagickSignature);
2013 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2014 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2015 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2017 if (p->taint != MagickFalse)
2019 if (LocaleCompare(p->magick,magick) != 0)
2021 if (LocaleCompare(p->filename,filename) != 0)
2024 return(MagickFalse);
2028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2032 % M o d i f y I m a g e %
2036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2038 % ModifyImage() ensures that there is only a single reference to the image
2039 % to be modified, updating the provided image pointer to point to a clone of
2040 % the original image if necessary.
2042 % The format of the ModifyImage method is:
2044 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2046 % A description of each parameter follows:
2048 % o image: the image.
2050 % o exception: return any errors or warnings in this structure.
2053 MagickExport MagickBooleanType ModifyImage(Image **image,
2054 ExceptionInfo *exception)
2059 assert(image != (Image **) NULL);
2060 assert(*image != (Image *) NULL);
2061 assert((*image)->signature == MagickSignature);
2062 if ((*image)->debug != MagickFalse)
2063 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2064 if (GetImageReferenceCount(*image) <= 1)
2066 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2067 LockSemaphoreInfo((*image)->semaphore);
2068 (*image)->reference_count--;
2069 UnlockSemaphoreInfo((*image)->semaphore);
2075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2079 % N e w M a g i c k I m a g e %
2083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2085 % NewMagickImage() creates a blank image canvas of the specified size and
2088 % The format of the NewMagickImage method is:
2090 % Image *NewMagickImage(const ImageInfo *image_info,
2091 % const size_t width,const size_t height,
2092 % const PixelInfo *background)
2094 % A description of each parameter follows:
2096 % o image: the image.
2098 % o width: the image width.
2100 % o height: the image height.
2102 % o background: the image color.
2105 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2106 const size_t width,const size_t height,
2107 const PixelInfo *background)
2124 assert(image_info != (const ImageInfo *) NULL);
2125 if (image_info->debug != MagickFalse)
2126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2127 assert(image_info->signature == MagickSignature);
2128 assert(background != (const PixelInfo *) NULL);
2129 image=AcquireImage(image_info);
2130 image->columns=width;
2132 image->colorspace=background->colorspace;
2133 image->matte=background->matte;
2134 image->fuzz=background->fuzz;
2135 image->depth=background->depth;
2137 exception=(&image->exception);
2138 image_view=AcquireCacheView(image);
2139 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2140 #pragma omp parallel for schedule(dynamic,4) shared(status)
2142 for (y=0; y < (ssize_t) image->rows; y++)
2150 if (status == MagickFalse)
2152 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2153 if (q == (Quantum *) NULL)
2158 for (x=0; x < (ssize_t) image->columns; x++)
2160 SetPixelPixelInfo(image,background,q);
2161 q+=GetPixelChannels(image);
2163 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2166 image_view=DestroyCacheView(image_view);
2167 if (status == MagickFalse)
2168 image=DestroyImage(image);
2173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2177 % R e f e r e n c e I m a g e %
2181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2183 % ReferenceImage() increments the reference count associated with an image
2184 % returning a pointer to the image.
2186 % The format of the ReferenceImage method is:
2188 % Image *ReferenceImage(Image *image)
2190 % A description of each parameter follows:
2192 % o image: the image.
2195 MagickExport Image *ReferenceImage(Image *image)
2197 assert(image != (Image *) NULL);
2198 if (image->debug != MagickFalse)
2199 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2200 assert(image->signature == MagickSignature);
2201 LockSemaphoreInfo(image->semaphore);
2202 image->reference_count++;
2203 UnlockSemaphoreInfo(image->semaphore);
2208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2212 % R e s e t I m a g e P a g e %
2216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2218 % ResetImagePage() resets the image page canvas and position.
2220 % The format of the ResetImagePage method is:
2222 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2224 % A description of each parameter follows:
2226 % o image: the image.
2228 % o page: the relative page specification.
2231 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2239 assert(image != (Image *) NULL);
2240 assert(image->signature == MagickSignature);
2241 if (image->debug != MagickFalse)
2242 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2243 flags=ParseAbsoluteGeometry(page,&geometry);
2244 if ((flags & WidthValue) != 0)
2246 if ((flags & HeightValue) == 0)
2247 geometry.height=geometry.width;
2248 image->page.width=geometry.width;
2249 image->page.height=geometry.height;
2251 if ((flags & AspectValue) != 0)
2253 if ((flags & XValue) != 0)
2254 image->page.x+=geometry.x;
2255 if ((flags & YValue) != 0)
2256 image->page.y+=geometry.y;
2260 if ((flags & XValue) != 0)
2262 image->page.x=geometry.x;
2263 if ((image->page.width == 0) && (geometry.x > 0))
2264 image->page.width=image->columns+geometry.x;
2266 if ((flags & YValue) != 0)
2268 image->page.y=geometry.y;
2269 if ((image->page.height == 0) && (geometry.y > 0))
2270 image->page.height=image->rows+geometry.y;
2277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2281 % S e p a r a t e I m a g e C h a n n e l %
2285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2287 % SeparateImage() separates a channel from the image and returns it as
2288 % a grayscale image. A channel is a particular color component of each pixel
2291 % The format of the SeparateImage method is:
2293 % MagickBooleanType SeparateImage(Image *image)
2295 % A description of each parameter follows:
2297 % o image: the image.
2300 MagickExport MagickBooleanType SeparateImage(Image *image)
2302 #define SeparateImageTag "Separate/Image"
2319 assert(image != (Image *) NULL);
2320 assert(image->signature == MagickSignature);
2321 if (image->debug != MagickFalse)
2322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2323 exception=(&image->exception);
2324 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2325 return(MagickFalse);
2327 Separate image channels.
2331 image_view=AcquireCacheView(image);
2332 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2333 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2335 for (y=0; y < (ssize_t) image->rows; y++)
2343 if (status == MagickFalse)
2345 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2346 if (q == (Quantum *) NULL)
2351 for (x=0; x < (ssize_t) image->columns; x++)
2353 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2355 SetPixelGreen(image,GetPixelRed(image,q),q);
2356 SetPixelBlue(image,GetPixelRed(image,q),q);
2358 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2360 SetPixelRed(image,GetPixelGreen(image,q),q);
2361 SetPixelBlue(image,GetPixelGreen(image,q),q);
2363 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2365 SetPixelRed(image,GetPixelBlue(image,q),q);
2366 SetPixelGreen(image,GetPixelBlue(image,q),q);
2368 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2369 (image->colorspace == CMYKColorspace))
2371 SetPixelRed(image,GetPixelBlack(image,q),q);
2372 SetPixelGreen(image,GetPixelBlack(image,q),q);
2373 SetPixelBlue(image,GetPixelBlack(image,q),q);
2375 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2376 (image->matte != MagickFalse))
2378 SetPixelRed(image,GetPixelAlpha(image,q),q);
2379 SetPixelGreen(image,GetPixelAlpha(image,q),q);
2380 SetPixelBlue(image,GetPixelAlpha(image,q),q);
2382 q+=GetPixelChannels(image);
2384 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2386 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2391 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2392 #pragma omp critical (MagickCore_SeparateImage)
2394 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2395 if (proceed == MagickFalse)
2399 image_view=DestroyCacheView(image_view);
2400 (void) SetImageColorspace(image,RGBColorspace,exception);
2405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2409 % S e p a r a t e I m a g e s %
2413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2415 % SeparateImages() returns a separate grayscale image for each channel
2418 % The format of the SeparateImages method is:
2420 % MagickBooleanType SeparateImages(const Image *image,
2421 % ExceptionInfo *exception)
2423 % A description of each parameter follows:
2425 % o image: the image.
2427 % o exception: return any errors or warnings in this structure.
2430 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2439 assert(image != (Image *) NULL);
2440 assert(image->signature == MagickSignature);
2441 if (image->debug != MagickFalse)
2442 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2443 images=NewImageList();
2444 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2446 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2447 channel_mask=SetPixelChannelMask(separate_image,RedChannel);
2448 (void) SeparateImage(separate_image);
2449 (void) SetPixelChannelMap(separate_image,channel_mask);
2450 AppendImageToList(&images,separate_image);
2452 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2454 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2455 channel_mask=SetPixelChannelMask(separate_image,GreenChannel);
2456 (void) SeparateImage(separate_image);
2457 (void) SetPixelChannelMap(separate_image,channel_mask);
2458 AppendImageToList(&images,separate_image);
2460 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2462 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2463 channel_mask=SetPixelChannelMask(separate_image,BlueChannel);
2464 (void) SeparateImage(separate_image);
2465 (void) SetPixelChannelMap(separate_image,channel_mask);
2466 AppendImageToList(&images,separate_image);
2468 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2469 (image->colorspace == CMYKColorspace))
2471 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2472 channel_mask=SetPixelChannelMask(separate_image,BlackChannel);
2473 (void) SeparateImage(separate_image);
2474 (void) SetPixelChannelMap(separate_image,channel_mask);
2475 AppendImageToList(&images,separate_image);
2477 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2479 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2480 channel_mask=SetPixelChannelMask(separate_image,AlphaChannel);
2481 (void) SeparateImage(separate_image);
2482 (void) SetPixelChannelMap(separate_image,channel_mask);
2483 AppendImageToList(&images,separate_image);
2489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2493 % S e t I m a g e A l p h a C h a n n e l %
2497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2499 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2502 % The format of the SetImageAlphaChannel method is:
2504 % MagickBooleanType SetImageAlphaChannel(Image *image,
2505 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2507 % A description of each parameter follows:
2509 % o image: the image.
2511 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2512 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2513 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2514 % TransparentAlphaChannel.
2516 % o exception: return any errors or warnings in this structure.
2519 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2520 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2528 assert(image != (Image *) NULL);
2529 if (image->debug != MagickFalse)
2530 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2531 assert(image->signature == MagickSignature);
2535 case ActivateAlphaChannel:
2537 image->matte=MagickTrue;
2540 case BackgroundAlphaChannel:
2555 Set transparent pixels to background color.
2557 if (image->matte == MagickFalse)
2559 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2561 GetPixelInfo(image,&background);
2562 SetPixelInfoPacket(image,&image->background_color,&background);
2563 if (image->colorspace == CMYKColorspace)
2564 ConvertRGBToCMYK(&background);
2565 SetPacketPixelInfo(image,&background,&pixel);
2566 image_view=AcquireCacheView(image);
2567 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2568 #pragma omp parallel for schedule(dynamic,4) shared(status)
2570 for (y=0; y < (ssize_t) image->rows; y++)
2578 if (status == MagickFalse)
2580 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2582 if (q == (Quantum *) NULL)
2587 for (x=0; x < (ssize_t) image->columns; x++)
2589 if (GetPixelAlpha(image,q) == TransparentAlpha)
2591 SetPixelRed(image,pixel.red,q);
2592 SetPixelGreen(image,pixel.green,q);
2593 SetPixelBlue(image,pixel.blue,q);
2594 if (image->colorspace == CMYKColorspace)
2595 SetPixelBlack(image,pixel.black,q);
2597 q+=GetPixelChannels(image);
2599 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2602 image_view=DestroyCacheView(image_view);
2605 case DeactivateAlphaChannel:
2607 image->matte=MagickFalse;
2610 case ShapeAlphaChannel:
2611 case CopyAlphaChannel:
2614 Special usage case for SeparateImage(): copy grayscale color to
2617 channel_mask=SetPixelChannelMask(image,GrayChannel);
2618 status=SeparateImage(image);
2619 (void) SetPixelChannelMask(image,channel_mask);
2620 image->matte=MagickTrue; /* make sure transparency is now on! */
2621 if (alpha_type == ShapeAlphaChannel)
2627 Reset all color channels to background color.
2629 GetPixelInfo(image,&background);
2630 SetPixelInfoPacket(image,&(image->background_color),&background);
2631 (void) LevelImageColors(image,&background,&background,MagickTrue,
2636 case ExtractAlphaChannel:
2638 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2639 status=SeparateImage(image);
2640 (void) SetPixelChannelMask(image,channel_mask);
2641 image->matte=MagickFalse;
2644 case OpaqueAlphaChannel:
2646 status=SetImageOpacity(image,OpaqueAlpha);
2647 image->matte=MagickTrue;
2650 case TransparentAlphaChannel:
2652 status=SetImageOpacity(image,TransparentAlpha);
2653 image->matte=MagickTrue;
2656 case SetAlphaChannel:
2658 if (image->matte == MagickFalse)
2660 status=SetImageOpacity(image,OpaqueAlpha);
2661 image->matte=MagickTrue;
2665 case UndefinedAlphaChannel:
2668 if (status == MagickFalse)
2670 return(SyncImagePixelCache(image,exception));
2674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2678 % S e t I m a g e B a c k g r o u n d C o l o r %
2682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2684 % SetImageBackgroundColor() initializes the image pixels to the image
2685 % background color. The background color is defined by the background_color
2686 % member of the image structure.
2688 % The format of the SetImage method is:
2690 % MagickBooleanType SetImageBackgroundColor(Image *image)
2692 % A description of each parameter follows:
2694 % o image: the image.
2697 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2717 assert(image != (Image *) NULL);
2718 if (image->debug != MagickFalse)
2719 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2720 assert(image->signature == MagickSignature);
2721 exception=(&image->exception);
2722 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2723 return(MagickFalse);
2724 if (image->background_color.alpha != OpaqueAlpha)
2725 image->matte=MagickTrue;
2726 GetPixelInfo(image,&background);
2727 SetPixelInfoPacket(image,&image->background_color,&background);
2728 if (image->colorspace == CMYKColorspace)
2729 ConvertRGBToCMYK(&background);
2730 SetPacketPixelInfo(image,&background,&pixel);
2732 Set image background color.
2736 image_view=AcquireCacheView(image);
2737 for (y=0; y < (ssize_t) image->rows; y++)
2745 if (status == MagickFalse)
2747 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2748 if (q == (Quantum *) NULL)
2753 for (x=0; x < (ssize_t) image->columns; x++)
2755 SetPixelPacket(image,&pixel,q);
2756 if (image->colorspace == CMYKColorspace)
2757 SetPixelBlack(image,pixel.black,q);
2758 q+=GetPixelChannels(image);
2760 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2763 image_view=DestroyCacheView(image_view);
2768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2772 % S e t I m a g e C o l o r %
2776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2778 % SetImageColor() set the entire image canvas to the specified color.
2780 % The format of the SetImageColor method is:
2782 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color)
2784 % A description of each parameter follows:
2786 % o image: the image.
2788 % o background: the image color.
2791 MagickExport MagickBooleanType SetImageColor(Image *image,
2792 const PixelInfo *color)
2806 assert(image != (Image *) NULL);
2807 if (image->debug != MagickFalse)
2808 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2809 assert(image->signature == MagickSignature);
2810 assert(color != (const PixelInfo *) NULL);
2811 image->colorspace=color->colorspace;
2812 image->matte=color->matte;
2813 image->fuzz=color->fuzz;
2814 image->depth=color->depth;
2816 exception=(&image->exception);
2817 image_view=AcquireCacheView(image);
2818 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2819 #pragma omp parallel for schedule(dynamic,4) shared(status)
2821 for (y=0; y < (ssize_t) image->rows; y++)
2829 if (status == MagickFalse)
2831 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2832 if (q == (Quantum *) NULL)
2837 for (x=0; x < (ssize_t) image->columns; x++)
2839 SetPixelPixelInfo(image,color,q);
2840 q+=GetPixelChannels(image);
2842 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2845 image_view=DestroyCacheView(image_view);
2850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2854 % S e t I m a g e S t o r a g e C l a s s %
2858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2860 % SetImageStorageClass() sets the image class: DirectClass for true color
2861 % images or PseudoClass for colormapped images.
2863 % The format of the SetImageStorageClass method is:
2865 % MagickBooleanType SetImageStorageClass(Image *image,
2866 % const ClassType storage_class,ExceptionInfo *exception)
2868 % A description of each parameter follows:
2870 % o image: the image.
2872 % o storage_class: The image class.
2874 % o exception: return any errors or warnings in this structure.
2877 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2878 const ClassType storage_class,ExceptionInfo *exception)
2880 image->storage_class=storage_class;
2881 return(SyncImagePixelCache(image,exception));
2885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2889 % S e t I m a g e C l i p M a s k %
2893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2895 % SetImageClipMask() associates a clip path with the image. The clip path
2896 % must be the same dimensions as the image. Set any pixel component of
2897 % the clip path to TransparentAlpha to prevent that corresponding image
2898 % pixel component from being updated when SyncAuthenticPixels() is applied.
2900 % The format of the SetImageClipMask method is:
2902 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2904 % A description of each parameter follows:
2906 % o image: the image.
2908 % o clip_mask: the image clip path.
2911 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2912 const Image *clip_mask)
2914 assert(image != (Image *) NULL);
2915 if (image->debug != MagickFalse)
2916 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2917 assert(image->signature == MagickSignature);
2918 if (clip_mask != (const Image *) NULL)
2919 if ((clip_mask->columns != image->columns) ||
2920 (clip_mask->rows != image->rows))
2921 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2922 if (image->clip_mask != (Image *) NULL)
2923 image->clip_mask=DestroyImage(image->clip_mask);
2924 image->clip_mask=NewImageList();
2925 if (clip_mask == (Image *) NULL)
2927 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
2928 return(MagickFalse);
2929 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2930 if (image->clip_mask == (Image *) NULL)
2931 return(MagickFalse);
2936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2940 % S e t I m a g e E x t e n t %
2944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2946 % SetImageExtent() sets the image size (i.e. columns & rows).
2948 % The format of the SetImageExtent method is:
2950 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2951 % const size_t rows,ExceptionInfo *exception)
2953 % A description of each parameter follows:
2955 % o image: the image.
2957 % o columns: The image width in pixels.
2959 % o rows: The image height in pixels.
2961 % o exception: return any errors or warnings in this structure.
2964 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2965 const size_t rows,ExceptionInfo *exception)
2967 if ((columns == 0) || (rows == 0))
2968 return(MagickFalse);
2969 image->columns=columns;
2971 return(SyncImagePixelCache(image,exception));
2975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2979 + S e t I m a g e I n f o %
2983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2985 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2986 % It is set to a type of image format based on the prefix or suffix of the
2987 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2988 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2989 % precendence over the suffix. Use an optional index enclosed in brackets
2990 % after a file name to specify a desired scene of a multi-resolution image
2991 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2992 % indicates success.
2994 % The format of the SetImageInfo method is:
2996 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2997 % const unsigned int frames,ExceptionInfo *exception)
2999 % A description of each parameter follows:
3001 % o image_info: the image info.
3003 % o frames: the number of images you intend to write.
3005 % o exception: return any errors or warnings in this structure.
3008 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
3009 const unsigned int frames,ExceptionInfo *exception)
3012 extension[MaxTextExtent],
3013 filename[MaxTextExtent],
3014 magic[MaxTextExtent],
3016 subimage[MaxTextExtent];
3040 magick[2*MaxTextExtent];
3043 Look for 'image.format' in filename.
3045 assert(image_info != (ImageInfo *) NULL);
3046 assert(image_info->signature == MagickSignature);
3047 if (image_info->debug != MagickFalse)
3048 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3049 image_info->filename);
3053 GetPathComponent(image_info->filename,SubimagePath,subimage);
3054 if (*subimage != '\0')
3057 Look for scene specification (e.g. img0001.pcd[4]).
3059 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3061 if (IsGeometry(subimage) != MagickFalse)
3062 (void) CloneString(&image_info->extract,subimage);
3070 (void) CloneString(&image_info->scenes,subimage);
3071 image_info->scene=StringToUnsignedLong(image_info->scenes);
3072 image_info->number_scenes=image_info->scene;
3073 p=image_info->scenes;
3074 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3076 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3079 first=(size_t) strtol(p,&q,10);
3081 while (isspace((int) ((unsigned char) *q)) != 0)
3084 last=(size_t) strtol(q+1,&q,10);
3087 if (first < image_info->scene)
3088 image_info->scene=first;
3089 if (last > image_info->number_scenes)
3090 image_info->number_scenes=last;
3093 image_info->number_scenes-=image_info->scene-1;
3098 GetPathComponent(image_info->filename,ExtensionPath,extension);
3099 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3100 if (*extension != '\0')
3101 if ((LocaleCompare(extension,"gz") == 0) ||
3102 (LocaleCompare(extension,"Z") == 0) ||
3103 (LocaleCompare(extension,"wmz") == 0))
3106 path[MaxTextExtent];
3108 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3109 path[strlen(path)-strlen(extension)-1]='\0';
3110 GetPathComponent(path,ExtensionPath,extension);
3113 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3114 if (*extension != '\0')
3115 if (LocaleCompare(extension,"bz2") == 0)
3118 path[MaxTextExtent];
3120 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3121 path[strlen(path)-strlen(extension)-1]='\0';
3122 GetPathComponent(path,ExtensionPath,extension);
3125 image_info->affirm=MagickFalse;
3126 sans_exception=AcquireExceptionInfo();
3127 if (*extension != '\0')
3136 *format_type_formats[] =
3159 User specified image format.
3161 (void) CopyMagickString(magic,extension,MaxTextExtent);
3164 Look for explicit image formats.
3166 format_type=UndefinedFormatType;
3168 while ((format_type == UndefinedFormatType) &&
3169 (format_type_formats[i] != (char *) NULL))
3171 if ((*magic == *format_type_formats[i]) &&
3172 (LocaleCompare(magic,format_type_formats[i]) == 0))
3173 format_type=ExplicitFormatType;
3176 magick_info=GetMagickInfo(magic,sans_exception);
3177 if ((magick_info != (const MagickInfo *) NULL) &&
3178 (magick_info->format_type != UndefinedFormatType))
3179 format_type=magick_info->format_type;
3180 if (format_type == UndefinedFormatType)
3181 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3183 if (format_type == ExplicitFormatType)
3185 image_info->affirm=MagickTrue;
3186 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3188 if (LocaleCompare(magic,"RGB") == 0)
3189 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3192 Look for explicit 'format:image' in filename.
3195 GetPathComponent(image_info->filename,MagickPath,magic);
3197 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3201 User specified image format.
3204 if (IsMagickConflict(magic) == MagickFalse)
3206 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3207 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3208 image_info->affirm=MagickTrue;
3210 image_info->temporary=MagickTrue;
3213 magick_info=GetMagickInfo(magic,sans_exception);
3214 sans_exception=DestroyExceptionInfo(sans_exception);
3215 if ((magick_info == (const MagickInfo *) NULL) ||
3216 (GetMagickEndianSupport(magick_info) == MagickFalse))
3217 image_info->endian=UndefinedEndian;
3218 GetPathComponent(image_info->filename,CanonicalPath,filename);
3219 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3220 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3223 Test for multiple image support (e.g. image%02d.png).
3225 (void) InterpretImageFilename(image_info,(Image *) NULL,
3226 image_info->filename,(int) image_info->scene,filename);
3227 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3228 (strchr(filename,'%') == (char *) NULL))
3229 image_info->adjoin=MagickFalse;
3231 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3234 Some image formats do not support multiple frames per file.
3236 magick_info=GetMagickInfo(magic,exception);
3237 if (magick_info != (const MagickInfo *) NULL)
3238 if (GetMagickAdjoin(magick_info) == MagickFalse)
3239 image_info->adjoin=MagickFalse;
3241 if (image_info->affirm != MagickFalse)
3246 Determine the image format from the first few bytes of the file.
3248 image=AcquireImage(image_info);
3249 (void) CopyMagickString(image->filename,image_info->filename,
3251 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3252 if (status == MagickFalse)
3254 image=DestroyImage(image);
3255 return(MagickFalse);
3257 if ((IsBlobSeekable(image) == MagickFalse) ||
3258 (IsBlobExempt(image) != MagickFalse))
3261 Copy standard input or pipe to temporary file.
3264 status=ImageToFile(image,filename,exception);
3265 (void) CloseBlob(image);
3266 if (status == MagickFalse)
3268 image=DestroyImage(image);
3269 return(MagickFalse);
3271 SetImageInfoFile(image_info,(FILE *) NULL);
3272 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3273 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3274 if (status == MagickFalse)
3276 image=DestroyImage(image);
3277 return(MagickFalse);
3279 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3280 image_info->temporary=MagickTrue;
3282 (void) ResetMagickMemory(magick,0,sizeof(magick));
3283 count=ReadBlob(image,2*MaxTextExtent,magick);
3284 (void) CloseBlob(image);
3285 image=DestroyImage(image);
3287 Check magic.xml configuration file.
3289 sans_exception=AcquireExceptionInfo();
3290 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3291 if ((magic_info != (const MagicInfo *) NULL) &&
3292 (GetMagicName(magic_info) != (char *) NULL))
3294 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3296 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3297 if ((magick_info == (const MagickInfo *) NULL) ||
3298 (GetMagickEndianSupport(magick_info) == MagickFalse))
3299 image_info->endian=UndefinedEndian;
3300 sans_exception=DestroyExceptionInfo(sans_exception);
3303 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3304 if ((magick_info == (const MagickInfo *) NULL) ||
3305 (GetMagickEndianSupport(magick_info) == MagickFalse))
3306 image_info->endian=UndefinedEndian;
3307 sans_exception=DestroyExceptionInfo(sans_exception);
3313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3317 % S e t I m a g e I n f o B l o b %
3321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3323 % SetImageInfoBlob() sets the image info blob member.
3325 % The format of the SetImageInfoBlob method is:
3327 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3328 % const size_t length)
3330 % A description of each parameter follows:
3332 % o image_info: the image info.
3336 % o length: the blob length.
3339 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3340 const size_t length)
3342 assert(image_info != (ImageInfo *) NULL);
3343 assert(image_info->signature == MagickSignature);
3344 if (image_info->debug != MagickFalse)
3345 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3346 image_info->filename);
3347 image_info->blob=(void *) blob;
3348 image_info->length=length;
3352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3356 % S e t I m a g e I n f o F i l e %
3360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3362 % SetImageInfoFile() sets the image info file member.
3364 % The format of the SetImageInfoFile method is:
3366 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3368 % A description of each parameter follows:
3370 % o image_info: the image info.
3375 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3377 assert(image_info != (ImageInfo *) NULL);
3378 assert(image_info->signature == MagickSignature);
3379 if (image_info->debug != MagickFalse)
3380 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3381 image_info->filename);
3382 image_info->file=file;
3386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3390 % S e t I m a g e M a s k %
3394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3396 % SetImageMask() associates a mask with the image. The mask must be the same
3397 % dimensions as the image.
3399 % The format of the SetImageMask method is:
3401 % MagickBooleanType SetImageMask(Image *image,const Image *mask)
3403 % A description of each parameter follows:
3405 % o image: the image.
3407 % o mask: the image mask.
3410 MagickExport MagickBooleanType SetImageMask(Image *image,
3413 assert(image != (Image *) NULL);
3414 if (image->debug != MagickFalse)
3415 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3416 assert(image->signature == MagickSignature);
3417 if (mask != (const Image *) NULL)
3418 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3419 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3420 if (image->mask != (Image *) NULL)
3421 image->mask=DestroyImage(image->mask);
3422 image->mask=NewImageList();
3423 if (mask == (Image *) NULL)
3425 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
3426 return(MagickFalse);
3427 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3428 if (image->mask == (Image *) NULL)
3429 return(MagickFalse);
3434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3438 % S e t I m a g e O p a c i t y %
3442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3444 % SetImageOpacity() sets the opacity levels of the image.
3446 % The format of the SetImageOpacity method is:
3448 % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3450 % A description of each parameter follows:
3452 % o image: the image.
3454 % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3455 % fully transparent.
3458 MagickExport MagickBooleanType SetImageOpacity(Image *image,
3459 const Quantum opacity)
3473 assert(image != (Image *) NULL);
3474 if (image->debug != MagickFalse)
3475 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3476 assert(image->signature == MagickSignature);
3477 image->matte=opacity != OpaqueAlpha ? MagickTrue : MagickFalse;
3479 exception=(&image->exception);
3480 image_view=AcquireCacheView(image);
3481 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3482 #pragma omp parallel for schedule(dynamic,4) shared(status)
3484 for (y=0; y < (ssize_t) image->rows; y++)
3492 if (status == MagickFalse)
3494 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3495 if (q == (Quantum *) NULL)
3500 for (x=0; x < (ssize_t) image->columns; x++)
3502 SetPixelAlpha(image,opacity,q);
3503 q+=GetPixelChannels(image);
3505 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3508 image_view=DestroyCacheView(image_view);
3513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3517 % S e t I m a g e T y p e %
3521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3523 % SetImageType() sets the type of image. Choose from these types:
3525 % Bilevel Grayscale GrayscaleMatte
3526 % Palette PaletteMatte TrueColor
3527 % TrueColorMatte ColorSeparation ColorSeparationMatte
3530 % The format of the SetImageType method is:
3532 % MagickBooleanType SetImageType(Image *image,const ImageType type)
3534 % A description of each parameter follows:
3536 % o image: the image.
3538 % o type: Image type.
3541 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3558 assert(image != (Image *) NULL);
3559 if (image->debug != MagickFalse)
3560 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3561 assert(image->signature == MagickSignature);
3563 image_info=AcquireImageInfo();
3564 image_info->dither=image->dither;
3565 artifact=GetImageArtifact(image,"dither");
3566 if (artifact != (const char *) NULL)
3567 (void) SetImageOption(image_info,"dither",artifact);
3568 exception=(&image->exception);
3573 if (IsImageGray(image,&image->exception) == MagickFalse)
3574 status=TransformImageColorspace(image,GRAYColorspace);
3575 if (IsImageMonochrome(image,&image->exception) == MagickFalse)
3577 quantize_info=AcquireQuantizeInfo(image_info);
3578 quantize_info->number_colors=2;
3579 quantize_info->colorspace=GRAYColorspace;
3580 status=QuantizeImage(quantize_info,image);
3581 quantize_info=DestroyQuantizeInfo(quantize_info);
3583 image->matte=MagickFalse;
3588 if (IsImageGray(image,&image->exception) == MagickFalse)
3589 status=TransformImageColorspace(image,GRAYColorspace);
3590 image->matte=MagickFalse;
3593 case GrayscaleMatteType:
3595 if (IsImageGray(image,&image->exception) == MagickFalse)
3596 status=TransformImageColorspace(image,GRAYColorspace);
3597 if (image->matte == MagickFalse)
3598 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3603 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3604 status=TransformImageColorspace(image,RGBColorspace);
3605 if ((image->storage_class == DirectClass) || (image->colors > 256))
3607 quantize_info=AcquireQuantizeInfo(image_info);
3608 quantize_info->number_colors=256;
3609 status=QuantizeImage(quantize_info,image);
3610 quantize_info=DestroyQuantizeInfo(quantize_info);
3612 image->matte=MagickFalse;
3615 case PaletteBilevelMatteType:
3620 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3621 status=TransformImageColorspace(image,RGBColorspace);
3622 if (image->matte == MagickFalse)
3623 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3624 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3625 (void) BilevelImage(image,(double) QuantumRange/2.0);
3626 (void) SetPixelChannelMask(image,channel_mask);
3627 quantize_info=AcquireQuantizeInfo(image_info);
3628 status=QuantizeImage(quantize_info,image);
3629 quantize_info=DestroyQuantizeInfo(quantize_info);
3632 case PaletteMatteType:
3634 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3635 status=TransformImageColorspace(image,RGBColorspace);
3636 if (image->matte == MagickFalse)
3637 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3638 quantize_info=AcquireQuantizeInfo(image_info);
3639 quantize_info->colorspace=TransparentColorspace;
3640 status=QuantizeImage(quantize_info,image);
3641 quantize_info=DestroyQuantizeInfo(quantize_info);
3646 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3647 status=TransformImageColorspace(image,RGBColorspace);
3648 if (image->storage_class != DirectClass)
3649 status=SetImageStorageClass(image,DirectClass,&image->exception);
3650 image->matte=MagickFalse;
3653 case TrueColorMatteType:
3655 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3656 status=TransformImageColorspace(image,RGBColorspace);
3657 if (image->storage_class != DirectClass)
3658 status=SetImageStorageClass(image,DirectClass,&image->exception);
3659 if (image->matte == MagickFalse)
3660 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3663 case ColorSeparationType:
3665 if (image->colorspace != CMYKColorspace)
3667 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3668 status=TransformImageColorspace(image,RGBColorspace);
3669 status=TransformImageColorspace(image,CMYKColorspace);
3671 if (image->storage_class != DirectClass)
3672 status=SetImageStorageClass(image,DirectClass,&image->exception);
3673 image->matte=MagickFalse;
3676 case ColorSeparationMatteType:
3678 if (image->colorspace != CMYKColorspace)
3680 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3681 status=TransformImageColorspace(image,RGBColorspace);
3682 status=TransformImageColorspace(image,CMYKColorspace);
3684 if (image->storage_class != DirectClass)
3685 status=SetImageStorageClass(image,DirectClass,&image->exception);
3686 if (image->matte == MagickFalse)
3687 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3695 image_info=DestroyImageInfo(image_info);
3700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3704 % 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 %
3708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3710 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3711 % image and returns the previous setting. A virtual pixel is any pixel access
3712 % that is outside the boundaries of the image cache.
3714 % The format of the SetImageVirtualPixelMethod() method is:
3716 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3717 % const VirtualPixelMethod virtual_pixel_method)
3719 % A description of each parameter follows:
3721 % o image: the image.
3723 % o virtual_pixel_method: choose the type of virtual pixel.
3726 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3727 const VirtualPixelMethod virtual_pixel_method)
3729 assert(image != (const Image *) NULL);
3730 assert(image->signature == MagickSignature);
3731 if (image->debug != MagickFalse)
3732 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3733 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3741 % S m u s h I m a g e s %
3745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3747 % SmushImages() takes all images from the current image pointer to the end
3748 % of the image list and smushes them to each other top-to-bottom if the
3749 % stack parameter is true, otherwise left-to-right.
3751 % The current gravity setting now effects how the image is justified in the
3754 % The format of the SmushImages method is:
3756 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3757 % ExceptionInfo *exception)
3759 % A description of each parameter follows:
3761 % o images: the image sequence.
3763 % o stack: A value other than 0 stacks the images top-to-bottom.
3765 % o offset: minimum distance in pixels between images.
3767 % o exception: return any errors or warnings in this structure.
3771 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3772 const ssize_t offset,ExceptionInfo *exception)
3786 register const Quantum
3799 if (images->previous == (Image *) NULL)
3802 SetGeometry(smush_image,&right_geometry);
3803 GravityAdjustGeometry(right_image->columns,right_image->rows,
3804 right_image->gravity,&right_geometry);
3805 left_image=images->previous;
3806 SetGeometry(smush_image,&left_geometry);
3807 GravityAdjustGeometry(left_image->columns,left_image->rows,
3808 left_image->gravity,&left_geometry);
3809 gap=right_image->columns;
3810 left_view=AcquireCacheView(left_image);
3811 right_view=AcquireCacheView(right_image);
3812 for (y=0; y < (ssize_t) smush_image->rows; y++)
3814 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3816 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3817 if ((p == (const Quantum *) NULL) ||
3818 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3819 ((left_image->columns-x-1) >= gap))
3822 i=(ssize_t) left_image->columns-x-1;
3823 for (x=0; x < (ssize_t) right_image->columns; x++)
3825 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3827 if ((p == (const Quantum *) NULL) ||
3828 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3829 ((x+i) >= (ssize_t) gap))
3832 if ((x+i) < (ssize_t) gap)
3835 right_view=DestroyCacheView(right_view);
3836 left_view=DestroyCacheView(left_view);
3837 if (y < (ssize_t) smush_image->rows)
3839 return((ssize_t) gap-offset);
3842 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3843 const ssize_t offset,ExceptionInfo *exception)
3857 register const Quantum
3870 if (images->previous == (Image *) NULL)
3872 bottom_image=images;
3873 SetGeometry(smush_image,&bottom_geometry);
3874 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3875 bottom_image->gravity,&bottom_geometry);
3876 top_image=images->previous;
3877 SetGeometry(smush_image,&top_geometry);
3878 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3880 gap=bottom_image->rows;
3881 top_view=AcquireCacheView(top_image);
3882 bottom_view=AcquireCacheView(bottom_image);
3883 for (x=0; x < (ssize_t) smush_image->columns; x++)
3885 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3887 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3888 if ((p == (const Quantum *) NULL) ||
3889 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3890 ((top_image->rows-y-1) >= gap))
3893 i=(ssize_t) top_image->rows-y-1;
3894 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3896 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3898 if ((p == (const Quantum *) NULL) ||
3899 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3900 ((y+i) >= (ssize_t) gap))
3903 if ((y+i) < (ssize_t) gap)
3906 bottom_view=DestroyCacheView(bottom_view);
3907 top_view=DestroyCacheView(top_view);
3908 if (x < (ssize_t) smush_image->columns)
3910 return((ssize_t) gap-offset);
3913 MagickExport Image *SmushImages(const Image *images,
3914 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3916 #define SmushImageTag "Smush/Image"
3938 register const Image
3951 Compute maximum area of smushed area.
3953 assert(images != (Image *) NULL);
3954 assert(images->signature == MagickSignature);
3955 if (images->debug != MagickFalse)
3956 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3957 assert(exception != (ExceptionInfo *) NULL);
3958 assert(exception->signature == MagickSignature);
3962 width=image->columns;
3964 next=GetNextImageInList(image);
3965 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3967 if (next->matte != MagickFalse)
3970 if (stack != MagickFalse)
3972 if (next->columns > width)
3973 width=next->columns;
3975 if (next->previous != (Image *) NULL)
3979 width+=next->columns;
3980 if (next->previous != (Image *) NULL)
3982 if (next->rows > height)
3988 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3989 if (smush_image == (Image *) NULL)
3990 return((Image *) NULL);
3991 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3993 smush_image=DestroyImage(smush_image);
3994 return((Image *) NULL);
3996 smush_image->matte=matte;
3997 (void) SetImageBackgroundColor(smush_image);
4001 smush_view=AcquireCacheView(smush_image);
4002 for (n=0; n < (MagickOffsetType) number_images; n++)
4004 SetGeometry(smush_image,&geometry);
4005 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4006 if (stack != MagickFalse)
4008 x_offset-=geometry.x;
4009 y_offset-=SmushYGap(smush_image,image,offset,exception);
4013 x_offset-=SmushXGap(smush_image,image,offset,exception);
4014 y_offset-=geometry.y;
4016 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
4017 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4018 if (proceed == MagickFalse)
4020 if (stack == MagickFalse)
4022 x_offset+=(ssize_t) image->columns;
4028 y_offset+=(ssize_t) image->rows;
4030 image=GetNextImageInList(image);
4032 if (stack == MagickFalse)
4033 smush_image->columns=(size_t) x_offset;
4035 smush_image->rows=(size_t) y_offset;
4036 smush_view=DestroyCacheView(smush_view);
4037 if (status == MagickFalse)
4038 smush_image=DestroyImage(smush_image);
4039 return(smush_image);
4043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4047 % S t r i p I m a g e %
4051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4053 % StripImage() strips an image of all profiles and comments.
4055 % The format of the StripImage method is:
4057 % MagickBooleanType StripImage(Image *image)
4059 % A description of each parameter follows:
4061 % o image: the image.
4064 MagickExport MagickBooleanType StripImage(Image *image)
4066 assert(image != (Image *) NULL);
4067 if (image->debug != MagickFalse)
4068 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4069 DestroyImageProfiles(image);
4070 (void) DeleteImageProperty(image,"comment");
4071 (void) DeleteImageProperty(image,"date:create");
4072 (void) DeleteImageProperty(image,"date:modify");
4073 (void) SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4082 + S y n c I m a g e %
4086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4088 % SyncImage() initializes the red, green, and blue intensities of each pixel
4089 % as defined by the colormap index.
4091 % The format of the SyncImage method is:
4093 % MagickBooleanType SyncImage(Image *image)
4095 % A description of each parameter follows:
4097 % o image: the image.
4101 static inline Quantum PushColormapIndex(Image *image,
4102 const size_t index,MagickBooleanType *range_exception)
4104 if (index < image->colors)
4105 return((Quantum) index);
4106 *range_exception=MagickTrue;
4107 return((Quantum) 0);
4110 MagickExport MagickBooleanType SyncImage(Image *image)
4125 assert(image != (Image *) NULL);
4126 if (image->debug != MagickFalse)
4127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4128 assert(image->signature == MagickSignature);
4129 if (image->storage_class == DirectClass)
4130 return(MagickFalse);
4131 range_exception=MagickFalse;
4133 exception=(&image->exception);
4134 image_view=AcquireCacheView(image);
4135 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4136 #pragma omp parallel for schedule(dynamic,4) shared(status)
4138 for (y=0; y < (ssize_t) image->rows; y++)
4149 if (status == MagickFalse)
4151 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4152 if (q == (Quantum *) NULL)
4157 for (x=0; x < (ssize_t) image->columns; x++)
4159 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4161 SetPixelPacket(image,image->colormap+(ssize_t) index,q);
4162 q+=GetPixelChannels(image);
4164 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4167 image_view=DestroyCacheView(image_view);
4168 if (range_exception != MagickFalse)
4169 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4170 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4179 % S y n c I m a g e S e t t i n g s %
4183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4185 % SyncImageSettings() sync the image info options to the image.
4187 % The format of the SyncImageSettings method is:
4189 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4191 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4194 % A description of each parameter follows:
4196 % o image_info: the image info.
4198 % o image: the image.
4202 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4208 assert(image_info != (const ImageInfo *) NULL);
4209 assert(image_info->signature == MagickSignature);
4210 assert(images != (Image *) NULL);
4211 assert(images->signature == MagickSignature);
4212 if (images->debug != MagickFalse)
4213 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4215 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4216 (void) SyncImageSettings(image_info,image);
4217 (void) DeleteImageOption(image_info,"page");
4221 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4225 property[MaxTextExtent];
4243 assert(image_info != (const ImageInfo *) NULL);
4244 assert(image_info->signature == MagickSignature);
4245 assert(image != (Image *) NULL);
4246 assert(image->signature == MagickSignature);
4247 if (image->debug != MagickFalse)
4248 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4249 option=GetImageOption(image_info,"background");
4250 if (option != (const char *) NULL)
4251 (void) QueryColorDatabase(option,&image->background_color,
4253 option=GetImageOption(image_info,"bias");
4254 if (option != (const char *) NULL)
4255 image->bias=SiPrefixToDouble(option,QuantumRange);
4256 option=GetImageOption(image_info,"black-point-compensation");
4257 if (option != (const char *) NULL)
4258 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4259 MagickBooleanOptions,MagickFalse,option);
4260 option=GetImageOption(image_info,"blue-primary");
4261 if (option != (const char *) NULL)
4263 flags=ParseGeometry(option,&geometry_info);
4264 image->chromaticity.blue_primary.x=geometry_info.rho;
4265 image->chromaticity.blue_primary.y=geometry_info.sigma;
4266 if ((flags & SigmaValue) == 0)
4267 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4269 option=GetImageOption(image_info,"bordercolor");
4270 if (option != (const char *) NULL)
4271 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4272 option=GetImageOption(image_info,"colors");
4273 if (option != (const char *) NULL)
4274 image->colors=StringToUnsignedLong(option);
4275 option=GetImageOption(image_info,"compose");
4276 if (option != (const char *) NULL)
4277 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4278 MagickFalse,option);
4279 option=GetImageOption(image_info,"compress");
4280 if (option != (const char *) NULL)
4281 image->compression=(CompressionType) ParseCommandOption(
4282 MagickCompressOptions,MagickFalse,option);
4283 option=GetImageOption(image_info,"debug");
4284 if (option != (const char *) NULL)
4285 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4286 MagickFalse,option);
4287 option=GetImageOption(image_info,"density");
4288 if (option != (const char *) NULL)
4296 flags=ParseGeometry(option,&geometry_info);
4297 image->x_resolution=geometry_info.rho;
4298 image->y_resolution=geometry_info.sigma;
4299 if ((flags & SigmaValue) == 0)
4300 image->y_resolution=image->x_resolution;
4302 option=GetImageOption(image_info,"depth");
4303 if (option != (const char *) NULL)
4304 image->depth=StringToUnsignedLong(option);
4305 option=GetImageOption(image_info,"endian");
4306 if (option != (const char *) NULL)
4307 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4308 MagickFalse,option);
4309 option=GetImageOption(image_info,"filter");
4310 if (option != (const char *) NULL)
4311 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4312 MagickFalse,option);
4313 option=GetImageOption(image_info,"fuzz");
4314 if (option != (const char *) NULL)
4315 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4316 option=GetImageOption(image_info,"gravity");
4317 if (option != (const char *) NULL)
4318 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4319 MagickFalse,option);
4320 option=GetImageOption(image_info,"green-primary");
4321 if (option != (const char *) NULL)
4323 flags=ParseGeometry(option,&geometry_info);
4324 image->chromaticity.green_primary.x=geometry_info.rho;
4325 image->chromaticity.green_primary.y=geometry_info.sigma;
4326 if ((flags & SigmaValue) == 0)
4327 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4329 option=GetImageOption(image_info,"intent");
4330 if (option != (const char *) NULL)
4331 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4332 MagickIntentOptions,MagickFalse,option);
4333 option=GetImageOption(image_info,"interlace");
4334 if (option != (const char *) NULL)
4335 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4336 MagickFalse,option);
4337 option=GetImageOption(image_info,"interpolate");
4338 if (option != (const char *) NULL)
4339 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
4340 MagickInterpolateOptions,MagickFalse,option);
4341 option=GetImageOption(image_info,"loop");
4342 if (option != (const char *) NULL)
4343 image->iterations=StringToUnsignedLong(option);
4344 option=GetImageOption(image_info,"mattecolor");
4345 if (option != (const char *) NULL)
4346 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4347 option=GetImageOption(image_info,"orient");
4348 if (option != (const char *) NULL)
4349 image->orientation=(OrientationType) ParseCommandOption(
4350 MagickOrientationOptions,MagickFalse,option);
4351 option=GetImageOption(image_info,"page");
4352 if (option != (const char *) NULL)
4357 geometry=GetPageGeometry(option);
4358 flags=ParseAbsoluteGeometry(geometry,&image->page);
4359 geometry=DestroyString(geometry);
4361 option=GetImageOption(image_info,"quality");
4362 if (option != (const char *) NULL)
4363 image->quality=StringToUnsignedLong(option);
4364 option=GetImageOption(image_info,"red-primary");
4365 if (option != (const char *) NULL)
4367 flags=ParseGeometry(option,&geometry_info);
4368 image->chromaticity.red_primary.x=geometry_info.rho;
4369 image->chromaticity.red_primary.y=geometry_info.sigma;
4370 if ((flags & SigmaValue) == 0)
4371 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4373 if (image_info->quality != UndefinedCompressionQuality)
4374 image->quality=image_info->quality;
4375 option=GetImageOption(image_info,"scene");
4376 if (option != (const char *) NULL)
4377 image->scene=StringToUnsignedLong(option);
4378 option=GetImageOption(image_info,"taint");
4379 if (option != (const char *) NULL)
4380 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4381 MagickFalse,option);
4382 option=GetImageOption(image_info,"tile-offset");
4383 if (option != (const char *) NULL)
4388 geometry=GetPageGeometry(option);
4389 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4390 geometry=DestroyString(geometry);
4392 option=GetImageOption(image_info,"transparent-color");
4393 if (option != (const char *) NULL)
4394 (void) QueryColorDatabase(option,&image->transparent_color,
4396 option=GetImageOption(image_info,"type");
4397 if (option != (const char *) NULL)
4398 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4400 option=GetImageOption(image_info,"units");
4401 if (option != (const char *) NULL)
4402 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4403 MagickFalse,option);
4405 units = image_info->units;
4406 if (units != UndefinedResolution)
4408 if (image->units != units)
4409 switch (image->units)
4411 case PixelsPerInchResolution:
4413 if (units == PixelsPerCentimeterResolution)
4415 image->x_resolution/=2.54;
4416 image->y_resolution/=2.54;
4420 case PixelsPerCentimeterResolution:
4422 if (units == PixelsPerInchResolution)
4424 image->x_resolution=(double) ((size_t) (100.0*2.54*
4425 image->x_resolution+0.5))/100.0;
4426 image->y_resolution=(double) ((size_t) (100.0*2.54*
4427 image->y_resolution+0.5))/100.0;
4436 option=GetImageOption(image_info,"white-point");
4437 if (option != (const char *) NULL)
4439 flags=ParseGeometry(option,&geometry_info);
4440 image->chromaticity.white_point.x=geometry_info.rho;
4441 image->chromaticity.white_point.y=geometry_info.sigma;
4442 if ((flags & SigmaValue) == 0)
4443 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4445 ResetImageOptionIterator(image_info);
4446 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4448 value=GetImageOption(image_info,option);
4449 if (value != (const char *) NULL)
4451 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4452 (void) SetImageArtifact(image,property,value);
4454 option=GetNextImageOption(image_info);