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/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/segment.h"
87 #include "MagickCore/semaphore.h"
88 #include "MagickCore/signature-private.h"
89 #include "MagickCore/statistic.h"
90 #include "MagickCore/string_.h"
91 #include "MagickCore/string-private.h"
92 #include "MagickCore/thread-private.h"
93 #include "MagickCore/threshold.h"
94 #include "MagickCore/timer.h"
95 #include "MagickCore/utility.h"
96 #include "MagickCore/utility-private.h"
97 #include "MagickCore/version.h"
98 #include "MagickCore/xwindow-private.h"
101 Constant declaration.
103 MagickPrivate const char
104 BackgroundColor[] = "#ffffff", /* white */
105 BorderColor[] = "#dfdfdf", /* gray */
106 ForegroundColor[] = "#000", /* black */
107 MatteColor[] = "#bdbdbd"; /* gray */
109 MagickExport const char
110 DefaultTileFrame[] = "15x15+3+3",
111 DefaultTileGeometry[] = "120x120+4+3>",
112 DefaultTileLabel[] = "%f\n%G\n%b",
113 LoadImageTag[] = "Load/Image",
114 LoadImagesTag[] = "Load/Images",
115 PSDensityGeometry[] = "72.0x72.0",
116 PSPageGeometry[] = "612x792",
117 SaveImageTag[] = "Save/Image",
118 SaveImagesTag[] = "Save/Images",
119 TransparentColor[] = "#00000000"; /* transparent black */
121 MagickExport const double
122 DefaultResolution = 72.0;
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % A c q u i r e I m a g e %
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % AcquireImage() returns a pointer to an image structure initialized to
138 % The format of the AcquireImage method is:
140 % Image *AcquireImage(const ImageInfo *image_info)
142 % A description of each parameter follows:
144 % o image_info: Many of the image default values are set from this
145 % structure. For example, filename, compression, depth, background color,
149 MagickExport Image *AcquireImage(const ImageInfo *image_info)
161 Allocate image structure.
163 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
164 image=(Image *) AcquireMagickMemory(sizeof(*image));
165 if (image == (Image *) NULL)
166 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
167 (void) ResetMagickMemory(image,0,sizeof(*image));
169 Initialize Image structure.
171 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
172 image->storage_class=DirectClass;
173 image->depth=MAGICKCORE_QUANTUM_DEPTH;
174 image->colorspace=RGBColorspace;
175 image->interlace=NoInterlace;
176 image->ticks_per_second=UndefinedTicksPerSecond;
177 image->compose=OverCompositeOp;
179 GetExceptionInfo(&image->exception);
180 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
182 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
183 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
184 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
186 image->x_resolution=DefaultResolution;
187 image->y_resolution=DefaultResolution;
188 image->units=PixelsPerInchResolution;
189 GetTimerInfo(&image->timer);
190 image->ping=MagickFalse;
191 image->cache=AcquirePixelCache(0);
192 image->channel_mask=DefaultChannels;
193 image->channel_map=AcquirePixelChannelMap();
194 image->blob=CloneBlobInfo((BlobInfo *) NULL);
195 image->debug=IsEventLogging();
196 image->reference_count=1;
197 image->semaphore=AllocateSemaphoreInfo();
198 image->signature=MagickSignature;
199 if (image_info == (ImageInfo *) NULL)
204 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
206 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
207 (void) CopyMagickString(image->magick_filename,image_info->filename,
209 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
210 if (image_info->size != (char *) NULL)
212 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
213 image->columns=image->extract_info.width;
214 image->rows=image->extract_info.height;
215 image->offset=image->extract_info.x;
216 image->extract_info.x=0;
217 image->extract_info.y=0;
219 if (image_info->extract != (char *) NULL)
224 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
225 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
227 image->extract_info=geometry;
228 Swap(image->columns,image->extract_info.width);
229 Swap(image->rows,image->extract_info.height);
232 image->compression=image_info->compression;
233 image->quality=image_info->quality;
234 image->endian=image_info->endian;
235 image->interlace=image_info->interlace;
236 image->units=image_info->units;
237 if (image_info->density != (char *) NULL)
242 flags=ParseGeometry(image_info->density,&geometry_info);
243 image->x_resolution=geometry_info.rho;
244 image->y_resolution=geometry_info.sigma;
245 if ((flags & SigmaValue) == 0)
246 image->y_resolution=image->x_resolution;
248 if (image_info->page != (char *) NULL)
253 image->page=image->extract_info;
254 geometry=GetPageGeometry(image_info->page);
255 (void) ParseAbsoluteGeometry(geometry,&image->page);
256 geometry=DestroyString(geometry);
258 if (image_info->depth != 0)
259 image->depth=image_info->depth;
260 image->dither=image_info->dither;
261 image->background_color=image_info->background_color;
262 image->border_color=image_info->border_color;
263 image->matte_color=image_info->matte_color;
264 image->transparent_color=image_info->transparent_color;
265 image->ping=image_info->ping;
266 image->progress_monitor=image_info->progress_monitor;
267 image->client_data=image_info->client_data;
268 if (image_info->cache != (void *) NULL)
269 ClonePixelCacheMethods(image->cache,image_info->cache);
270 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
271 (void) SyncImageSettings(image_info,image);
272 option=GetImageOption(image_info,"delay");
273 if (option != (const char *) NULL)
278 flags=ParseGeometry(option,&geometry_info);
279 if ((flags & GreaterValue) != 0)
281 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
282 image->delay=(size_t) floor(geometry_info.rho+0.5);
285 if ((flags & LessValue) != 0)
287 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
288 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
291 image->delay=(size_t) floor(geometry_info.rho+0.5);
292 if ((flags & SigmaValue) != 0)
293 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
295 option=GetImageOption(image_info,"dispose");
296 if (option != (const char *) NULL)
297 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 % A c q u i r e I m a g e I n f o %
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 % AcquireImageInfo() allocates the ImageInfo structure.
315 % The format of the AcquireImageInfo method is:
317 % ImageInfo *AcquireImageInfo(void)
320 MagickExport ImageInfo *AcquireImageInfo(void)
325 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
326 if (image_info == (ImageInfo *) NULL)
327 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
328 GetImageInfo(image_info);
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % A c q u i r e N e x t I m a g e %
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 % AcquireNextImage() initializes the next image in a sequence to
344 % default values. The next member of image points to the newly allocated
345 % image. If there is a memory shortage, next is assigned NULL.
347 % The format of the AcquireNextImage method is:
349 % void AcquireNextImage(const ImageInfo *image_info,Image *image)
351 % A description of each parameter follows:
353 % o image_info: Many of the image default values are set from this
354 % structure. For example, filename, compression, depth, background color,
357 % o image: the image.
360 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
363 Allocate image structure.
365 assert(image != (Image *) NULL);
366 assert(image->signature == MagickSignature);
367 if (image->debug != MagickFalse)
368 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
369 image->next=AcquireImage(image_info);
370 if (GetNextImageInList(image) == (Image *) NULL)
372 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
374 if (image_info != (ImageInfo *) NULL)
375 (void) CopyMagickString(GetNextImageInList(image)->filename,
376 image_info->filename,MaxTextExtent);
377 DestroyBlob(GetNextImageInList(image));
378 image->next->blob=ReferenceBlob(image->blob);
379 image->next->endian=image->endian;
380 image->next->scene=image->scene+1;
381 image->next->previous=image;
385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 % A p p e n d I m a g e s %
393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 % AppendImages() takes all images from the current image pointer to the end
396 % of the image list and appends them to each other top-to-bottom if the
397 % stack parameter is true, otherwise left-to-right.
399 % The current gravity setting now effects how the image is justified in the
402 % The format of the AppendImages method is:
404 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
405 % ExceptionInfo *exception)
407 % A description of each parameter follows:
409 % o images: the image sequence.
411 % o stack: A value other than 0 stacks the images top-to-bottom.
413 % o exception: return any errors or warnings in this structure.
416 MagickExport Image *AppendImages(const Image *images,
417 const MagickBooleanType stack,ExceptionInfo *exception)
419 #define AppendImageTag "Append/Image"
456 Compute maximum area of appended area.
458 assert(images != (Image *) NULL);
459 assert(images->signature == MagickSignature);
460 if (images->debug != MagickFalse)
461 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
462 assert(exception != (ExceptionInfo *) NULL);
463 assert(exception->signature == MagickSignature);
467 width=image->columns;
469 next=GetNextImageInList(image);
470 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
472 if (next->matte != MagickFalse)
475 if (stack != MagickFalse)
477 if (next->columns > width)
482 width+=next->columns;
483 if (next->rows > height)
489 append_image=CloneImage(image,width,height,MagickTrue,exception);
490 if (append_image == (Image *) NULL)
491 return((Image *) NULL);
492 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
494 append_image=DestroyImage(append_image);
495 return((Image *) NULL);
497 append_image->matte=matte;
498 (void) SetImageBackgroundColor(append_image);
502 append_view=AcquireCacheView(append_image);
503 for (n=0; n < (MagickOffsetType) number_images; n++)
505 SetGeometry(append_image,&geometry);
506 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
507 if (stack != MagickFalse)
508 x_offset-=geometry.x;
510 y_offset-=geometry.y;
511 image_view=AcquireCacheView(image);
512 #if defined(MAGICKCORE_OPENMP_SUPPORT)
513 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
515 for (y=0; y < (ssize_t) image->rows; y++)
520 register const Quantum
529 if (status == MagickFalse)
531 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
532 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
533 image->columns,1,exception);
534 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
539 for (x=0; x < (ssize_t) image->columns; x++)
541 SetPixelRed(append_image,GetPixelRed(image,p),q);
542 SetPixelGreen(append_image,GetPixelGreen(image,p),q);
543 SetPixelBlue(append_image,GetPixelBlue(image,p),q);
544 if ((image->colorspace == CMYKColorspace) &&
545 (append_image->colorspace == CMYKColorspace))
546 SetPixelBlack(append_image,GetPixelBlack(image,p),q);
547 SetPixelAlpha(append_image,OpaqueAlpha,q);
548 if (image->matte != MagickFalse)
549 SetPixelAlpha(append_image,GetPixelAlpha(image,p),q);
550 p+=GetPixelChannels(image);
551 q+=GetPixelChannels(append_image);
553 sync=SyncCacheViewAuthenticPixels(append_view,exception);
554 if (sync == MagickFalse)
557 image_view=DestroyCacheView(image_view);
558 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
559 if (proceed == MagickFalse)
561 if (stack == MagickFalse)
563 x_offset+=(ssize_t) image->columns;
569 y_offset+=(ssize_t) image->rows;
571 image=GetNextImageInList(image);
573 append_view=DestroyCacheView(append_view);
574 if (status == MagickFalse)
575 append_image=DestroyImage(append_image);
576 return(append_image);
580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584 % C a t c h I m a g e E x c e p t i o n %
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
590 % CatchImageException() returns if no exceptions are found in the image
591 % sequence, otherwise it determines the most severe exception and reports
592 % it as a warning or error depending on the severity.
594 % The format of the CatchImageException method is:
596 % ExceptionType CatchImageException(Image *image)
598 % A description of each parameter follows:
600 % o image: An image sequence.
603 MagickExport ExceptionType CatchImageException(Image *image)
611 assert(image != (const Image *) NULL);
612 assert(image->signature == MagickSignature);
613 if (image->debug != MagickFalse)
614 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
615 exception=AcquireExceptionInfo();
616 GetImageException(image,exception);
617 CatchException(exception);
618 severity=exception->severity;
619 exception=DestroyExceptionInfo(exception);
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % C l i p I m a g e P a t h %
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634 % ClipImagePath() sets the image clip mask based any clipping path information
637 % The format of the ClipImagePath method is:
639 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
640 % const MagickBooleanType inside,ExceptionInfo *exception)
642 % A description of each parameter follows:
644 % o image: the image.
646 % o pathname: name of clipping path resource. If name is preceded by #, use
647 % clipping path numbered by name.
649 % o inside: if non-zero, later operations take effect inside clipping path.
650 % Otherwise later operations take effect outside clipping path.
652 % o exception: return any errors or warnings in this structure.
656 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
658 return(ClipImagePath(image,"#1",MagickTrue,exception));
661 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
662 const MagickBooleanType inside,ExceptionInfo *exception)
664 #define ClipImagePathTag "ClipPath/Image"
678 assert(image != (const Image *) NULL);
679 assert(image->signature == MagickSignature);
680 if (image->debug != MagickFalse)
681 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
682 assert(pathname != NULL);
683 property=AcquireString(pathname);
684 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
686 value=GetImageProperty(image,property);
687 property=DestroyString(property);
688 if (value == (const char *) NULL)
690 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
694 image_info=AcquireImageInfo();
695 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
696 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
697 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
698 image_info=DestroyImageInfo(image_info);
699 if (clip_mask == (Image *) NULL)
701 if (clip_mask->storage_class == PseudoClass)
703 (void) SyncImage(clip_mask);
704 if (SetImageStorageClass(clip_mask,DirectClass,&image->exception) == MagickFalse)
707 if (inside == MagickFalse)
708 (void) NegateImage(clip_mask,MagickFalse,&image->exception);
709 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
710 "8BIM:1999,2998:%s\nPS",pathname);
711 (void) SetImageClipMask(image,clip_mask,exception);
712 clip_mask=DestroyImage(clip_mask);
717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
721 % C l o n e I m a g e %
725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
727 % CloneImage() copies an image and returns the copy as a new image object.
729 % If the specified columns and rows is 0, an exact copy of the image is
730 % returned, otherwise the pixel data is undefined and must be initialized
731 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
732 % failure, a NULL image is returned and exception describes the reason for the
735 % The format of the CloneImage method is:
737 % Image *CloneImage(const Image *image,const size_t columns,
738 % const size_t rows,const MagickBooleanType orphan,
739 % ExceptionInfo *exception)
741 % A description of each parameter follows:
743 % o image: the image.
745 % o columns: the number of columns in the cloned image.
747 % o rows: the number of rows in the cloned image.
749 % o detach: With a value other than 0, the cloned image is detached from
750 % its parent I/O stream.
752 % o exception: return any errors or warnings in this structure.
755 MagickExport Image *CloneImage(const Image *image,const size_t columns,
756 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
770 assert(image != (const Image *) NULL);
771 assert(image->signature == MagickSignature);
772 if (image->debug != MagickFalse)
773 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
774 assert(exception != (ExceptionInfo *) NULL);
775 assert(exception->signature == MagickSignature);
776 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
777 if (clone_image == (Image *) NULL)
778 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
779 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
780 clone_image->signature=MagickSignature;
781 clone_image->storage_class=image->storage_class;
782 clone_image->number_channels=image->number_channels;
783 clone_image->number_meta_channels=image->number_meta_channels;
784 clone_image->metacontent_extent=image->metacontent_extent;
785 clone_image->colorspace=image->colorspace;
786 clone_image->matte=image->matte;
787 clone_image->columns=image->columns;
788 clone_image->rows=image->rows;
789 clone_image->dither=image->dither;
790 if (image->colormap != (PixelPacket *) NULL)
793 Allocate and copy the image colormap.
795 clone_image->colors=image->colors;
796 length=(size_t) image->colors;
797 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
798 sizeof(*clone_image->colormap));
799 if (clone_image->colormap == (PixelPacket *) NULL)
800 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
801 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
802 sizeof(*clone_image->colormap));
804 (void) CloneImageProfiles(clone_image,image);
805 (void) CloneImageProperties(clone_image,image);
806 (void) CloneImageArtifacts(clone_image,image);
807 GetTimerInfo(&clone_image->timer);
808 GetExceptionInfo(&clone_image->exception);
809 InheritException(&clone_image->exception,&image->exception);
810 if (image->ascii85 != (void *) NULL)
811 Ascii85Initialize(clone_image);
812 clone_image->magick_columns=image->magick_columns;
813 clone_image->magick_rows=image->magick_rows;
814 clone_image->type=image->type;
815 clone_image->sync=image->sync;
816 clone_image->channel_mask=image->channel_mask;
817 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
818 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
820 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
821 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
822 clone_image->progress_monitor=image->progress_monitor;
823 clone_image->client_data=image->client_data;
824 clone_image->reference_count=1;
825 clone_image->next=image->next;
826 clone_image->previous=image->previous;
827 clone_image->list=NewImageList();
828 clone_image->clip_mask=NewImageList();
829 clone_image->mask=NewImageList();
830 if (detach == MagickFalse)
831 clone_image->blob=ReferenceBlob(image->blob);
834 clone_image->next=NewImageList();
835 clone_image->previous=NewImageList();
836 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
838 clone_image->ping=image->ping;
839 clone_image->debug=IsEventLogging();
840 clone_image->semaphore=AllocateSemaphoreInfo();
841 if ((columns == 0) && (rows == 0))
843 if (image->montage != (char *) NULL)
844 (void) CloneString(&clone_image->montage,image->montage);
845 if (image->directory != (char *) NULL)
846 (void) CloneString(&clone_image->directory,image->directory);
847 if (image->clip_mask != (Image *) NULL)
848 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
850 if (image->mask != (Image *) NULL)
851 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
852 clone_image->cache=ReferencePixelCache(image->cache);
855 if ((columns == image->columns) && (rows == image->rows))
857 if (image->clip_mask != (Image *) NULL)
858 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
860 if (image->mask != (Image *) NULL)
861 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
863 scale=(MagickRealType) columns/(MagickRealType) image->columns;
864 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
865 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
866 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
867 scale=(MagickRealType) rows/(MagickRealType) image->rows;
868 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
869 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
870 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
871 clone_image->columns=columns;
872 clone_image->rows=rows;
873 clone_image->cache=ClonePixelCache(image->cache);
878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 % C l o n e I m a g e I n f o %
886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
888 % CloneImageInfo() makes a copy of the given image info structure. If
889 % NULL is specified, a new image info structure is created initialized to
892 % The format of the CloneImageInfo method is:
894 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
896 % A description of each parameter follows:
898 % o image_info: the image info.
901 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
906 clone_info=AcquireImageInfo();
907 if (image_info == (ImageInfo *) NULL)
909 clone_info->compression=image_info->compression;
910 clone_info->temporary=image_info->temporary;
911 clone_info->adjoin=image_info->adjoin;
912 clone_info->antialias=image_info->antialias;
913 clone_info->scene=image_info->scene;
914 clone_info->number_scenes=image_info->number_scenes;
915 clone_info->depth=image_info->depth;
916 if (image_info->size != (char *) NULL)
917 (void) CloneString(&clone_info->size,image_info->size);
918 if (image_info->extract != (char *) NULL)
919 (void) CloneString(&clone_info->extract,image_info->extract);
920 if (image_info->scenes != (char *) NULL)
921 (void) CloneString(&clone_info->scenes,image_info->scenes);
922 if (image_info->page != (char *) NULL)
923 (void) CloneString(&clone_info->page,image_info->page);
924 clone_info->interlace=image_info->interlace;
925 clone_info->endian=image_info->endian;
926 clone_info->units=image_info->units;
927 clone_info->quality=image_info->quality;
928 if (image_info->sampling_factor != (char *) NULL)
929 (void) CloneString(&clone_info->sampling_factor,
930 image_info->sampling_factor);
931 if (image_info->server_name != (char *) NULL)
932 (void) CloneString(&clone_info->server_name,image_info->server_name);
933 if (image_info->font != (char *) NULL)
934 (void) CloneString(&clone_info->font,image_info->font);
935 if (image_info->texture != (char *) NULL)
936 (void) CloneString(&clone_info->texture,image_info->texture);
937 if (image_info->density != (char *) NULL)
938 (void) CloneString(&clone_info->density,image_info->density);
939 clone_info->pointsize=image_info->pointsize;
940 clone_info->fuzz=image_info->fuzz;
941 clone_info->background_color=image_info->background_color;
942 clone_info->border_color=image_info->border_color;
943 clone_info->matte_color=image_info->matte_color;
944 clone_info->transparent_color=image_info->transparent_color;
945 clone_info->dither=image_info->dither;
946 clone_info->monochrome=image_info->monochrome;
947 clone_info->colors=image_info->colors;
948 clone_info->colorspace=image_info->colorspace;
949 clone_info->type=image_info->type;
950 clone_info->orientation=image_info->orientation;
951 clone_info->preview_type=image_info->preview_type;
952 clone_info->group=image_info->group;
953 clone_info->ping=image_info->ping;
954 clone_info->verbose=image_info->verbose;
955 if (image_info->view != (char *) NULL)
956 (void) CloneString(&clone_info->view,image_info->view);
957 if (image_info->authenticate != (char *) NULL)
958 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
959 (void) CloneImageOptions(clone_info,image_info);
960 clone_info->progress_monitor=image_info->progress_monitor;
961 clone_info->client_data=image_info->client_data;
962 clone_info->cache=image_info->cache;
963 if (image_info->cache != (void *) NULL)
964 clone_info->cache=ReferencePixelCache(image_info->cache);
965 if (image_info->profile != (void *) NULL)
966 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
967 image_info->profile);
968 SetImageInfoFile(clone_info,image_info->file);
969 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
970 clone_info->stream=image_info->stream;
971 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
972 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
973 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
974 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
975 (void) CopyMagickString(clone_info->filename,image_info->filename,
977 clone_info->channel=image_info->channel;
978 clone_info->debug=IsEventLogging();
979 clone_info->signature=image_info->signature;
984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
988 % C o m b i n e I m a g e s %
992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994 % CombineImages() combines one or more images into a single image. The
995 % grayscale value of the pixels of each image in the sequence is assigned in
996 % order to the specified channels of the combined image. The typical
997 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
999 % The format of the CombineImages method is:
1001 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
1003 % A description of each parameter follows:
1005 % o image: the image.
1007 % o exception: return any errors or warnings in this structure.
1010 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1012 #define CombineImageTag "Combine/Image"
1033 Ensure the image are the same size.
1035 assert(image != (const Image *) NULL);
1036 assert(image->signature == MagickSignature);
1037 if (image->debug != MagickFalse)
1038 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1039 assert(exception != (ExceptionInfo *) NULL);
1040 assert(exception->signature == MagickSignature);
1041 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1043 if ((next->columns != image->columns) || (next->rows != image->rows))
1044 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1046 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1047 if (combine_image == (Image *) NULL)
1048 return((Image *) NULL);
1049 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1051 combine_image=DestroyImage(combine_image);
1052 return((Image *) NULL);
1054 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1055 combine_image->matte=MagickTrue;
1056 (void) SetImageBackgroundColor(combine_image);
1062 combine_view=AcquireCacheView(combine_image);
1063 for (y=0; y < (ssize_t) combine_image->rows; y++)
1074 register const Quantum
1083 if (status == MagickFalse)
1085 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1087 if (pixels == (Quantum *) NULL)
1093 if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) &&
1094 (next != (Image *) NULL))
1096 image_view=AcquireCacheView(next);
1097 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1098 if (p == (const Quantum *) NULL)
1101 for (x=0; x < (ssize_t) combine_image->columns; x++)
1103 SetPixelRed(image,GetPixelIntensity(image,p),q);
1104 p+=GetPixelChannels(image);
1105 q+=GetPixelChannels(combine_image);
1107 image_view=DestroyCacheView(image_view);
1108 next=GetNextImageInList(next);
1110 if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) &&
1111 (next != (Image *) NULL))
1113 image_view=AcquireCacheView(next);
1114 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1115 if (p == (const Quantum *) NULL)
1118 for (x=0; x < (ssize_t) combine_image->columns; x++)
1120 SetPixelGreen(image,GetPixelIntensity(image,p),q);
1121 p+=GetPixelChannels(image);
1122 q+=GetPixelChannels(combine_image);
1124 image_view=DestroyCacheView(image_view);
1125 next=GetNextImageInList(next);
1127 if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) &&
1128 (next != (Image *) NULL))
1130 image_view=AcquireCacheView(next);
1131 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1132 if (p == (const Quantum *) NULL)
1135 for (x=0; x < (ssize_t) combine_image->columns; x++)
1137 SetPixelBlue(image,GetPixelIntensity(image,p),q);
1138 p+=GetPixelChannels(image);
1139 q+=GetPixelChannels(combine_image);
1141 image_view=DestroyCacheView(image_view);
1142 next=GetNextImageInList(next);
1144 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
1145 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1147 image_view=AcquireCacheView(next);
1148 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1149 if (p == (const Quantum *) NULL)
1152 for (x=0; x < (ssize_t) combine_image->columns; x++)
1154 SetPixelBlack(image,GetPixelIntensity(image,p),q);
1155 p+=GetPixelChannels(image);
1156 q+=GetPixelChannels(combine_image);
1158 image_view=DestroyCacheView(image_view);
1159 next=GetNextImageInList(next);
1161 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
1162 (next != (Image *) NULL))
1164 image_view=AcquireCacheView(next);
1165 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1166 if (p == (const Quantum *) NULL)
1169 for (x=0; x < (ssize_t) combine_image->columns; x++)
1171 SetPixelAlpha(image,GetPixelIntensity(image,p),q);
1172 p+=GetPixelChannels(image);
1173 q+=GetPixelChannels(combine_image);
1175 image_view=DestroyCacheView(image_view);
1176 next=GetNextImageInList(next);
1178 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1180 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1185 proceed=SetImageProgress(image,CombineImageTag,progress++,
1186 combine_image->rows);
1187 if (proceed == MagickFalse)
1191 combine_view=DestroyCacheView(combine_view);
1192 if (status == MagickFalse)
1193 combine_image=DestroyImage(combine_image);
1194 return(combine_image);
1198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1202 % D e s t r o y I m a g e %
1206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1208 % DestroyImage() dereferences an image, deallocating memory associated with
1209 % the image if the reference count becomes zero.
1211 % The format of the DestroyImage method is:
1213 % Image *DestroyImage(Image *image)
1215 % A description of each parameter follows:
1217 % o image: the image.
1220 MagickExport Image *DestroyImage(Image *image)
1228 assert(image != (Image *) NULL);
1229 assert(image->signature == MagickSignature);
1230 if (image->debug != MagickFalse)
1231 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1232 destroy=MagickFalse;
1233 LockSemaphoreInfo(image->semaphore);
1234 image->reference_count--;
1235 if (image->reference_count == 0)
1237 UnlockSemaphoreInfo(image->semaphore);
1238 if (destroy == MagickFalse)
1239 return((Image *) NULL);
1243 DestroyImagePixels(image);
1244 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1245 if (image->clip_mask != (Image *) NULL)
1246 image->clip_mask=DestroyImage(image->clip_mask);
1247 if (image->mask != (Image *) NULL)
1248 image->mask=DestroyImage(image->mask);
1249 if (image->montage != (char *) NULL)
1250 image->montage=DestroyString(image->montage);
1251 if (image->directory != (char *) NULL)
1252 image->directory=DestroyString(image->directory);
1253 if (image->colormap != (PixelPacket *) NULL)
1254 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1255 if (image->geometry != (char *) NULL)
1256 image->geometry=DestroyString(image->geometry);
1257 DestroyImageProfiles(image);
1258 DestroyImageProperties(image);
1259 DestroyImageArtifacts(image);
1260 if (image->ascii85 != (Ascii85Info*) NULL)
1261 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1263 (void) DestroyExceptionInfo(&image->exception);
1264 if (image->semaphore != (SemaphoreInfo *) NULL)
1265 DestroySemaphoreInfo(&image->semaphore);
1266 image->signature=(~MagickSignature);
1267 image=(Image *) RelinquishMagickMemory(image);
1272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1276 % D e s t r o y I m a g e I n f o %
1280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1282 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1285 % The format of the DestroyImageInfo method is:
1287 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1289 % A description of each parameter follows:
1291 % o image_info: the image info.
1294 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1296 assert(image_info != (ImageInfo *) NULL);
1297 assert(image_info->signature == MagickSignature);
1298 if (image_info->debug != MagickFalse)
1299 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1300 image_info->filename);
1301 if (image_info->size != (char *) NULL)
1302 image_info->size=DestroyString(image_info->size);
1303 if (image_info->extract != (char *) NULL)
1304 image_info->extract=DestroyString(image_info->extract);
1305 if (image_info->scenes != (char *) NULL)
1306 image_info->scenes=DestroyString(image_info->scenes);
1307 if (image_info->page != (char *) NULL)
1308 image_info->page=DestroyString(image_info->page);
1309 if (image_info->sampling_factor != (char *) NULL)
1310 image_info->sampling_factor=DestroyString(
1311 image_info->sampling_factor);
1312 if (image_info->server_name != (char *) NULL)
1313 image_info->server_name=DestroyString(
1314 image_info->server_name);
1315 if (image_info->font != (char *) NULL)
1316 image_info->font=DestroyString(image_info->font);
1317 if (image_info->texture != (char *) NULL)
1318 image_info->texture=DestroyString(image_info->texture);
1319 if (image_info->density != (char *) NULL)
1320 image_info->density=DestroyString(image_info->density);
1321 if (image_info->view != (char *) NULL)
1322 image_info->view=DestroyString(image_info->view);
1323 if (image_info->authenticate != (char *) NULL)
1324 image_info->authenticate=DestroyString(
1325 image_info->authenticate);
1326 DestroyImageOptions(image_info);
1327 if (image_info->cache != (void *) NULL)
1328 image_info->cache=DestroyPixelCache(image_info->cache);
1329 if (image_info->profile != (StringInfo *) NULL)
1330 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1331 image_info->profile);
1332 image_info->signature=(~MagickSignature);
1333 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342 + D i s a s s o c i a t e I m a g e S t r e a m %
1346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1348 % DisassociateImageStream() disassociates the image stream.
1350 % The format of the DisassociateImageStream method is:
1352 % MagickBooleanType DisassociateImageStream(const Image *image)
1354 % A description of each parameter follows:
1356 % o image: the image.
1359 MagickExport void DisassociateImageStream(Image *image)
1361 assert(image != (const Image *) NULL);
1362 assert(image->signature == MagickSignature);
1363 if (image->debug != MagickFalse)
1364 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1365 (void) DetachBlob(image->blob);
1369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1373 % G e t I m a g e A l p h a C h a n n e l %
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1379 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1380 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1383 % The format of the GetImageAlphaChannel method is:
1385 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1387 % A description of each parameter follows:
1389 % o image: the image.
1392 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1394 assert(image != (const Image *) NULL);
1395 if (image->debug != MagickFalse)
1396 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1397 assert(image->signature == MagickSignature);
1398 return(image->matte);
1402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1406 % G e t I m a g e C l i p M a s k %
1410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412 % GetImageClipMask() returns the clip path associated with the image.
1414 % The format of the GetImageClipMask method is:
1416 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1418 % A description of each parameter follows:
1420 % o image: the image.
1423 MagickExport Image *GetImageClipMask(const Image *image,
1424 ExceptionInfo *exception)
1426 assert(image != (const Image *) NULL);
1427 if (image->debug != MagickFalse)
1428 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1429 assert(image->signature == MagickSignature);
1430 if (image->clip_mask == (Image *) NULL)
1431 return((Image *) NULL);
1432 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1440 % G e t I m a g e E x c e p t i o n %
1444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1446 % GetImageException() traverses an image sequence and returns any
1447 % error more severe than noted by the exception parameter.
1449 % The format of the GetImageException method is:
1451 % void GetImageException(Image *image,ExceptionInfo *exception)
1453 % A description of each parameter follows:
1455 % o image: Specifies a pointer to a list of one or more images.
1457 % o exception: return the highest severity exception.
1460 MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1465 assert(image != (Image *) NULL);
1466 assert(image->signature == MagickSignature);
1467 if (image->debug != MagickFalse)
1468 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1469 assert(exception != (ExceptionInfo *) NULL);
1470 assert(exception->signature == MagickSignature);
1471 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1473 if (next->exception.severity == UndefinedException)
1475 if (next->exception.severity > exception->severity)
1476 InheritException(exception,&next->exception);
1477 next->exception.severity=UndefinedException;
1482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1486 % G e t I m a g e I n f o %
1490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1492 % GetImageInfo() initializes image_info to default values.
1494 % The format of the GetImageInfo method is:
1496 % void GetImageInfo(ImageInfo *image_info)
1498 % A description of each parameter follows:
1500 % o image_info: the image info.
1503 MagickExport void GetImageInfo(ImageInfo *image_info)
1512 File and image dimension members.
1514 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1515 assert(image_info != (ImageInfo *) NULL);
1516 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1517 image_info->adjoin=MagickTrue;
1518 image_info->interlace=NoInterlace;
1519 image_info->channel=DefaultChannels;
1520 image_info->quality=UndefinedCompressionQuality;
1521 image_info->antialias=MagickTrue;
1522 image_info->dither=MagickTrue;
1523 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1524 if (synchronize != (const char *) NULL)
1525 image_info->synchronize=IsMagickTrue(synchronize);
1526 exception=AcquireExceptionInfo();
1527 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1529 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1530 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1531 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1533 exception=DestroyExceptionInfo(exception);
1534 image_info->debug=IsEventLogging();
1535 image_info->signature=MagickSignature;
1539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1543 % G e t I m a g e I n f o F i l e %
1547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1549 % GetImageInfoFile() returns the image info file member.
1551 % The format of the GetImageInfoFile method is:
1553 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1555 % A description of each parameter follows:
1557 % o image_info: the image info.
1560 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1562 return(image_info->file);
1566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1570 % G e t I m a g e M a s k %
1574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1576 % GetImageMask() returns the mask associated with the image.
1578 % The format of the GetImageMask method is:
1580 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1582 % A description of each parameter follows:
1584 % o image: the image.
1587 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1589 assert(image != (const Image *) NULL);
1590 if (image->debug != MagickFalse)
1591 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1592 assert(image->signature == MagickSignature);
1593 if (image->mask == (Image *) NULL)
1594 return((Image *) NULL);
1595 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1603 + G e t I m a g e R e f e r e n c e C o u n t %
1607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1609 % GetImageReferenceCount() returns the image reference count.
1611 % The format of the GetReferenceCount method is:
1613 % ssize_t GetImageReferenceCount(Image *image)
1615 % A description of each parameter follows:
1617 % o image: the image.
1620 MagickExport ssize_t GetImageReferenceCount(Image *image)
1625 assert(image != (Image *) NULL);
1626 assert(image->signature == MagickSignature);
1627 if (image->debug != MagickFalse)
1628 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1629 LockSemaphoreInfo(image->semaphore);
1630 reference_count=image->reference_count;
1631 UnlockSemaphoreInfo(image->semaphore);
1632 return(reference_count);
1636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 % 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 %
1644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1646 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1647 % image. A virtual pixel is any pixel access that is outside the boundaries
1648 % of the image cache.
1650 % The format of the GetImageVirtualPixelMethod() method is:
1652 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1654 % A description of each parameter follows:
1656 % o image: the image.
1659 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1661 assert(image != (Image *) NULL);
1662 assert(image->signature == MagickSignature);
1663 if (image->debug != MagickFalse)
1664 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1665 return(GetPixelCacheVirtualMethod(image));
1669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1673 % I n t e r p r e t I m a g e F i l e n a m e %
1677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1679 % InterpretImageFilename() interprets embedded characters in an image filename.
1680 % The filename length is returned.
1682 % The format of the InterpretImageFilename method is:
1684 % size_t InterpretImageFilename(const ImageInfo *image_info,
1685 % Image *image,const char *format,int value,char *filename)
1687 % A description of each parameter follows.
1689 % o image_info: the image info..
1691 % o image: the image.
1693 % o format: A filename describing the format to use to write the numeric
1694 % argument. Only the first numeric format identifier is replaced.
1696 % o value: Numeric value to substitute into format filename.
1698 % o filename: return the formatted filename in this character buffer.
1701 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1702 Image *image,const char *format,int value,char *filename)
1719 canonical=MagickFalse;
1721 (void) CopyMagickString(filename,format,MaxTextExtent);
1722 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1735 value=(ssize_t) strtol(q,&q,10);
1747 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1748 (p-format)),p,value);
1750 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1751 canonical=MagickTrue;
1760 pattern[MaxTextExtent];
1777 if (strchr(p,']') == (char *) NULL)
1781 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1792 if (LocaleNCompare(pattern,"filename:",9) != 0)
1794 value=(const char *) NULL;
1795 if ((image_info != (const ImageInfo *) NULL) &&
1796 (image != (const Image *) NULL))
1797 value=GetMagickProperty(image_info,image,pattern);
1799 if (image != (Image *) NULL)
1800 value=GetImageProperty(image,pattern);
1802 if (image_info != (ImageInfo *) NULL)
1803 value=GetImageOption(image_info,pattern);
1804 if (value == (const char *) NULL)
1809 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1810 (MaxTextExtent-(p-format-length)));
1811 length+=strlen(pattern)-1;
1813 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1814 canonical=MagickTrue;
1824 for (q=filename; *q != '\0'; q++)
1825 if ((*q == '%') && (*(q+1) == '%'))
1827 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1828 canonical=MagickTrue;
1830 if (canonical == MagickFalse)
1831 (void) CopyMagickString(filename,format,MaxTextExtent);
1832 return(strlen(filename));
1836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1840 % I s H i g h D y n a m i c R a n g e I m a g e %
1844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1846 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1847 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1850 % The format of the IsHighDynamicRangeImage method is:
1852 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1853 % ExceptionInfo *exception)
1855 % A description of each parameter follows:
1857 % o image: the image.
1859 % o exception: return any errors or warnings in this structure.
1862 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1863 ExceptionInfo *exception)
1865 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1868 return(MagickFalse);
1882 assert(image != (Image *) NULL);
1883 assert(image->signature == MagickSignature);
1884 if (image->debug != MagickFalse)
1885 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1887 GetPixelInfo(image,&zero);
1888 image_view=AcquireCacheView(image);
1889 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1890 #pragma omp parallel for schedule(dynamic,4) shared(status)
1892 for (y=0; y < (ssize_t) image->rows; y++)
1897 register const Quantum
1903 if (status == MagickFalse)
1905 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1906 if (p == (const Quantum *) NULL)
1912 for (x=0; x < (ssize_t) image->columns; x++)
1914 SetPixelInfo(image,p,&pixel);
1915 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1916 (pixel.red != (QuantumAny) pixel.red))
1918 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1919 (pixel.green != (QuantumAny) pixel.green))
1921 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1922 (pixel.blue != (QuantumAny) pixel.blue))
1924 if (pixel.colorspace == CMYKColorspace)
1926 if ((pixel.black < 0.0) || (pixel.black > QuantumRange) ||
1927 (pixel.black != (QuantumAny) pixel.black))
1930 if (pixel.matte != MagickFalse)
1932 if ((pixel.alpha < 0.0) || (pixel.alpha > QuantumRange) ||
1933 (pixel.alpha != (QuantumAny) pixel.alpha))
1936 p+=GetPixelChannels(image);
1938 if (x < (ssize_t) image->columns)
1941 image_view=DestroyCacheView(image_view);
1942 return(status != MagickFalse ? MagickFalse : MagickTrue);
1947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1951 % I s I m a g e O b j e c t %
1955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1957 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1958 % set of image objects.
1960 % The format of the IsImageObject method is:
1962 % MagickBooleanType IsImageObject(const Image *image)
1964 % A description of each parameter follows:
1966 % o image: the image.
1969 MagickExport MagickBooleanType IsImageObject(const Image *image)
1971 register const Image
1974 assert(image != (Image *) NULL);
1975 if (image->debug != MagickFalse)
1976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1977 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1978 if (p->signature != MagickSignature)
1979 return(MagickFalse);
1984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1988 % I s T a i n t I m a g e %
1992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1994 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1995 % since it was first constituted.
1997 % The format of the IsTaintImage method is:
1999 % MagickBooleanType IsTaintImage(const Image *image)
2001 % A description of each parameter follows:
2003 % o image: the image.
2006 MagickExport MagickBooleanType IsTaintImage(const Image *image)
2009 magick[MaxTextExtent],
2010 filename[MaxTextExtent];
2012 register const Image
2015 assert(image != (Image *) NULL);
2016 if (image->debug != MagickFalse)
2017 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2018 assert(image->signature == MagickSignature);
2019 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2020 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2021 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2023 if (p->taint != MagickFalse)
2025 if (LocaleCompare(p->magick,magick) != 0)
2027 if (LocaleCompare(p->filename,filename) != 0)
2030 return(MagickFalse);
2034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2038 % M o d i f y I m a g e %
2042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2044 % ModifyImage() ensures that there is only a single reference to the image
2045 % to be modified, updating the provided image pointer to point to a clone of
2046 % the original image if necessary.
2048 % The format of the ModifyImage method is:
2050 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2052 % A description of each parameter follows:
2054 % o image: the image.
2056 % o exception: return any errors or warnings in this structure.
2059 MagickExport MagickBooleanType ModifyImage(Image **image,
2060 ExceptionInfo *exception)
2065 assert(image != (Image **) NULL);
2066 assert(*image != (Image *) NULL);
2067 assert((*image)->signature == MagickSignature);
2068 if ((*image)->debug != MagickFalse)
2069 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2070 if (GetImageReferenceCount(*image) <= 1)
2072 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2073 LockSemaphoreInfo((*image)->semaphore);
2074 (*image)->reference_count--;
2075 UnlockSemaphoreInfo((*image)->semaphore);
2081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2085 % N e w M a g i c k I m a g e %
2089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2091 % NewMagickImage() creates a blank image canvas of the specified size and
2094 % The format of the NewMagickImage method is:
2096 % Image *NewMagickImage(const ImageInfo *image_info,
2097 % const size_t width,const size_t height,
2098 % const PixelInfo *background)
2100 % A description of each parameter follows:
2102 % o image: the image.
2104 % o width: the image width.
2106 % o height: the image height.
2108 % o background: the image color.
2111 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2112 const size_t width,const size_t height,
2113 const PixelInfo *background)
2130 assert(image_info != (const ImageInfo *) NULL);
2131 if (image_info->debug != MagickFalse)
2132 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2133 assert(image_info->signature == MagickSignature);
2134 assert(background != (const PixelInfo *) NULL);
2135 image=AcquireImage(image_info);
2136 image->columns=width;
2138 image->colorspace=background->colorspace;
2139 image->matte=background->matte;
2140 image->fuzz=background->fuzz;
2141 image->depth=background->depth;
2143 exception=(&image->exception);
2144 image_view=AcquireCacheView(image);
2145 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2146 #pragma omp parallel for schedule(dynamic,4) shared(status)
2148 for (y=0; y < (ssize_t) image->rows; y++)
2156 if (status == MagickFalse)
2158 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2159 if (q == (Quantum *) NULL)
2164 for (x=0; x < (ssize_t) image->columns; x++)
2166 SetPixelPixelInfo(image,background,q);
2167 q+=GetPixelChannels(image);
2169 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2172 image_view=DestroyCacheView(image_view);
2173 if (status == MagickFalse)
2174 image=DestroyImage(image);
2179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2183 % R e f e r e n c e I m a g e %
2187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2189 % ReferenceImage() increments the reference count associated with an image
2190 % returning a pointer to the image.
2192 % The format of the ReferenceImage method is:
2194 % Image *ReferenceImage(Image *image)
2196 % A description of each parameter follows:
2198 % o image: the image.
2201 MagickExport Image *ReferenceImage(Image *image)
2203 assert(image != (Image *) NULL);
2204 if (image->debug != MagickFalse)
2205 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2206 assert(image->signature == MagickSignature);
2207 LockSemaphoreInfo(image->semaphore);
2208 image->reference_count++;
2209 UnlockSemaphoreInfo(image->semaphore);
2214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2218 % R e s e t I m a g e P a g e %
2222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2224 % ResetImagePage() resets the image page canvas and position.
2226 % The format of the ResetImagePage method is:
2228 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2230 % A description of each parameter follows:
2232 % o image: the image.
2234 % o page: the relative page specification.
2237 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2245 assert(image != (Image *) NULL);
2246 assert(image->signature == MagickSignature);
2247 if (image->debug != MagickFalse)
2248 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2249 flags=ParseAbsoluteGeometry(page,&geometry);
2250 if ((flags & WidthValue) != 0)
2252 if ((flags & HeightValue) == 0)
2253 geometry.height=geometry.width;
2254 image->page.width=geometry.width;
2255 image->page.height=geometry.height;
2257 if ((flags & AspectValue) != 0)
2259 if ((flags & XValue) != 0)
2260 image->page.x+=geometry.x;
2261 if ((flags & YValue) != 0)
2262 image->page.y+=geometry.y;
2266 if ((flags & XValue) != 0)
2268 image->page.x=geometry.x;
2269 if ((image->page.width == 0) && (geometry.x > 0))
2270 image->page.width=image->columns+geometry.x;
2272 if ((flags & YValue) != 0)
2274 image->page.y=geometry.y;
2275 if ((image->page.height == 0) && (geometry.y > 0))
2276 image->page.height=image->rows+geometry.y;
2283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2287 % S e p a r a t e I m a g e C h a n n e l %
2291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2293 % SeparateImage() separates a channel from the image and returns it as
2294 % a grayscale image. A channel is a particular color component of each pixel
2297 % The format of the SeparateImage method is:
2299 % MagickBooleanType SeparateImage(Image *image)
2301 % A description of each parameter follows:
2303 % o image: the image.
2306 MagickExport MagickBooleanType SeparateImage(Image *image)
2308 #define SeparateImageTag "Separate/Image"
2325 assert(image != (Image *) NULL);
2326 assert(image->signature == MagickSignature);
2327 if (image->debug != MagickFalse)
2328 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2329 exception=(&image->exception);
2330 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2331 return(MagickFalse);
2333 Separate image channels.
2337 image_view=AcquireCacheView(image);
2338 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2339 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2341 for (y=0; y < (ssize_t) image->rows; y++)
2349 if (status == MagickFalse)
2351 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2352 if (q == (Quantum *) NULL)
2357 for (x=0; x < (ssize_t) image->columns; x++)
2359 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2361 SetPixelGreen(image,GetPixelRed(image,q),q);
2362 SetPixelBlue(image,GetPixelRed(image,q),q);
2364 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2366 SetPixelRed(image,GetPixelGreen(image,q),q);
2367 SetPixelBlue(image,GetPixelGreen(image,q),q);
2369 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2371 SetPixelRed(image,GetPixelBlue(image,q),q);
2372 SetPixelGreen(image,GetPixelBlue(image,q),q);
2374 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2375 (image->colorspace == CMYKColorspace))
2377 SetPixelRed(image,GetPixelBlack(image,q),q);
2378 SetPixelGreen(image,GetPixelBlack(image,q),q);
2379 SetPixelBlue(image,GetPixelBlack(image,q),q);
2381 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2382 (image->matte != MagickFalse))
2384 SetPixelRed(image,GetPixelAlpha(image,q),q);
2385 SetPixelGreen(image,GetPixelAlpha(image,q),q);
2386 SetPixelBlue(image,GetPixelAlpha(image,q),q);
2388 q+=GetPixelChannels(image);
2390 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2392 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2397 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2398 #pragma omp critical (MagickCore_SeparateImage)
2400 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2401 if (proceed == MagickFalse)
2405 image_view=DestroyCacheView(image_view);
2406 (void) SetImageColorspace(image,RGBColorspace,exception);
2411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2415 % S e p a r a t e I m a g e s %
2419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2421 % SeparateImages() returns a separate grayscale image for each channel
2424 % The format of the SeparateImages method is:
2426 % MagickBooleanType SeparateImages(const Image *image,
2427 % ExceptionInfo *exception)
2429 % A description of each parameter follows:
2431 % o image: the image.
2433 % o exception: return any errors or warnings in this structure.
2436 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2445 assert(image != (Image *) NULL);
2446 assert(image->signature == MagickSignature);
2447 if (image->debug != MagickFalse)
2448 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2449 images=NewImageList();
2450 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2452 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2453 channel_mask=SetPixelChannelMask(separate_image,RedChannel);
2454 (void) SeparateImage(separate_image);
2455 (void) SetPixelChannelMap(separate_image,channel_mask);
2456 AppendImageToList(&images,separate_image);
2458 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2460 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2461 channel_mask=SetPixelChannelMask(separate_image,GreenChannel);
2462 (void) SeparateImage(separate_image);
2463 (void) SetPixelChannelMap(separate_image,channel_mask);
2464 AppendImageToList(&images,separate_image);
2466 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2468 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2469 channel_mask=SetPixelChannelMask(separate_image,BlueChannel);
2470 (void) SeparateImage(separate_image);
2471 (void) SetPixelChannelMap(separate_image,channel_mask);
2472 AppendImageToList(&images,separate_image);
2474 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2475 (image->colorspace == CMYKColorspace))
2477 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2478 channel_mask=SetPixelChannelMask(separate_image,BlackChannel);
2479 (void) SeparateImage(separate_image);
2480 (void) SetPixelChannelMap(separate_image,channel_mask);
2481 AppendImageToList(&images,separate_image);
2483 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2485 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2486 channel_mask=SetPixelChannelMask(separate_image,AlphaChannel);
2487 (void) SeparateImage(separate_image);
2488 (void) SetPixelChannelMap(separate_image,channel_mask);
2489 AppendImageToList(&images,separate_image);
2495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2499 % S e t I m a g e A l p h a C h a n n e l %
2503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2505 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2508 % The format of the SetImageAlphaChannel method is:
2510 % MagickBooleanType SetImageAlphaChannel(Image *image,
2511 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2513 % A description of each parameter follows:
2515 % o image: the image.
2517 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2518 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2519 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2520 % TransparentAlphaChannel.
2522 % o exception: return any errors or warnings in this structure.
2525 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2526 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2534 assert(image != (Image *) NULL);
2535 if (image->debug != MagickFalse)
2536 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2537 assert(image->signature == MagickSignature);
2541 case ActivateAlphaChannel:
2543 image->matte=MagickTrue;
2546 case BackgroundAlphaChannel:
2561 Set transparent pixels to background color.
2563 if (image->matte == MagickFalse)
2565 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2567 GetPixelInfo(image,&background);
2568 SetPixelInfoPacket(image,&image->background_color,&background);
2569 if (image->colorspace == CMYKColorspace)
2570 ConvertRGBToCMYK(&background);
2571 SetPacketPixelInfo(image,&background,&pixel);
2572 image_view=AcquireCacheView(image);
2573 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2574 #pragma omp parallel for schedule(dynamic,4) shared(status)
2576 for (y=0; y < (ssize_t) image->rows; y++)
2584 if (status == MagickFalse)
2586 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2588 if (q == (Quantum *) NULL)
2593 for (x=0; x < (ssize_t) image->columns; x++)
2595 if (GetPixelAlpha(image,q) == TransparentAlpha)
2597 SetPixelRed(image,pixel.red,q);
2598 SetPixelGreen(image,pixel.green,q);
2599 SetPixelBlue(image,pixel.blue,q);
2600 if (image->colorspace == CMYKColorspace)
2601 SetPixelBlack(image,pixel.black,q);
2603 q+=GetPixelChannels(image);
2605 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2608 image_view=DestroyCacheView(image_view);
2611 case DeactivateAlphaChannel:
2613 image->matte=MagickFalse;
2616 case ShapeAlphaChannel:
2617 case CopyAlphaChannel:
2620 Special usage case for SeparateImage(): copy grayscale color to
2623 channel_mask=SetPixelChannelMask(image,GrayChannel);
2624 status=SeparateImage(image);
2625 (void) SetPixelChannelMask(image,channel_mask);
2626 image->matte=MagickTrue; /* make sure transparency is now on! */
2627 if (alpha_type == ShapeAlphaChannel)
2633 Reset all color channels to background color.
2635 GetPixelInfo(image,&background);
2636 SetPixelInfoPacket(image,&(image->background_color),&background);
2637 (void) LevelImageColors(image,&background,&background,MagickTrue,
2642 case ExtractAlphaChannel:
2644 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2645 status=SeparateImage(image);
2646 (void) SetPixelChannelMask(image,channel_mask);
2647 image->matte=MagickFalse;
2650 case OpaqueAlphaChannel:
2652 status=SetImageOpacity(image,OpaqueAlpha);
2653 image->matte=MagickTrue;
2656 case TransparentAlphaChannel:
2658 status=SetImageOpacity(image,TransparentAlpha);
2659 image->matte=MagickTrue;
2662 case SetAlphaChannel:
2664 if (image->matte == MagickFalse)
2666 status=SetImageOpacity(image,OpaqueAlpha);
2667 image->matte=MagickTrue;
2671 case UndefinedAlphaChannel:
2674 if (status == MagickFalse)
2676 return(SyncImagePixelCache(image,exception));
2680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2684 % S e t I m a g e B a c k g r o u n d C o l o r %
2688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2690 % SetImageBackgroundColor() initializes the image pixels to the image
2691 % background color. The background color is defined by the background_color
2692 % member of the image structure.
2694 % The format of the SetImage method is:
2696 % MagickBooleanType SetImageBackgroundColor(Image *image)
2698 % A description of each parameter follows:
2700 % o image: the image.
2703 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2723 assert(image != (Image *) NULL);
2724 if (image->debug != MagickFalse)
2725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2726 assert(image->signature == MagickSignature);
2727 exception=(&image->exception);
2728 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2729 return(MagickFalse);
2730 if (image->background_color.alpha != OpaqueAlpha)
2731 image->matte=MagickTrue;
2732 GetPixelInfo(image,&background);
2733 SetPixelInfoPacket(image,&image->background_color,&background);
2734 if (image->colorspace == CMYKColorspace)
2735 ConvertRGBToCMYK(&background);
2736 SetPacketPixelInfo(image,&background,&pixel);
2738 Set image background color.
2742 image_view=AcquireCacheView(image);
2743 for (y=0; y < (ssize_t) image->rows; y++)
2751 if (status == MagickFalse)
2753 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2754 if (q == (Quantum *) NULL)
2759 for (x=0; x < (ssize_t) image->columns; x++)
2761 SetPixelPacket(image,&pixel,q);
2762 if (image->colorspace == CMYKColorspace)
2763 SetPixelBlack(image,pixel.black,q);
2764 q+=GetPixelChannels(image);
2766 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2769 image_view=DestroyCacheView(image_view);
2774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2778 % S e t I m a g e C o l o r %
2782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2784 % SetImageColor() set the entire image canvas to the specified color.
2786 % The format of the SetImageColor method is:
2788 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color)
2790 % A description of each parameter follows:
2792 % o image: the image.
2794 % o background: the image color.
2797 MagickExport MagickBooleanType SetImageColor(Image *image,
2798 const PixelInfo *color)
2812 assert(image != (Image *) NULL);
2813 if (image->debug != MagickFalse)
2814 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2815 assert(image->signature == MagickSignature);
2816 assert(color != (const PixelInfo *) NULL);
2817 image->colorspace=color->colorspace;
2818 image->matte=color->matte;
2819 image->fuzz=color->fuzz;
2820 image->depth=color->depth;
2822 exception=(&image->exception);
2823 image_view=AcquireCacheView(image);
2824 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2825 #pragma omp parallel for schedule(dynamic,4) shared(status)
2827 for (y=0; y < (ssize_t) image->rows; y++)
2835 if (status == MagickFalse)
2837 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2838 if (q == (Quantum *) NULL)
2843 for (x=0; x < (ssize_t) image->columns; x++)
2845 SetPixelPixelInfo(image,color,q);
2846 q+=GetPixelChannels(image);
2848 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2851 image_view=DestroyCacheView(image_view);
2856 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2860 % S e t I m a g e S t o r a g e C l a s s %
2864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2866 % SetImageStorageClass() sets the image class: DirectClass for true color
2867 % images or PseudoClass for colormapped images.
2869 % The format of the SetImageStorageClass method is:
2871 % MagickBooleanType SetImageStorageClass(Image *image,
2872 % const ClassType storage_class,ExceptionInfo *exception)
2874 % A description of each parameter follows:
2876 % o image: the image.
2878 % o storage_class: The image class.
2880 % o exception: return any errors or warnings in this structure.
2883 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2884 const ClassType storage_class,ExceptionInfo *exception)
2886 image->storage_class=storage_class;
2887 return(SyncImagePixelCache(image,exception));
2891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2895 % S e t I m a g e C l i p M a s k %
2899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2901 % SetImageClipMask() associates a clip path with the image. The clip path
2902 % must be the same dimensions as the image. Set any pixel component of
2903 % the clip path to TransparentAlpha to prevent that corresponding image
2904 % pixel component from being updated when SyncAuthenticPixels() is applied.
2906 % The format of the SetImageClipMask method is:
2908 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2909 % ExceptionInfo *exception)
2911 % A description of each parameter follows:
2913 % o image: the image.
2915 % o clip_mask: the image clip path.
2917 % o exception: return any errors or warnings in this structure.
2920 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2921 const Image *clip_mask,ExceptionInfo *exception)
2923 assert(image != (Image *) NULL);
2924 if (image->debug != MagickFalse)
2925 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2926 assert(image->signature == MagickSignature);
2927 if (clip_mask != (const Image *) NULL)
2928 if ((clip_mask->columns != image->columns) ||
2929 (clip_mask->rows != image->rows))
2930 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2931 if (image->clip_mask != (Image *) NULL)
2932 image->clip_mask=DestroyImage(image->clip_mask);
2933 image->clip_mask=NewImageList();
2934 if (clip_mask == (Image *) NULL)
2936 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
2937 return(MagickFalse);
2938 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2939 if (image->clip_mask == (Image *) NULL)
2940 return(MagickFalse);
2945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2949 % S e t I m a g e E x t e n t %
2953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2955 % SetImageExtent() sets the image size (i.e. columns & rows).
2957 % The format of the SetImageExtent method is:
2959 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2960 % const size_t rows,ExceptionInfo *exception)
2962 % A description of each parameter follows:
2964 % o image: the image.
2966 % o columns: The image width in pixels.
2968 % o rows: The image height in pixels.
2970 % o exception: return any errors or warnings in this structure.
2973 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2974 const size_t rows,ExceptionInfo *exception)
2976 if ((columns == 0) || (rows == 0))
2977 return(MagickFalse);
2978 image->columns=columns;
2980 return(SyncImagePixelCache(image,exception));
2984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2988 + S e t I m a g e I n f o %
2992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2994 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2995 % It is set to a type of image format based on the prefix or suffix of the
2996 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2997 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2998 % precendence over the suffix. Use an optional index enclosed in brackets
2999 % after a file name to specify a desired scene of a multi-resolution image
3000 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
3001 % indicates success.
3003 % The format of the SetImageInfo method is:
3005 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
3006 % const unsigned int frames,ExceptionInfo *exception)
3008 % A description of each parameter follows:
3010 % o image_info: the image info.
3012 % o frames: the number of images you intend to write.
3014 % o exception: return any errors or warnings in this structure.
3017 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
3018 const unsigned int frames,ExceptionInfo *exception)
3021 extension[MaxTextExtent],
3022 filename[MaxTextExtent],
3023 magic[MaxTextExtent],
3025 subimage[MaxTextExtent];
3049 magick[2*MaxTextExtent];
3052 Look for 'image.format' in filename.
3054 assert(image_info != (ImageInfo *) NULL);
3055 assert(image_info->signature == MagickSignature);
3056 if (image_info->debug != MagickFalse)
3057 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3058 image_info->filename);
3062 GetPathComponent(image_info->filename,SubimagePath,subimage);
3063 if (*subimage != '\0')
3066 Look for scene specification (e.g. img0001.pcd[4]).
3068 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3070 if (IsGeometry(subimage) != MagickFalse)
3071 (void) CloneString(&image_info->extract,subimage);
3079 (void) CloneString(&image_info->scenes,subimage);
3080 image_info->scene=StringToUnsignedLong(image_info->scenes);
3081 image_info->number_scenes=image_info->scene;
3082 p=image_info->scenes;
3083 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3085 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3088 first=(size_t) strtol(p,&q,10);
3090 while (isspace((int) ((unsigned char) *q)) != 0)
3093 last=(size_t) strtol(q+1,&q,10);
3096 if (first < image_info->scene)
3097 image_info->scene=first;
3098 if (last > image_info->number_scenes)
3099 image_info->number_scenes=last;
3102 image_info->number_scenes-=image_info->scene-1;
3107 GetPathComponent(image_info->filename,ExtensionPath,extension);
3108 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3109 if (*extension != '\0')
3110 if ((LocaleCompare(extension,"gz") == 0) ||
3111 (LocaleCompare(extension,"Z") == 0) ||
3112 (LocaleCompare(extension,"wmz") == 0))
3115 path[MaxTextExtent];
3117 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3118 path[strlen(path)-strlen(extension)-1]='\0';
3119 GetPathComponent(path,ExtensionPath,extension);
3122 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3123 if (*extension != '\0')
3124 if (LocaleCompare(extension,"bz2") == 0)
3127 path[MaxTextExtent];
3129 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3130 path[strlen(path)-strlen(extension)-1]='\0';
3131 GetPathComponent(path,ExtensionPath,extension);
3134 image_info->affirm=MagickFalse;
3135 sans_exception=AcquireExceptionInfo();
3136 if (*extension != '\0')
3145 *format_type_formats[] =
3168 User specified image format.
3170 (void) CopyMagickString(magic,extension,MaxTextExtent);
3173 Look for explicit image formats.
3175 format_type=UndefinedFormatType;
3177 while ((format_type == UndefinedFormatType) &&
3178 (format_type_formats[i] != (char *) NULL))
3180 if ((*magic == *format_type_formats[i]) &&
3181 (LocaleCompare(magic,format_type_formats[i]) == 0))
3182 format_type=ExplicitFormatType;
3185 magick_info=GetMagickInfo(magic,sans_exception);
3186 if ((magick_info != (const MagickInfo *) NULL) &&
3187 (magick_info->format_type != UndefinedFormatType))
3188 format_type=magick_info->format_type;
3189 if (format_type == UndefinedFormatType)
3190 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3192 if (format_type == ExplicitFormatType)
3194 image_info->affirm=MagickTrue;
3195 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3197 if (LocaleCompare(magic,"RGB") == 0)
3198 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3201 Look for explicit 'format:image' in filename.
3204 GetPathComponent(image_info->filename,MagickPath,magic);
3206 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3210 User specified image format.
3213 if (IsMagickConflict(magic) == MagickFalse)
3215 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3216 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3217 image_info->affirm=MagickTrue;
3219 image_info->temporary=MagickTrue;
3222 magick_info=GetMagickInfo(magic,sans_exception);
3223 sans_exception=DestroyExceptionInfo(sans_exception);
3224 if ((magick_info == (const MagickInfo *) NULL) ||
3225 (GetMagickEndianSupport(magick_info) == MagickFalse))
3226 image_info->endian=UndefinedEndian;
3227 GetPathComponent(image_info->filename,CanonicalPath,filename);
3228 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3229 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3232 Test for multiple image support (e.g. image%02d.png).
3234 (void) InterpretImageFilename(image_info,(Image *) NULL,
3235 image_info->filename,(int) image_info->scene,filename);
3236 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3237 (strchr(filename,'%') == (char *) NULL))
3238 image_info->adjoin=MagickFalse;
3240 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3243 Some image formats do not support multiple frames per file.
3245 magick_info=GetMagickInfo(magic,exception);
3246 if (magick_info != (const MagickInfo *) NULL)
3247 if (GetMagickAdjoin(magick_info) == MagickFalse)
3248 image_info->adjoin=MagickFalse;
3250 if (image_info->affirm != MagickFalse)
3255 Determine the image format from the first few bytes of the file.
3257 image=AcquireImage(image_info);
3258 (void) CopyMagickString(image->filename,image_info->filename,
3260 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3261 if (status == MagickFalse)
3263 image=DestroyImage(image);
3264 return(MagickFalse);
3266 if ((IsBlobSeekable(image) == MagickFalse) ||
3267 (IsBlobExempt(image) != MagickFalse))
3270 Copy standard input or pipe to temporary file.
3273 status=ImageToFile(image,filename,exception);
3274 (void) CloseBlob(image);
3275 if (status == MagickFalse)
3277 image=DestroyImage(image);
3278 return(MagickFalse);
3280 SetImageInfoFile(image_info,(FILE *) NULL);
3281 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3282 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3283 if (status == MagickFalse)
3285 image=DestroyImage(image);
3286 return(MagickFalse);
3288 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3289 image_info->temporary=MagickTrue;
3291 (void) ResetMagickMemory(magick,0,sizeof(magick));
3292 count=ReadBlob(image,2*MaxTextExtent,magick);
3293 (void) CloseBlob(image);
3294 image=DestroyImage(image);
3296 Check magic.xml configuration file.
3298 sans_exception=AcquireExceptionInfo();
3299 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3300 if ((magic_info != (const MagicInfo *) NULL) &&
3301 (GetMagicName(magic_info) != (char *) NULL))
3303 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3305 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3306 if ((magick_info == (const MagickInfo *) NULL) ||
3307 (GetMagickEndianSupport(magick_info) == MagickFalse))
3308 image_info->endian=UndefinedEndian;
3309 sans_exception=DestroyExceptionInfo(sans_exception);
3312 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3313 if ((magick_info == (const MagickInfo *) NULL) ||
3314 (GetMagickEndianSupport(magick_info) == MagickFalse))
3315 image_info->endian=UndefinedEndian;
3316 sans_exception=DestroyExceptionInfo(sans_exception);
3322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3326 % S e t I m a g e I n f o B l o b %
3330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3332 % SetImageInfoBlob() sets the image info blob member.
3334 % The format of the SetImageInfoBlob method is:
3336 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3337 % const size_t length)
3339 % A description of each parameter follows:
3341 % o image_info: the image info.
3345 % o length: the blob length.
3348 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3349 const size_t length)
3351 assert(image_info != (ImageInfo *) NULL);
3352 assert(image_info->signature == MagickSignature);
3353 if (image_info->debug != MagickFalse)
3354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3355 image_info->filename);
3356 image_info->blob=(void *) blob;
3357 image_info->length=length;
3361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3365 % S e t I m a g e I n f o F i l e %
3369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3371 % SetImageInfoFile() sets the image info file member.
3373 % The format of the SetImageInfoFile method is:
3375 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3377 % A description of each parameter follows:
3379 % o image_info: the image info.
3384 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3386 assert(image_info != (ImageInfo *) NULL);
3387 assert(image_info->signature == MagickSignature);
3388 if (image_info->debug != MagickFalse)
3389 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3390 image_info->filename);
3391 image_info->file=file;
3395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3399 % S e t I m a g e M a s k %
3403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3405 % SetImageMask() associates a mask with the image. The mask must be the same
3406 % dimensions as the image.
3408 % The format of the SetImageMask method is:
3410 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3411 % ExceptionInfo *exception)
3413 % A description of each parameter follows:
3415 % o image: the image.
3417 % o mask: the image mask.
3419 % o exception: return any errors or warnings in this structure.
3422 MagickExport MagickBooleanType SetImageMask(Image *image,
3423 const Image *mask,ExceptionInfo *exception)
3425 assert(image != (Image *) NULL);
3426 if (image->debug != MagickFalse)
3427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3428 assert(image->signature == MagickSignature);
3429 if (mask != (const Image *) NULL)
3430 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3431 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3432 if (image->mask != (Image *) NULL)
3433 image->mask=DestroyImage(image->mask);
3434 image->mask=NewImageList();
3435 if (mask == (Image *) NULL)
3437 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
3438 return(MagickFalse);
3439 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3440 if (image->mask == (Image *) NULL)
3441 return(MagickFalse);
3446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3450 % S e t I m a g e O p a c i t y %
3454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3456 % SetImageOpacity() sets the opacity levels of the image.
3458 % The format of the SetImageOpacity method is:
3460 % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3462 % A description of each parameter follows:
3464 % o image: the image.
3466 % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3467 % fully transparent.
3470 MagickExport MagickBooleanType SetImageOpacity(Image *image,
3471 const Quantum opacity)
3485 assert(image != (Image *) NULL);
3486 if (image->debug != MagickFalse)
3487 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3488 assert(image->signature == MagickSignature);
3489 image->matte=opacity != OpaqueAlpha ? MagickTrue : MagickFalse;
3491 exception=(&image->exception);
3492 image_view=AcquireCacheView(image);
3493 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3494 #pragma omp parallel for schedule(dynamic,4) shared(status)
3496 for (y=0; y < (ssize_t) image->rows; y++)
3504 if (status == MagickFalse)
3506 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3507 if (q == (Quantum *) NULL)
3512 for (x=0; x < (ssize_t) image->columns; x++)
3514 SetPixelAlpha(image,opacity,q);
3515 q+=GetPixelChannels(image);
3517 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3520 image_view=DestroyCacheView(image_view);
3525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3529 % S e t I m a g e T y p e %
3533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3535 % SetImageType() sets the type of image. Choose from these types:
3537 % Bilevel Grayscale GrayscaleMatte
3538 % Palette PaletteMatte TrueColor
3539 % TrueColorMatte ColorSeparation ColorSeparationMatte
3542 % The format of the SetImageType method is:
3544 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3545 % ExceptionInfo *exception)
3547 % A description of each parameter follows:
3549 % o image: the image.
3551 % o type: Image type.
3553 % o exception: return any errors or warnings in this structure.
3556 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3557 ExceptionInfo *exception)
3571 assert(image != (Image *) NULL);
3572 if (image->debug != MagickFalse)
3573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3574 assert(image->signature == MagickSignature);
3576 image_info=AcquireImageInfo();
3577 image_info->dither=image->dither;
3578 artifact=GetImageArtifact(image,"dither");
3579 if (artifact != (const char *) NULL)
3580 (void) SetImageOption(image_info,"dither",artifact);
3585 if (IsImageGray(image,&image->exception) == MagickFalse)
3586 status=TransformImageColorspace(image,GRAYColorspace);
3587 if (IsImageMonochrome(image,&image->exception) == MagickFalse)
3589 quantize_info=AcquireQuantizeInfo(image_info);
3590 quantize_info->number_colors=2;
3591 quantize_info->colorspace=GRAYColorspace;
3592 status=QuantizeImage(quantize_info,image,exception);
3593 quantize_info=DestroyQuantizeInfo(quantize_info);
3595 image->matte=MagickFalse;
3600 if (IsImageGray(image,&image->exception) == MagickFalse)
3601 status=TransformImageColorspace(image,GRAYColorspace);
3602 image->matte=MagickFalse;
3605 case GrayscaleMatteType:
3607 if (IsImageGray(image,&image->exception) == MagickFalse)
3608 status=TransformImageColorspace(image,GRAYColorspace);
3609 if (image->matte == MagickFalse)
3610 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3615 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3616 status=TransformImageColorspace(image,RGBColorspace);
3617 if ((image->storage_class == DirectClass) || (image->colors > 256))
3619 quantize_info=AcquireQuantizeInfo(image_info);
3620 quantize_info->number_colors=256;
3621 status=QuantizeImage(quantize_info,image,exception);
3622 quantize_info=DestroyQuantizeInfo(quantize_info);
3624 image->matte=MagickFalse;
3627 case PaletteBilevelMatteType:
3632 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3633 status=TransformImageColorspace(image,RGBColorspace);
3634 if (image->matte == MagickFalse)
3635 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3636 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3637 (void) BilevelImage(image,(double) QuantumRange/2.0);
3638 (void) SetPixelChannelMask(image,channel_mask);
3639 quantize_info=AcquireQuantizeInfo(image_info);
3640 status=QuantizeImage(quantize_info,image,exception);
3641 quantize_info=DestroyQuantizeInfo(quantize_info);
3644 case PaletteMatteType:
3646 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3647 status=TransformImageColorspace(image,RGBColorspace);
3648 if (image->matte == MagickFalse)
3649 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3650 quantize_info=AcquireQuantizeInfo(image_info);
3651 quantize_info->colorspace=TransparentColorspace;
3652 status=QuantizeImage(quantize_info,image,exception);
3653 quantize_info=DestroyQuantizeInfo(quantize_info);
3658 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3659 status=TransformImageColorspace(image,RGBColorspace);
3660 if (image->storage_class != DirectClass)
3661 status=SetImageStorageClass(image,DirectClass,&image->exception);
3662 image->matte=MagickFalse;
3665 case TrueColorMatteType:
3667 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3668 status=TransformImageColorspace(image,RGBColorspace);
3669 if (image->storage_class != DirectClass)
3670 status=SetImageStorageClass(image,DirectClass,&image->exception);
3671 if (image->matte == MagickFalse)
3672 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3675 case ColorSeparationType:
3677 if (image->colorspace != CMYKColorspace)
3679 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3680 status=TransformImageColorspace(image,RGBColorspace);
3681 status=TransformImageColorspace(image,CMYKColorspace);
3683 if (image->storage_class != DirectClass)
3684 status=SetImageStorageClass(image,DirectClass,&image->exception);
3685 image->matte=MagickFalse;
3688 case ColorSeparationMatteType:
3690 if (image->colorspace != CMYKColorspace)
3692 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3693 status=TransformImageColorspace(image,RGBColorspace);
3694 status=TransformImageColorspace(image,CMYKColorspace);
3696 if (image->storage_class != DirectClass)
3697 status=SetImageStorageClass(image,DirectClass,&image->exception);
3698 if (image->matte == MagickFalse)
3699 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3707 image_info=DestroyImageInfo(image_info);
3712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3716 % 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 %
3720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3722 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3723 % image and returns the previous setting. A virtual pixel is any pixel access
3724 % that is outside the boundaries of the image cache.
3726 % The format of the SetImageVirtualPixelMethod() method is:
3728 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3729 % const VirtualPixelMethod virtual_pixel_method)
3731 % A description of each parameter follows:
3733 % o image: the image.
3735 % o virtual_pixel_method: choose the type of virtual pixel.
3738 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3739 const VirtualPixelMethod virtual_pixel_method)
3741 assert(image != (const Image *) NULL);
3742 assert(image->signature == MagickSignature);
3743 if (image->debug != MagickFalse)
3744 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3745 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3753 % S m u s h I m a g e s %
3757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3759 % SmushImages() takes all images from the current image pointer to the end
3760 % of the image list and smushes them to each other top-to-bottom if the
3761 % stack parameter is true, otherwise left-to-right.
3763 % The current gravity setting now effects how the image is justified in the
3766 % The format of the SmushImages method is:
3768 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3769 % ExceptionInfo *exception)
3771 % A description of each parameter follows:
3773 % o images: the image sequence.
3775 % o stack: A value other than 0 stacks the images top-to-bottom.
3777 % o offset: minimum distance in pixels between images.
3779 % o exception: return any errors or warnings in this structure.
3783 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3784 const ssize_t offset,ExceptionInfo *exception)
3798 register const Quantum
3811 if (images->previous == (Image *) NULL)
3814 SetGeometry(smush_image,&right_geometry);
3815 GravityAdjustGeometry(right_image->columns,right_image->rows,
3816 right_image->gravity,&right_geometry);
3817 left_image=images->previous;
3818 SetGeometry(smush_image,&left_geometry);
3819 GravityAdjustGeometry(left_image->columns,left_image->rows,
3820 left_image->gravity,&left_geometry);
3821 gap=right_image->columns;
3822 left_view=AcquireCacheView(left_image);
3823 right_view=AcquireCacheView(right_image);
3824 for (y=0; y < (ssize_t) smush_image->rows; y++)
3826 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3828 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3829 if ((p == (const Quantum *) NULL) ||
3830 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3831 ((left_image->columns-x-1) >= gap))
3834 i=(ssize_t) left_image->columns-x-1;
3835 for (x=0; x < (ssize_t) right_image->columns; x++)
3837 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3839 if ((p == (const Quantum *) NULL) ||
3840 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3841 ((x+i) >= (ssize_t) gap))
3844 if ((x+i) < (ssize_t) gap)
3847 right_view=DestroyCacheView(right_view);
3848 left_view=DestroyCacheView(left_view);
3849 if (y < (ssize_t) smush_image->rows)
3851 return((ssize_t) gap-offset);
3854 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3855 const ssize_t offset,ExceptionInfo *exception)
3869 register const Quantum
3882 if (images->previous == (Image *) NULL)
3884 bottom_image=images;
3885 SetGeometry(smush_image,&bottom_geometry);
3886 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3887 bottom_image->gravity,&bottom_geometry);
3888 top_image=images->previous;
3889 SetGeometry(smush_image,&top_geometry);
3890 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3892 gap=bottom_image->rows;
3893 top_view=AcquireCacheView(top_image);
3894 bottom_view=AcquireCacheView(bottom_image);
3895 for (x=0; x < (ssize_t) smush_image->columns; x++)
3897 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3899 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3900 if ((p == (const Quantum *) NULL) ||
3901 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3902 ((top_image->rows-y-1) >= gap))
3905 i=(ssize_t) top_image->rows-y-1;
3906 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3908 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3910 if ((p == (const Quantum *) NULL) ||
3911 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3912 ((y+i) >= (ssize_t) gap))
3915 if ((y+i) < (ssize_t) gap)
3918 bottom_view=DestroyCacheView(bottom_view);
3919 top_view=DestroyCacheView(top_view);
3920 if (x < (ssize_t) smush_image->columns)
3922 return((ssize_t) gap-offset);
3925 MagickExport Image *SmushImages(const Image *images,
3926 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3928 #define SmushImageTag "Smush/Image"
3950 register const Image
3963 Compute maximum area of smushed area.
3965 assert(images != (Image *) NULL);
3966 assert(images->signature == MagickSignature);
3967 if (images->debug != MagickFalse)
3968 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3969 assert(exception != (ExceptionInfo *) NULL);
3970 assert(exception->signature == MagickSignature);
3974 width=image->columns;
3976 next=GetNextImageInList(image);
3977 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3979 if (next->matte != MagickFalse)
3982 if (stack != MagickFalse)
3984 if (next->columns > width)
3985 width=next->columns;
3987 if (next->previous != (Image *) NULL)
3991 width+=next->columns;
3992 if (next->previous != (Image *) NULL)
3994 if (next->rows > height)
4000 smush_image=CloneImage(image,width,height,MagickTrue,exception);
4001 if (smush_image == (Image *) NULL)
4002 return((Image *) NULL);
4003 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
4005 smush_image=DestroyImage(smush_image);
4006 return((Image *) NULL);
4008 smush_image->matte=matte;
4009 (void) SetImageBackgroundColor(smush_image);
4013 smush_view=AcquireCacheView(smush_image);
4014 for (n=0; n < (MagickOffsetType) number_images; n++)
4016 SetGeometry(smush_image,&geometry);
4017 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4018 if (stack != MagickFalse)
4020 x_offset-=geometry.x;
4021 y_offset-=SmushYGap(smush_image,image,offset,exception);
4025 x_offset-=SmushXGap(smush_image,image,offset,exception);
4026 y_offset-=geometry.y;
4028 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
4029 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4030 if (proceed == MagickFalse)
4032 if (stack == MagickFalse)
4034 x_offset+=(ssize_t) image->columns;
4040 y_offset+=(ssize_t) image->rows;
4042 image=GetNextImageInList(image);
4044 if (stack == MagickFalse)
4045 smush_image->columns=(size_t) x_offset;
4047 smush_image->rows=(size_t) y_offset;
4048 smush_view=DestroyCacheView(smush_view);
4049 if (status == MagickFalse)
4050 smush_image=DestroyImage(smush_image);
4051 return(smush_image);
4055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4059 % S t r i p I m a g e %
4063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4065 % StripImage() strips an image of all profiles and comments.
4067 % The format of the StripImage method is:
4069 % MagickBooleanType StripImage(Image *image)
4071 % A description of each parameter follows:
4073 % o image: the image.
4076 MagickExport MagickBooleanType StripImage(Image *image)
4078 assert(image != (Image *) NULL);
4079 if (image->debug != MagickFalse)
4080 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4081 DestroyImageProfiles(image);
4082 (void) DeleteImageProperty(image,"comment");
4083 (void) DeleteImageProperty(image,"date:create");
4084 (void) DeleteImageProperty(image,"date:modify");
4085 (void) SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4094 + S y n c I m a g e %
4098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4100 % SyncImage() initializes the red, green, and blue intensities of each pixel
4101 % as defined by the colormap index.
4103 % The format of the SyncImage method is:
4105 % MagickBooleanType SyncImage(Image *image)
4107 % A description of each parameter follows:
4109 % o image: the image.
4113 static inline Quantum PushColormapIndex(Image *image,
4114 const size_t index,MagickBooleanType *range_exception)
4116 if (index < image->colors)
4117 return((Quantum) index);
4118 *range_exception=MagickTrue;
4119 return((Quantum) 0);
4122 MagickExport MagickBooleanType SyncImage(Image *image)
4137 assert(image != (Image *) NULL);
4138 if (image->debug != MagickFalse)
4139 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4140 assert(image->signature == MagickSignature);
4141 if (image->storage_class == DirectClass)
4142 return(MagickFalse);
4143 range_exception=MagickFalse;
4145 exception=(&image->exception);
4146 image_view=AcquireCacheView(image);
4147 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4148 #pragma omp parallel for schedule(dynamic,4) shared(status)
4150 for (y=0; y < (ssize_t) image->rows; y++)
4161 if (status == MagickFalse)
4163 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4164 if (q == (Quantum *) NULL)
4169 for (x=0; x < (ssize_t) image->columns; x++)
4171 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4173 SetPixelPacket(image,image->colormap+(ssize_t) index,q);
4174 q+=GetPixelChannels(image);
4176 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4179 image_view=DestroyCacheView(image_view);
4180 if (range_exception != MagickFalse)
4181 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4182 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4191 % S y n c I m a g e S e t t i n g s %
4195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4197 % SyncImageSettings() sync the image info options to the image.
4199 % The format of the SyncImageSettings method is:
4201 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4203 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4206 % A description of each parameter follows:
4208 % o image_info: the image info.
4210 % o image: the image.
4214 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4220 assert(image_info != (const ImageInfo *) NULL);
4221 assert(image_info->signature == MagickSignature);
4222 assert(images != (Image *) NULL);
4223 assert(images->signature == MagickSignature);
4224 if (images->debug != MagickFalse)
4225 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4227 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4228 (void) SyncImageSettings(image_info,image);
4229 (void) DeleteImageOption(image_info,"page");
4233 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4237 property[MaxTextExtent];
4255 assert(image_info != (const ImageInfo *) NULL);
4256 assert(image_info->signature == MagickSignature);
4257 assert(image != (Image *) NULL);
4258 assert(image->signature == MagickSignature);
4259 if (image->debug != MagickFalse)
4260 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4261 option=GetImageOption(image_info,"background");
4262 if (option != (const char *) NULL)
4263 (void) QueryColorDatabase(option,&image->background_color,
4265 option=GetImageOption(image_info,"bias");
4266 if (option != (const char *) NULL)
4267 image->bias=SiPrefixToDouble(option,QuantumRange);
4268 option=GetImageOption(image_info,"black-point-compensation");
4269 if (option != (const char *) NULL)
4270 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4271 MagickBooleanOptions,MagickFalse,option);
4272 option=GetImageOption(image_info,"blue-primary");
4273 if (option != (const char *) NULL)
4275 flags=ParseGeometry(option,&geometry_info);
4276 image->chromaticity.blue_primary.x=geometry_info.rho;
4277 image->chromaticity.blue_primary.y=geometry_info.sigma;
4278 if ((flags & SigmaValue) == 0)
4279 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4281 option=GetImageOption(image_info,"bordercolor");
4282 if (option != (const char *) NULL)
4283 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4284 option=GetImageOption(image_info,"colors");
4285 if (option != (const char *) NULL)
4286 image->colors=StringToUnsignedLong(option);
4287 option=GetImageOption(image_info,"compose");
4288 if (option != (const char *) NULL)
4289 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4290 MagickFalse,option);
4291 option=GetImageOption(image_info,"compress");
4292 if (option != (const char *) NULL)
4293 image->compression=(CompressionType) ParseCommandOption(
4294 MagickCompressOptions,MagickFalse,option);
4295 option=GetImageOption(image_info,"debug");
4296 if (option != (const char *) NULL)
4297 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4298 MagickFalse,option);
4299 option=GetImageOption(image_info,"density");
4300 if (option != (const char *) NULL)
4308 flags=ParseGeometry(option,&geometry_info);
4309 image->x_resolution=geometry_info.rho;
4310 image->y_resolution=geometry_info.sigma;
4311 if ((flags & SigmaValue) == 0)
4312 image->y_resolution=image->x_resolution;
4314 option=GetImageOption(image_info,"depth");
4315 if (option != (const char *) NULL)
4316 image->depth=StringToUnsignedLong(option);
4317 option=GetImageOption(image_info,"endian");
4318 if (option != (const char *) NULL)
4319 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4320 MagickFalse,option);
4321 option=GetImageOption(image_info,"filter");
4322 if (option != (const char *) NULL)
4323 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4324 MagickFalse,option);
4325 option=GetImageOption(image_info,"fuzz");
4326 if (option != (const char *) NULL)
4327 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4328 option=GetImageOption(image_info,"gravity");
4329 if (option != (const char *) NULL)
4330 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4331 MagickFalse,option);
4332 option=GetImageOption(image_info,"green-primary");
4333 if (option != (const char *) NULL)
4335 flags=ParseGeometry(option,&geometry_info);
4336 image->chromaticity.green_primary.x=geometry_info.rho;
4337 image->chromaticity.green_primary.y=geometry_info.sigma;
4338 if ((flags & SigmaValue) == 0)
4339 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4341 option=GetImageOption(image_info,"intent");
4342 if (option != (const char *) NULL)
4343 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4344 MagickIntentOptions,MagickFalse,option);
4345 option=GetImageOption(image_info,"interlace");
4346 if (option != (const char *) NULL)
4347 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4348 MagickFalse,option);
4349 option=GetImageOption(image_info,"interpolate");
4350 if (option != (const char *) NULL)
4351 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
4352 MagickInterpolateOptions,MagickFalse,option);
4353 option=GetImageOption(image_info,"loop");
4354 if (option != (const char *) NULL)
4355 image->iterations=StringToUnsignedLong(option);
4356 option=GetImageOption(image_info,"mattecolor");
4357 if (option != (const char *) NULL)
4358 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4359 option=GetImageOption(image_info,"orient");
4360 if (option != (const char *) NULL)
4361 image->orientation=(OrientationType) ParseCommandOption(
4362 MagickOrientationOptions,MagickFalse,option);
4363 option=GetImageOption(image_info,"page");
4364 if (option != (const char *) NULL)
4369 geometry=GetPageGeometry(option);
4370 flags=ParseAbsoluteGeometry(geometry,&image->page);
4371 geometry=DestroyString(geometry);
4373 option=GetImageOption(image_info,"quality");
4374 if (option != (const char *) NULL)
4375 image->quality=StringToUnsignedLong(option);
4376 option=GetImageOption(image_info,"red-primary");
4377 if (option != (const char *) NULL)
4379 flags=ParseGeometry(option,&geometry_info);
4380 image->chromaticity.red_primary.x=geometry_info.rho;
4381 image->chromaticity.red_primary.y=geometry_info.sigma;
4382 if ((flags & SigmaValue) == 0)
4383 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4385 if (image_info->quality != UndefinedCompressionQuality)
4386 image->quality=image_info->quality;
4387 option=GetImageOption(image_info,"scene");
4388 if (option != (const char *) NULL)
4389 image->scene=StringToUnsignedLong(option);
4390 option=GetImageOption(image_info,"taint");
4391 if (option != (const char *) NULL)
4392 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4393 MagickFalse,option);
4394 option=GetImageOption(image_info,"tile-offset");
4395 if (option != (const char *) NULL)
4400 geometry=GetPageGeometry(option);
4401 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4402 geometry=DestroyString(geometry);
4404 option=GetImageOption(image_info,"transparent-color");
4405 if (option != (const char *) NULL)
4406 (void) QueryColorDatabase(option,&image->transparent_color,
4408 option=GetImageOption(image_info,"type");
4409 if (option != (const char *) NULL)
4410 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4412 option=GetImageOption(image_info,"units");
4413 if (option != (const char *) NULL)
4414 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4415 MagickFalse,option);
4417 units = image_info->units;
4418 if (units != UndefinedResolution)
4420 if (image->units != units)
4421 switch (image->units)
4423 case PixelsPerInchResolution:
4425 if (units == PixelsPerCentimeterResolution)
4427 image->x_resolution/=2.54;
4428 image->y_resolution/=2.54;
4432 case PixelsPerCentimeterResolution:
4434 if (units == PixelsPerInchResolution)
4436 image->x_resolution=(double) ((size_t) (100.0*2.54*
4437 image->x_resolution+0.5))/100.0;
4438 image->y_resolution=(double) ((size_t) (100.0*2.54*
4439 image->y_resolution+0.5))/100.0;
4448 option=GetImageOption(image_info,"white-point");
4449 if (option != (const char *) NULL)
4451 flags=ParseGeometry(option,&geometry_info);
4452 image->chromaticity.white_point.x=geometry_info.rho;
4453 image->chromaticity.white_point.y=geometry_info.sigma;
4454 if ((flags & SigmaValue) == 0)
4455 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4457 ResetImageOptionIterator(image_info);
4458 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4460 value=GetImageOption(image_info,option);
4461 if (value != (const char *) NULL)
4463 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4464 (void) SetImageArtifact(image,property,value);
4466 option=GetNextImageOption(image_info);