2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII M M AAA GGGG EEEEE %
8 % I M M M AAAAA G GG EEE %
10 % IIIII M M A A GGGG EEEEE %
13 % MagickCore Image Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/memory_.h"
75 #include "MagickCore/module.h"
76 #include "MagickCore/monitor.h"
77 #include "MagickCore/monitor-private.h"
78 #include "MagickCore/option.h"
79 #include "MagickCore/paint.h"
80 #include "MagickCore/pixel-accessor.h"
81 #include "MagickCore/profile.h"
82 #include "MagickCore/property.h"
83 #include "MagickCore/quantize.h"
84 #include "MagickCore/random_.h"
85 #include "MagickCore/segment.h"
86 #include "MagickCore/semaphore.h"
87 #include "MagickCore/signature-private.h"
88 #include "MagickCore/statistic.h"
89 #include "MagickCore/string_.h"
90 #include "MagickCore/string-private.h"
91 #include "MagickCore/thread-private.h"
92 #include "MagickCore/threshold.h"
93 #include "MagickCore/timer.h"
94 #include "MagickCore/utility.h"
95 #include "MagickCore/utility-private.h"
96 #include "MagickCore/version.h"
97 #include "MagickCore/xwindow-private.h"
100 Constant declaration.
103 BackgroundColor[] = "#ffffff", /* white */
104 BorderColor[] = "#dfdfdf", /* gray */
105 DefaultTileFrame[] = "15x15+3+3",
106 DefaultTileGeometry[] = "120x120+4+3>",
107 DefaultTileLabel[] = "%f\n%G\n%b",
108 ForegroundColor[] = "#000", /* black */
109 LoadImageTag[] = "Load/Image",
110 LoadImagesTag[] = "Load/Images",
111 MatteColor[] = "#bdbdbd", /* gray */
112 PSDensityGeometry[] = "72.0x72.0",
113 PSPageGeometry[] = "612x792",
114 SaveImageTag[] = "Save/Image",
115 SaveImagesTag[] = "Save/Images",
116 TransparentColor[] = "#00000000"; /* transparent black */
119 DefaultResolution = 72.0;
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 % A c q u i r e I m a g e %
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 % AcquireImage() returns a pointer to an image structure initialized to
135 % The format of the AcquireImage method is:
137 % Image *AcquireImage(const ImageInfo *image_info)
139 % A description of each parameter follows:
141 % o image_info: Many of the image default values are set from this
142 % structure. For example, filename, compression, depth, background color,
146 MagickExport Image *AcquireImage(const ImageInfo *image_info)
158 Allocate image structure.
160 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
161 image=(Image *) AcquireMagickMemory(sizeof(*image));
162 if (image == (Image *) NULL)
163 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
164 (void) ResetMagickMemory(image,0,sizeof(*image));
166 Initialize Image structure.
168 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
169 image->storage_class=DirectClass;
170 image->depth=MAGICKCORE_QUANTUM_DEPTH;
171 image->colorspace=RGBColorspace;
172 image->interlace=NoInterlace;
173 image->ticks_per_second=UndefinedTicksPerSecond;
174 image->compose=OverCompositeOp;
176 GetExceptionInfo(&image->exception);
177 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
179 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
180 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
181 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
183 image->x_resolution=DefaultResolution;
184 image->y_resolution=DefaultResolution;
185 image->units=PixelsPerInchResolution;
186 GetTimerInfo(&image->timer);
187 image->ping=MagickFalse;
188 image->cache=AcquirePixelCache(0);
189 image->channel_mask=DefaultChannels;
190 image->channel_map=AcquirePixelChannelMap();
191 image->blob=CloneBlobInfo((BlobInfo *) NULL);
192 image->debug=IsEventLogging();
193 image->reference_count=1;
194 image->semaphore=AllocateSemaphoreInfo();
195 image->signature=MagickSignature;
196 if (image_info == (ImageInfo *) NULL)
201 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
203 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
204 (void) CopyMagickString(image->magick_filename,image_info->filename,
206 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
207 if (image_info->size != (char *) NULL)
209 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
210 image->columns=image->extract_info.width;
211 image->rows=image->extract_info.height;
212 image->offset=image->extract_info.x;
213 image->extract_info.x=0;
214 image->extract_info.y=0;
216 if (image_info->extract != (char *) NULL)
221 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
222 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
224 image->extract_info=geometry;
225 Swap(image->columns,image->extract_info.width);
226 Swap(image->rows,image->extract_info.height);
229 image->compression=image_info->compression;
230 image->quality=image_info->quality;
231 image->endian=image_info->endian;
232 image->interlace=image_info->interlace;
233 image->units=image_info->units;
234 if (image_info->density != (char *) NULL)
239 flags=ParseGeometry(image_info->density,&geometry_info);
240 image->x_resolution=geometry_info.rho;
241 image->y_resolution=geometry_info.sigma;
242 if ((flags & SigmaValue) == 0)
243 image->y_resolution=image->x_resolution;
245 if (image_info->page != (char *) NULL)
250 image->page=image->extract_info;
251 geometry=GetPageGeometry(image_info->page);
252 (void) ParseAbsoluteGeometry(geometry,&image->page);
253 geometry=DestroyString(geometry);
255 if (image_info->depth != 0)
256 image->depth=image_info->depth;
257 image->dither=image_info->dither;
258 image->background_color=image_info->background_color;
259 image->border_color=image_info->border_color;
260 image->matte_color=image_info->matte_color;
261 image->transparent_color=image_info->transparent_color;
262 image->ping=image_info->ping;
263 image->progress_monitor=image_info->progress_monitor;
264 image->client_data=image_info->client_data;
265 if (image_info->cache != (void *) NULL)
266 ClonePixelCacheMethods(image->cache,image_info->cache);
267 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
268 (void) SyncImageSettings(image_info,image);
269 option=GetImageOption(image_info,"delay");
270 if (option != (const char *) NULL)
275 flags=ParseGeometry(option,&geometry_info);
276 if ((flags & GreaterValue) != 0)
278 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
279 image->delay=(size_t) floor(geometry_info.rho+0.5);
282 if ((flags & LessValue) != 0)
284 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
285 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
288 image->delay=(size_t) floor(geometry_info.rho+0.5);
289 if ((flags & SigmaValue) != 0)
290 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
292 option=GetImageOption(image_info,"dispose");
293 if (option != (const char *) NULL)
294 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % A c q u i r e I m a g e I n f o %
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % AcquireImageInfo() allocates the ImageInfo structure.
312 % The format of the AcquireImageInfo method is:
314 % ImageInfo *AcquireImageInfo(void)
317 MagickExport ImageInfo *AcquireImageInfo(void)
322 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
323 if (image_info == (ImageInfo *) NULL)
324 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
325 GetImageInfo(image_info);
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 % A c q u i r e N e x t I m a g e %
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 % AcquireNextImage() initializes the next image in a sequence to
341 % default values. The next member of image points to the newly allocated
342 % image. If there is a memory shortage, next is assigned NULL.
344 % The format of the AcquireNextImage method is:
346 % void AcquireNextImage(const ImageInfo *image_info,Image *image)
348 % A description of each parameter follows:
350 % o image_info: Many of the image default values are set from this
351 % structure. For example, filename, compression, depth, background color,
354 % o image: the image.
357 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
360 Allocate image structure.
362 assert(image != (Image *) NULL);
363 assert(image->signature == MagickSignature);
364 if (image->debug != MagickFalse)
365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
366 image->next=AcquireImage(image_info);
367 if (GetNextImageInList(image) == (Image *) NULL)
369 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
371 if (image_info != (ImageInfo *) NULL)
372 (void) CopyMagickString(GetNextImageInList(image)->filename,
373 image_info->filename,MaxTextExtent);
374 DestroyBlob(GetNextImageInList(image));
375 image->next->blob=ReferenceBlob(image->blob);
376 image->next->endian=image->endian;
377 image->next->scene=image->scene+1;
378 image->next->previous=image;
382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 % A p p e n d I m a g e s %
390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 % AppendImages() takes all images from the current image pointer to the end
393 % of the image list and appends them to each other top-to-bottom if the
394 % stack parameter is true, otherwise left-to-right.
396 % The current gravity setting now effects how the image is justified in the
399 % The format of the AppendImages method is:
401 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
402 % ExceptionInfo *exception)
404 % A description of each parameter follows:
406 % o images: the image sequence.
408 % o stack: A value other than 0 stacks the images top-to-bottom.
410 % o exception: return any errors or warnings in this structure.
413 MagickExport Image *AppendImages(const Image *images,
414 const MagickBooleanType stack,ExceptionInfo *exception)
416 #define AppendImageTag "Append/Image"
453 Compute maximum area of appended area.
455 assert(images != (Image *) NULL);
456 assert(images->signature == MagickSignature);
457 if (images->debug != MagickFalse)
458 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
459 assert(exception != (ExceptionInfo *) NULL);
460 assert(exception->signature == MagickSignature);
464 width=image->columns;
466 next=GetNextImageInList(image);
467 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
469 if (next->matte != MagickFalse)
472 if (stack != MagickFalse)
474 if (next->columns > width)
479 width+=next->columns;
480 if (next->rows > height)
486 append_image=CloneImage(image,width,height,MagickTrue,exception);
487 if (append_image == (Image *) NULL)
488 return((Image *) NULL);
489 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
491 append_image=DestroyImage(append_image);
492 return((Image *) NULL);
494 append_image->matte=matte;
495 (void) SetImageBackgroundColor(append_image);
499 append_view=AcquireCacheView(append_image);
500 for (n=0; n < (MagickOffsetType) number_images; n++)
502 SetGeometry(append_image,&geometry);
503 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
504 if (stack != MagickFalse)
505 x_offset-=geometry.x;
507 y_offset-=geometry.y;
508 image_view=AcquireCacheView(image);
509 #if defined(MAGICKCORE_OPENMP_SUPPORT)
510 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
512 for (y=0; y < (ssize_t) image->rows; y++)
517 register const Quantum
526 if (status == MagickFalse)
528 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
529 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
530 image->columns,1,exception);
531 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
536 for (x=0; x < (ssize_t) image->columns; x++)
538 SetPixelRed(append_image,GetPixelRed(image,p),q);
539 SetPixelGreen(append_image,GetPixelGreen(image,p),q);
540 SetPixelBlue(append_image,GetPixelBlue(image,p),q);
541 if ((image->colorspace == CMYKColorspace) &&
542 (append_image->colorspace == CMYKColorspace))
543 SetPixelBlack(append_image,GetPixelBlack(image,p),q);
544 SetPixelAlpha(append_image,OpaqueAlpha,q);
545 if (image->matte != MagickFalse)
546 SetPixelAlpha(append_image,GetPixelAlpha(image,p),q);
547 p+=GetPixelChannels(image);
548 q+=GetPixelChannels(append_image);
550 sync=SyncCacheViewAuthenticPixels(append_view,exception);
551 if (sync == MagickFalse)
554 image_view=DestroyCacheView(image_view);
555 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
556 if (proceed == MagickFalse)
558 if (stack == MagickFalse)
560 x_offset+=(ssize_t) image->columns;
566 y_offset+=(ssize_t) image->rows;
568 image=GetNextImageInList(image);
570 append_view=DestroyCacheView(append_view);
571 if (status == MagickFalse)
572 append_image=DestroyImage(append_image);
573 return(append_image);
577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 % C a t c h I m a g e E x c e p t i o n %
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587 % CatchImageException() returns if no exceptions are found in the image
588 % sequence, otherwise it determines the most severe exception and reports
589 % it as a warning or error depending on the severity.
591 % The format of the CatchImageException method is:
593 % ExceptionType CatchImageException(Image *image)
595 % A description of each parameter follows:
597 % o image: An image sequence.
600 MagickExport ExceptionType CatchImageException(Image *image)
608 assert(image != (const Image *) NULL);
609 assert(image->signature == MagickSignature);
610 if (image->debug != MagickFalse)
611 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
612 exception=AcquireExceptionInfo();
613 GetImageException(image,exception);
614 CatchException(exception);
615 severity=exception->severity;
616 exception=DestroyExceptionInfo(exception);
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625 % C l i p I m a g e P a t h %
629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631 % ClipImagePath() sets the image clip mask based any clipping path information
634 % The format of the ClipImagePath method is:
636 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
637 % const MagickBooleanType inside)
639 % A description of each parameter follows:
641 % o image: the image.
643 % o pathname: name of clipping path resource. If name is preceded by #, use
644 % clipping path numbered by name.
646 % o inside: if non-zero, later operations take effect inside clipping path.
647 % Otherwise later operations take effect outside clipping path.
651 MagickExport MagickBooleanType ClipImage(Image *image)
653 return(ClipImagePath(image,"#1",MagickTrue));
656 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
657 const MagickBooleanType inside)
659 #define ClipImagePathTag "ClipPath/Image"
673 assert(image != (const Image *) NULL);
674 assert(image->signature == MagickSignature);
675 if (image->debug != MagickFalse)
676 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
677 assert(pathname != NULL);
678 property=AcquireString(pathname);
679 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
681 value=GetImageProperty(image,property);
682 property=DestroyString(property);
683 if (value == (const char *) NULL)
685 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
689 image_info=AcquireImageInfo();
690 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
691 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
692 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
693 image_info=DestroyImageInfo(image_info);
694 if (clip_mask == (Image *) NULL)
696 if (clip_mask->storage_class == PseudoClass)
698 (void) SyncImage(clip_mask);
699 if (SetImageStorageClass(clip_mask,DirectClass,&image->exception) == MagickFalse)
702 if (inside == MagickFalse)
703 (void) NegateImage(clip_mask,MagickFalse,&image->exception);
704 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
705 "8BIM:1999,2998:%s\nPS",pathname);
706 (void) SetImageClipMask(image,clip_mask);
707 clip_mask=DestroyImage(clip_mask);
712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
716 % C l o n e I m a g e %
720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
722 % CloneImage() copies an image and returns the copy as a new image object.
724 % If the specified columns and rows is 0, an exact copy of the image is
725 % returned, otherwise the pixel data is undefined and must be initialized
726 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
727 % failure, a NULL image is returned and exception describes the reason for the
730 % The format of the CloneImage method is:
732 % Image *CloneImage(const Image *image,const size_t columns,
733 % const size_t rows,const MagickBooleanType orphan,
734 % ExceptionInfo *exception)
736 % A description of each parameter follows:
738 % o image: the image.
740 % o columns: the number of columns in the cloned image.
742 % o rows: the number of rows in the cloned image.
744 % o detach: With a value other than 0, the cloned image is detached from
745 % its parent I/O stream.
747 % o exception: return any errors or warnings in this structure.
750 MagickExport Image *CloneImage(const Image *image,const size_t columns,
751 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
765 assert(image != (const Image *) NULL);
766 assert(image->signature == MagickSignature);
767 if (image->debug != MagickFalse)
768 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
769 assert(exception != (ExceptionInfo *) NULL);
770 assert(exception->signature == MagickSignature);
771 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
772 if (clone_image == (Image *) NULL)
773 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
774 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
775 clone_image->signature=MagickSignature;
776 clone_image->storage_class=image->storage_class;
777 clone_image->number_channels=image->number_channels;
778 clone_image->number_meta_channels=image->number_meta_channels;
779 clone_image->metacontent_extent=image->metacontent_extent;
780 clone_image->colorspace=image->colorspace;
781 clone_image->matte=image->matte;
782 clone_image->columns=image->columns;
783 clone_image->rows=image->rows;
784 clone_image->dither=image->dither;
785 if (image->colormap != (PixelPacket *) NULL)
788 Allocate and copy the image colormap.
790 clone_image->colors=image->colors;
791 length=(size_t) image->colors;
792 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
793 sizeof(*clone_image->colormap));
794 if (clone_image->colormap == (PixelPacket *) NULL)
795 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
796 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
797 sizeof(*clone_image->colormap));
799 (void) CloneImageProfiles(clone_image,image);
800 (void) CloneImageProperties(clone_image,image);
801 (void) CloneImageArtifacts(clone_image,image);
802 GetTimerInfo(&clone_image->timer);
803 GetExceptionInfo(&clone_image->exception);
804 InheritException(&clone_image->exception,&image->exception);
805 if (image->ascii85 != (void *) NULL)
806 Ascii85Initialize(clone_image);
807 clone_image->magick_columns=image->magick_columns;
808 clone_image->magick_rows=image->magick_rows;
809 clone_image->type=image->type;
810 clone_image->sync=image->sync;
811 clone_image->channel_mask=image->channel_mask;
812 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
813 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
815 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
816 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
817 clone_image->progress_monitor=image->progress_monitor;
818 clone_image->client_data=image->client_data;
819 clone_image->reference_count=1;
820 clone_image->next=image->next;
821 clone_image->previous=image->previous;
822 clone_image->list=NewImageList();
823 clone_image->clip_mask=NewImageList();
824 clone_image->mask=NewImageList();
825 if (detach == MagickFalse)
826 clone_image->blob=ReferenceBlob(image->blob);
829 clone_image->next=NewImageList();
830 clone_image->previous=NewImageList();
831 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
833 clone_image->ping=image->ping;
834 clone_image->debug=IsEventLogging();
835 clone_image->semaphore=AllocateSemaphoreInfo();
836 if ((columns == 0) && (rows == 0))
838 if (image->montage != (char *) NULL)
839 (void) CloneString(&clone_image->montage,image->montage);
840 if (image->directory != (char *) NULL)
841 (void) CloneString(&clone_image->directory,image->directory);
842 if (image->clip_mask != (Image *) NULL)
843 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
845 if (image->mask != (Image *) NULL)
846 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
847 clone_image->cache=ReferencePixelCache(image->cache);
850 if ((columns == image->columns) && (rows == image->rows))
852 if (image->clip_mask != (Image *) NULL)
853 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
855 if (image->mask != (Image *) NULL)
856 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
858 scale=(MagickRealType) columns/(MagickRealType) image->columns;
859 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
860 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
861 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
862 scale=(MagickRealType) rows/(MagickRealType) image->rows;
863 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
864 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
865 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
866 clone_image->columns=columns;
867 clone_image->rows=rows;
868 clone_image->cache=ClonePixelCache(image->cache);
873 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
877 % C l o n e I m a g e I n f o %
881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
883 % CloneImageInfo() makes a copy of the given image info structure. If
884 % NULL is specified, a new image info structure is created initialized to
887 % The format of the CloneImageInfo method is:
889 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
891 % A description of each parameter follows:
893 % o image_info: the image info.
896 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
901 clone_info=AcquireImageInfo();
902 if (image_info == (ImageInfo *) NULL)
904 clone_info->compression=image_info->compression;
905 clone_info->temporary=image_info->temporary;
906 clone_info->adjoin=image_info->adjoin;
907 clone_info->antialias=image_info->antialias;
908 clone_info->scene=image_info->scene;
909 clone_info->number_scenes=image_info->number_scenes;
910 clone_info->depth=image_info->depth;
911 if (image_info->size != (char *) NULL)
912 (void) CloneString(&clone_info->size,image_info->size);
913 if (image_info->extract != (char *) NULL)
914 (void) CloneString(&clone_info->extract,image_info->extract);
915 if (image_info->scenes != (char *) NULL)
916 (void) CloneString(&clone_info->scenes,image_info->scenes);
917 if (image_info->page != (char *) NULL)
918 (void) CloneString(&clone_info->page,image_info->page);
919 clone_info->interlace=image_info->interlace;
920 clone_info->endian=image_info->endian;
921 clone_info->units=image_info->units;
922 clone_info->quality=image_info->quality;
923 if (image_info->sampling_factor != (char *) NULL)
924 (void) CloneString(&clone_info->sampling_factor,
925 image_info->sampling_factor);
926 if (image_info->server_name != (char *) NULL)
927 (void) CloneString(&clone_info->server_name,image_info->server_name);
928 if (image_info->font != (char *) NULL)
929 (void) CloneString(&clone_info->font,image_info->font);
930 if (image_info->texture != (char *) NULL)
931 (void) CloneString(&clone_info->texture,image_info->texture);
932 if (image_info->density != (char *) NULL)
933 (void) CloneString(&clone_info->density,image_info->density);
934 clone_info->pointsize=image_info->pointsize;
935 clone_info->fuzz=image_info->fuzz;
936 clone_info->background_color=image_info->background_color;
937 clone_info->border_color=image_info->border_color;
938 clone_info->matte_color=image_info->matte_color;
939 clone_info->transparent_color=image_info->transparent_color;
940 clone_info->dither=image_info->dither;
941 clone_info->monochrome=image_info->monochrome;
942 clone_info->colors=image_info->colors;
943 clone_info->colorspace=image_info->colorspace;
944 clone_info->type=image_info->type;
945 clone_info->orientation=image_info->orientation;
946 clone_info->preview_type=image_info->preview_type;
947 clone_info->group=image_info->group;
948 clone_info->ping=image_info->ping;
949 clone_info->verbose=image_info->verbose;
950 if (image_info->view != (char *) NULL)
951 (void) CloneString(&clone_info->view,image_info->view);
952 if (image_info->authenticate != (char *) NULL)
953 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
954 (void) CloneImageOptions(clone_info,image_info);
955 clone_info->progress_monitor=image_info->progress_monitor;
956 clone_info->client_data=image_info->client_data;
957 clone_info->cache=image_info->cache;
958 if (image_info->cache != (void *) NULL)
959 clone_info->cache=ReferencePixelCache(image_info->cache);
960 if (image_info->profile != (void *) NULL)
961 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
962 image_info->profile);
963 SetImageInfoFile(clone_info,image_info->file);
964 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
965 clone_info->stream=image_info->stream;
966 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
967 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
968 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
969 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
970 (void) CopyMagickString(clone_info->filename,image_info->filename,
972 clone_info->channel=image_info->channel;
973 clone_info->debug=IsEventLogging();
974 clone_info->signature=image_info->signature;
979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
983 % C o m b i n e I m a g e s %
987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 % CombineImages() combines one or more images into a single image. The
990 % grayscale value of the pixels of each image in the sequence is assigned in
991 % order to the specified channels of the combined image. The typical
992 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
994 % The format of the CombineImages method is:
996 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
998 % A description of each parameter follows:
1000 % o image: the image.
1002 % o exception: return any errors or warnings in this structure.
1005 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1007 #define CombineImageTag "Combine/Image"
1028 Ensure the image are the same size.
1030 assert(image != (const Image *) NULL);
1031 assert(image->signature == MagickSignature);
1032 if (image->debug != MagickFalse)
1033 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1034 assert(exception != (ExceptionInfo *) NULL);
1035 assert(exception->signature == MagickSignature);
1036 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1038 if ((next->columns != image->columns) || (next->rows != image->rows))
1039 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1041 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1042 if (combine_image == (Image *) NULL)
1043 return((Image *) NULL);
1044 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1046 combine_image=DestroyImage(combine_image);
1047 return((Image *) NULL);
1049 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1050 combine_image->matte=MagickTrue;
1051 (void) SetImageBackgroundColor(combine_image);
1057 combine_view=AcquireCacheView(combine_image);
1058 for (y=0; y < (ssize_t) combine_image->rows; y++)
1069 register const Quantum
1078 if (status == MagickFalse)
1080 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1082 if (pixels == (Quantum *) NULL)
1088 if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) &&
1089 (next != (Image *) NULL))
1091 image_view=AcquireCacheView(next);
1092 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1093 if (p == (const Quantum *) NULL)
1096 for (x=0; x < (ssize_t) combine_image->columns; x++)
1098 SetPixelRed(image,GetPixelIntensity(image,p),q);
1099 p+=GetPixelChannels(image);
1100 q+=GetPixelChannels(combine_image);
1102 image_view=DestroyCacheView(image_view);
1103 next=GetNextImageInList(next);
1105 if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) &&
1106 (next != (Image *) NULL))
1108 image_view=AcquireCacheView(next);
1109 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1110 if (p == (const Quantum *) NULL)
1113 for (x=0; x < (ssize_t) combine_image->columns; x++)
1115 SetPixelGreen(image,GetPixelIntensity(image,p),q);
1116 p+=GetPixelChannels(image);
1117 q+=GetPixelChannels(combine_image);
1119 image_view=DestroyCacheView(image_view);
1120 next=GetNextImageInList(next);
1122 if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) &&
1123 (next != (Image *) NULL))
1125 image_view=AcquireCacheView(next);
1126 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1127 if (p == (const Quantum *) NULL)
1130 for (x=0; x < (ssize_t) combine_image->columns; x++)
1132 SetPixelBlue(image,GetPixelIntensity(image,p),q);
1133 p+=GetPixelChannels(image);
1134 q+=GetPixelChannels(combine_image);
1136 image_view=DestroyCacheView(image_view);
1137 next=GetNextImageInList(next);
1139 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
1140 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1142 image_view=AcquireCacheView(next);
1143 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1144 if (p == (const Quantum *) NULL)
1147 for (x=0; x < (ssize_t) combine_image->columns; x++)
1149 SetPixelBlack(image,GetPixelIntensity(image,p),q);
1150 p+=GetPixelChannels(image);
1151 q+=GetPixelChannels(combine_image);
1153 image_view=DestroyCacheView(image_view);
1154 next=GetNextImageInList(next);
1156 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
1157 (next != (Image *) NULL))
1159 image_view=AcquireCacheView(next);
1160 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1161 if (p == (const Quantum *) NULL)
1164 for (x=0; x < (ssize_t) combine_image->columns; x++)
1166 SetPixelAlpha(image,GetPixelIntensity(image,p),q);
1167 p+=GetPixelChannels(image);
1168 q+=GetPixelChannels(combine_image);
1170 image_view=DestroyCacheView(image_view);
1171 next=GetNextImageInList(next);
1173 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1175 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1180 proceed=SetImageProgress(image,CombineImageTag,progress++,
1181 combine_image->rows);
1182 if (proceed == MagickFalse)
1186 combine_view=DestroyCacheView(combine_view);
1187 if (status == MagickFalse)
1188 combine_image=DestroyImage(combine_image);
1189 return(combine_image);
1193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 % D e s t r o y I m a g e %
1201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1203 % DestroyImage() dereferences an image, deallocating memory associated with
1204 % the image if the reference count becomes zero.
1206 % The format of the DestroyImage method is:
1208 % Image *DestroyImage(Image *image)
1210 % A description of each parameter follows:
1212 % o image: the image.
1215 MagickExport Image *DestroyImage(Image *image)
1223 assert(image != (Image *) NULL);
1224 assert(image->signature == MagickSignature);
1225 if (image->debug != MagickFalse)
1226 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1227 destroy=MagickFalse;
1228 LockSemaphoreInfo(image->semaphore);
1229 image->reference_count--;
1230 if (image->reference_count == 0)
1232 UnlockSemaphoreInfo(image->semaphore);
1233 if (destroy == MagickFalse)
1234 return((Image *) NULL);
1238 DestroyImagePixels(image);
1239 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1240 if (image->clip_mask != (Image *) NULL)
1241 image->clip_mask=DestroyImage(image->clip_mask);
1242 if (image->mask != (Image *) NULL)
1243 image->mask=DestroyImage(image->mask);
1244 if (image->montage != (char *) NULL)
1245 image->montage=DestroyString(image->montage);
1246 if (image->directory != (char *) NULL)
1247 image->directory=DestroyString(image->directory);
1248 if (image->colormap != (PixelPacket *) NULL)
1249 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1250 if (image->geometry != (char *) NULL)
1251 image->geometry=DestroyString(image->geometry);
1252 DestroyImageProfiles(image);
1253 DestroyImageProperties(image);
1254 DestroyImageArtifacts(image);
1255 if (image->ascii85 != (Ascii85Info*) NULL)
1256 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1258 (void) DestroyExceptionInfo(&image->exception);
1259 if (image->semaphore != (SemaphoreInfo *) NULL)
1260 DestroySemaphoreInfo(&image->semaphore);
1261 image->signature=(~MagickSignature);
1262 image=(Image *) RelinquishMagickMemory(image);
1267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 % D e s t r o y I m a g e I n f o %
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1277 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1280 % The format of the DestroyImageInfo method is:
1282 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1284 % A description of each parameter follows:
1286 % o image_info: the image info.
1289 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1291 assert(image_info != (ImageInfo *) NULL);
1292 assert(image_info->signature == MagickSignature);
1293 if (image_info->debug != MagickFalse)
1294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1295 image_info->filename);
1296 if (image_info->size != (char *) NULL)
1297 image_info->size=DestroyString(image_info->size);
1298 if (image_info->extract != (char *) NULL)
1299 image_info->extract=DestroyString(image_info->extract);
1300 if (image_info->scenes != (char *) NULL)
1301 image_info->scenes=DestroyString(image_info->scenes);
1302 if (image_info->page != (char *) NULL)
1303 image_info->page=DestroyString(image_info->page);
1304 if (image_info->sampling_factor != (char *) NULL)
1305 image_info->sampling_factor=DestroyString(
1306 image_info->sampling_factor);
1307 if (image_info->server_name != (char *) NULL)
1308 image_info->server_name=DestroyString(
1309 image_info->server_name);
1310 if (image_info->font != (char *) NULL)
1311 image_info->font=DestroyString(image_info->font);
1312 if (image_info->texture != (char *) NULL)
1313 image_info->texture=DestroyString(image_info->texture);
1314 if (image_info->density != (char *) NULL)
1315 image_info->density=DestroyString(image_info->density);
1316 if (image_info->view != (char *) NULL)
1317 image_info->view=DestroyString(image_info->view);
1318 if (image_info->authenticate != (char *) NULL)
1319 image_info->authenticate=DestroyString(
1320 image_info->authenticate);
1321 DestroyImageOptions(image_info);
1322 if (image_info->cache != (void *) NULL)
1323 image_info->cache=DestroyPixelCache(image_info->cache);
1324 if (image_info->profile != (StringInfo *) NULL)
1325 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1326 image_info->profile);
1327 image_info->signature=(~MagickSignature);
1328 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337 + D i s a s s o c i a t e I m a g e S t r e a m %
1341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1343 % DisassociateImageStream() disassociates the image stream.
1345 % The format of the DisassociateImageStream method is:
1347 % MagickBooleanType DisassociateImageStream(const Image *image)
1349 % A description of each parameter follows:
1351 % o image: the image.
1354 MagickExport void DisassociateImageStream(Image *image)
1356 assert(image != (const Image *) NULL);
1357 assert(image->signature == MagickSignature);
1358 if (image->debug != MagickFalse)
1359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1360 (void) DetachBlob(image->blob);
1364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1368 % G e t I m a g e A l p h a C h a n n e l %
1372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1374 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1375 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1378 % The format of the GetImageAlphaChannel method is:
1380 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1382 % A description of each parameter follows:
1384 % o image: the image.
1387 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1389 assert(image != (const Image *) NULL);
1390 if (image->debug != MagickFalse)
1391 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1392 assert(image->signature == MagickSignature);
1393 return(image->matte);
1397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1401 % G e t I m a g e C l i p M a s k %
1405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1407 % GetImageClipMask() returns the clip path associated with the image.
1409 % The format of the GetImageClipMask method is:
1411 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1413 % A description of each parameter follows:
1415 % o image: the image.
1418 MagickExport Image *GetImageClipMask(const Image *image,
1419 ExceptionInfo *exception)
1421 assert(image != (const Image *) NULL);
1422 if (image->debug != MagickFalse)
1423 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1424 assert(image->signature == MagickSignature);
1425 if (image->clip_mask == (Image *) NULL)
1426 return((Image *) NULL);
1427 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1435 % G e t I m a g e E x c e p t i o n %
1439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1441 % GetImageException() traverses an image sequence and returns any
1442 % error more severe than noted by the exception parameter.
1444 % The format of the GetImageException method is:
1446 % void GetImageException(Image *image,ExceptionInfo *exception)
1448 % A description of each parameter follows:
1450 % o image: Specifies a pointer to a list of one or more images.
1452 % o exception: return the highest severity exception.
1455 MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1460 assert(image != (Image *) NULL);
1461 assert(image->signature == MagickSignature);
1462 if (image->debug != MagickFalse)
1463 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1464 assert(exception != (ExceptionInfo *) NULL);
1465 assert(exception->signature == MagickSignature);
1466 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1468 if (next->exception.severity == UndefinedException)
1470 if (next->exception.severity > exception->severity)
1471 InheritException(exception,&next->exception);
1472 next->exception.severity=UndefinedException;
1477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1481 % G e t I m a g e I n f o %
1485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1487 % GetImageInfo() initializes image_info to default values.
1489 % The format of the GetImageInfo method is:
1491 % void GetImageInfo(ImageInfo *image_info)
1493 % A description of each parameter follows:
1495 % o image_info: the image info.
1498 MagickExport void GetImageInfo(ImageInfo *image_info)
1507 File and image dimension members.
1509 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1510 assert(image_info != (ImageInfo *) NULL);
1511 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1512 image_info->adjoin=MagickTrue;
1513 image_info->interlace=NoInterlace;
1514 image_info->channel=DefaultChannels;
1515 image_info->quality=UndefinedCompressionQuality;
1516 image_info->antialias=MagickTrue;
1517 image_info->dither=MagickTrue;
1518 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1519 if (synchronize != (const char *) NULL)
1520 image_info->synchronize=IsMagickTrue(synchronize);
1521 exception=AcquireExceptionInfo();
1522 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1524 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1525 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1526 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1528 exception=DestroyExceptionInfo(exception);
1529 image_info->debug=IsEventLogging();
1530 image_info->signature=MagickSignature;
1534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1538 % G e t I m a g e I n f o F i l e %
1542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1544 % GetImageInfoFile() returns the image info file member.
1546 % The format of the GetImageInfoFile method is:
1548 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1550 % A description of each parameter follows:
1552 % o image_info: the image info.
1555 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1557 return(image_info->file);
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1565 % G e t I m a g e M a s k %
1569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1571 % GetImageMask() returns the mask associated with the image.
1573 % The format of the GetImageMask method is:
1575 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1577 % A description of each parameter follows:
1579 % o image: the image.
1582 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1584 assert(image != (const Image *) NULL);
1585 if (image->debug != MagickFalse)
1586 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1587 assert(image->signature == MagickSignature);
1588 if (image->mask == (Image *) NULL)
1589 return((Image *) NULL);
1590 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1598 + G e t I m a g e R e f e r e n c e C o u n t %
1602 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1604 % GetImageReferenceCount() returns the image reference count.
1606 % The format of the GetReferenceCount method is:
1608 % ssize_t GetImageReferenceCount(Image *image)
1610 % A description of each parameter follows:
1612 % o image: the image.
1615 MagickExport ssize_t GetImageReferenceCount(Image *image)
1620 assert(image != (Image *) NULL);
1621 assert(image->signature == MagickSignature);
1622 if (image->debug != MagickFalse)
1623 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1624 LockSemaphoreInfo(image->semaphore);
1625 reference_count=image->reference_count;
1626 UnlockSemaphoreInfo(image->semaphore);
1627 return(reference_count);
1631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1635 % 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 %
1639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1641 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1642 % image. A virtual pixel is any pixel access that is outside the boundaries
1643 % of the image cache.
1645 % The format of the GetImageVirtualPixelMethod() method is:
1647 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1649 % A description of each parameter follows:
1651 % o image: the image.
1654 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1656 assert(image != (Image *) NULL);
1657 assert(image->signature == MagickSignature);
1658 if (image->debug != MagickFalse)
1659 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1660 return(GetPixelCacheVirtualMethod(image));
1664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1668 % I n t e r p r e t I m a g e F i l e n a m e %
1672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1674 % InterpretImageFilename() interprets embedded characters in an image filename.
1675 % The filename length is returned.
1677 % The format of the InterpretImageFilename method is:
1679 % size_t InterpretImageFilename(const ImageInfo *image_info,
1680 % Image *image,const char *format,int value,char *filename)
1682 % A description of each parameter follows.
1684 % o image_info: the image info..
1686 % o image: the image.
1688 % o format: A filename describing the format to use to write the numeric
1689 % argument. Only the first numeric format identifier is replaced.
1691 % o value: Numeric value to substitute into format filename.
1693 % o filename: return the formatted filename in this character buffer.
1696 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1697 Image *image,const char *format,int value,char *filename)
1714 canonical=MagickFalse;
1716 (void) CopyMagickString(filename,format,MaxTextExtent);
1717 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1730 value=(ssize_t) strtol(q,&q,10);
1742 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1743 (p-format)),p,value);
1745 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1746 canonical=MagickTrue;
1755 pattern[MaxTextExtent];
1772 if (strchr(p,']') == (char *) NULL)
1776 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1787 if (LocaleNCompare(pattern,"filename:",9) != 0)
1789 value=(const char *) NULL;
1790 if ((image_info != (const ImageInfo *) NULL) &&
1791 (image != (const Image *) NULL))
1792 value=GetMagickProperty(image_info,image,pattern);
1794 if (image != (Image *) NULL)
1795 value=GetImageProperty(image,pattern);
1797 if (image_info != (ImageInfo *) NULL)
1798 value=GetImageOption(image_info,pattern);
1799 if (value == (const char *) NULL)
1804 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1805 (MaxTextExtent-(p-format-length)));
1806 length+=strlen(pattern)-1;
1808 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1809 canonical=MagickTrue;
1819 for (q=filename; *q != '\0'; q++)
1820 if ((*q == '%') && (*(q+1) == '%'))
1822 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1823 canonical=MagickTrue;
1825 if (canonical == MagickFalse)
1826 (void) CopyMagickString(filename,format,MaxTextExtent);
1827 return(strlen(filename));
1831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1835 % I s H i g h D y n a m i c R a n g e I m a g e %
1839 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1841 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1842 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1845 % The format of the IsHighDynamicRangeImage method is:
1847 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1848 % ExceptionInfo *exception)
1850 % A description of each parameter follows:
1852 % o image: the image.
1854 % o exception: return any errors or warnings in this structure.
1857 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1858 ExceptionInfo *exception)
1860 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1863 return(MagickFalse);
1877 assert(image != (Image *) NULL);
1878 assert(image->signature == MagickSignature);
1879 if (image->debug != MagickFalse)
1880 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1882 GetPixelInfo(image,&zero);
1883 image_view=AcquireCacheView(image);
1884 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1885 #pragma omp parallel for schedule(dynamic,4) shared(status)
1887 for (y=0; y < (ssize_t) image->rows; y++)
1892 register const Quantum
1898 if (status == MagickFalse)
1900 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1901 if (p == (const Quantum *) NULL)
1907 for (x=0; x < (ssize_t) image->columns; x++)
1909 SetPixelInfo(image,p,&pixel);
1910 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1911 (pixel.red != (QuantumAny) pixel.red))
1913 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1914 (pixel.green != (QuantumAny) pixel.green))
1916 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1917 (pixel.blue != (QuantumAny) pixel.blue))
1919 if (pixel.colorspace == CMYKColorspace)
1921 if ((pixel.black < 0.0) || (pixel.black > QuantumRange) ||
1922 (pixel.black != (QuantumAny) pixel.black))
1925 if (pixel.matte != MagickFalse)
1927 if ((pixel.alpha < 0.0) || (pixel.alpha > QuantumRange) ||
1928 (pixel.alpha != (QuantumAny) pixel.alpha))
1931 p+=GetPixelChannels(image);
1933 if (x < (ssize_t) image->columns)
1936 image_view=DestroyCacheView(image_view);
1937 return(status != MagickFalse ? MagickFalse : MagickTrue);
1942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1946 % I s I m a g e O b j e c t %
1950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1952 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1953 % set of image objects.
1955 % The format of the IsImageObject method is:
1957 % MagickBooleanType IsImageObject(const Image *image)
1959 % A description of each parameter follows:
1961 % o image: the image.
1964 MagickExport MagickBooleanType IsImageObject(const Image *image)
1966 register const Image
1969 assert(image != (Image *) NULL);
1970 if (image->debug != MagickFalse)
1971 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1972 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1973 if (p->signature != MagickSignature)
1974 return(MagickFalse);
1979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1983 % I s T a i n t I m a g e %
1987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1989 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1990 % since it was first constituted.
1992 % The format of the IsTaintImage method is:
1994 % MagickBooleanType IsTaintImage(const Image *image)
1996 % A description of each parameter follows:
1998 % o image: the image.
2001 MagickExport MagickBooleanType IsTaintImage(const Image *image)
2004 magick[MaxTextExtent],
2005 filename[MaxTextExtent];
2007 register const Image
2010 assert(image != (Image *) NULL);
2011 if (image->debug != MagickFalse)
2012 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2013 assert(image->signature == MagickSignature);
2014 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2015 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2016 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2018 if (p->taint != MagickFalse)
2020 if (LocaleCompare(p->magick,magick) != 0)
2022 if (LocaleCompare(p->filename,filename) != 0)
2025 return(MagickFalse);
2029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2033 % M o d i f y I m a g e %
2037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2039 % ModifyImage() ensures that there is only a single reference to the image
2040 % to be modified, updating the provided image pointer to point to a clone of
2041 % the original image if necessary.
2043 % The format of the ModifyImage method is:
2045 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2047 % A description of each parameter follows:
2049 % o image: the image.
2051 % o exception: return any errors or warnings in this structure.
2054 MagickExport MagickBooleanType ModifyImage(Image **image,
2055 ExceptionInfo *exception)
2060 assert(image != (Image **) NULL);
2061 assert(*image != (Image *) NULL);
2062 assert((*image)->signature == MagickSignature);
2063 if ((*image)->debug != MagickFalse)
2064 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2065 if (GetImageReferenceCount(*image) <= 1)
2067 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2068 LockSemaphoreInfo((*image)->semaphore);
2069 (*image)->reference_count--;
2070 UnlockSemaphoreInfo((*image)->semaphore);
2076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2080 % N e w M a g i c k I m a g e %
2084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2086 % NewMagickImage() creates a blank image canvas of the specified size and
2089 % The format of the NewMagickImage method is:
2091 % Image *NewMagickImage(const ImageInfo *image_info,
2092 % const size_t width,const size_t height,
2093 % const PixelInfo *background)
2095 % A description of each parameter follows:
2097 % o image: the image.
2099 % o width: the image width.
2101 % o height: the image height.
2103 % o background: the image color.
2106 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2107 const size_t width,const size_t height,
2108 const PixelInfo *background)
2125 assert(image_info != (const ImageInfo *) NULL);
2126 if (image_info->debug != MagickFalse)
2127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2128 assert(image_info->signature == MagickSignature);
2129 assert(background != (const PixelInfo *) NULL);
2130 image=AcquireImage(image_info);
2131 image->columns=width;
2133 image->colorspace=background->colorspace;
2134 image->matte=background->matte;
2135 image->fuzz=background->fuzz;
2136 image->depth=background->depth;
2138 exception=(&image->exception);
2139 image_view=AcquireCacheView(image);
2140 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2141 #pragma omp parallel for schedule(dynamic,4) shared(status)
2143 for (y=0; y < (ssize_t) image->rows; y++)
2151 if (status == MagickFalse)
2153 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2154 if (q == (Quantum *) NULL)
2159 for (x=0; x < (ssize_t) image->columns; x++)
2161 SetPixelPixelInfo(image,background,q);
2162 q+=GetPixelChannels(image);
2164 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2167 image_view=DestroyCacheView(image_view);
2168 if (status == MagickFalse)
2169 image=DestroyImage(image);
2174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2178 % R e f e r e n c e I m a g e %
2182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2184 % ReferenceImage() increments the reference count associated with an image
2185 % returning a pointer to the image.
2187 % The format of the ReferenceImage method is:
2189 % Image *ReferenceImage(Image *image)
2191 % A description of each parameter follows:
2193 % o image: the image.
2196 MagickExport Image *ReferenceImage(Image *image)
2198 assert(image != (Image *) NULL);
2199 if (image->debug != MagickFalse)
2200 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2201 assert(image->signature == MagickSignature);
2202 LockSemaphoreInfo(image->semaphore);
2203 image->reference_count++;
2204 UnlockSemaphoreInfo(image->semaphore);
2209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2213 % R e s e t I m a g e P a g e %
2217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2219 % ResetImagePage() resets the image page canvas and position.
2221 % The format of the ResetImagePage method is:
2223 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2225 % A description of each parameter follows:
2227 % o image: the image.
2229 % o page: the relative page specification.
2232 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2240 assert(image != (Image *) NULL);
2241 assert(image->signature == MagickSignature);
2242 if (image->debug != MagickFalse)
2243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2244 flags=ParseAbsoluteGeometry(page,&geometry);
2245 if ((flags & WidthValue) != 0)
2247 if ((flags & HeightValue) == 0)
2248 geometry.height=geometry.width;
2249 image->page.width=geometry.width;
2250 image->page.height=geometry.height;
2252 if ((flags & AspectValue) != 0)
2254 if ((flags & XValue) != 0)
2255 image->page.x+=geometry.x;
2256 if ((flags & YValue) != 0)
2257 image->page.y+=geometry.y;
2261 if ((flags & XValue) != 0)
2263 image->page.x=geometry.x;
2264 if ((image->page.width == 0) && (geometry.x > 0))
2265 image->page.width=image->columns+geometry.x;
2267 if ((flags & YValue) != 0)
2269 image->page.y=geometry.y;
2270 if ((image->page.height == 0) && (geometry.y > 0))
2271 image->page.height=image->rows+geometry.y;
2278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2282 % S e p a r a t e I m a g e C h a n n e l %
2286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2288 % SeparateImage() separates a channel from the image and returns it as
2289 % a grayscale image. A channel is a particular color component of each pixel
2292 % The format of the SeparateImage method is:
2294 % MagickBooleanType SeparateImage(Image *image)
2296 % A description of each parameter follows:
2298 % o image: the image.
2301 MagickExport MagickBooleanType SeparateImage(Image *image)
2303 #define SeparateImageTag "Separate/Image"
2320 assert(image != (Image *) NULL);
2321 assert(image->signature == MagickSignature);
2322 if (image->debug != MagickFalse)
2323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2324 exception=(&image->exception);
2325 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2326 return(MagickFalse);
2328 Separate image channels.
2332 image_view=AcquireCacheView(image);
2333 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2334 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2336 for (y=0; y < (ssize_t) image->rows; y++)
2344 if (status == MagickFalse)
2346 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2347 if (q == (Quantum *) NULL)
2352 for (x=0; x < (ssize_t) image->columns; x++)
2354 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2356 SetPixelGreen(image,GetPixelRed(image,q),q);
2357 SetPixelBlue(image,GetPixelRed(image,q),q);
2359 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2361 SetPixelRed(image,GetPixelGreen(image,q),q);
2362 SetPixelBlue(image,GetPixelGreen(image,q),q);
2364 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2366 SetPixelRed(image,GetPixelBlue(image,q),q);
2367 SetPixelGreen(image,GetPixelBlue(image,q),q);
2369 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2370 (image->colorspace == CMYKColorspace))
2372 SetPixelRed(image,GetPixelBlack(image,q),q);
2373 SetPixelGreen(image,GetPixelBlack(image,q),q);
2374 SetPixelBlue(image,GetPixelBlack(image,q),q);
2376 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2377 (image->matte != MagickFalse))
2379 SetPixelRed(image,GetPixelAlpha(image,q),q);
2380 SetPixelGreen(image,GetPixelAlpha(image,q),q);
2381 SetPixelBlue(image,GetPixelAlpha(image,q),q);
2383 q+=GetPixelChannels(image);
2385 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2387 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2392 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2393 #pragma omp critical (MagickCore_SeparateImage)
2395 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2396 if (proceed == MagickFalse)
2400 image_view=DestroyCacheView(image_view);
2401 (void) SetImageColorspace(image,RGBColorspace,exception);
2406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2410 % S e p a r a t e I m a g e s %
2414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2416 % SeparateImages() returns a separate grayscale image for each channel
2419 % The format of the SeparateImages method is:
2421 % MagickBooleanType SeparateImages(const Image *image,
2422 % ExceptionInfo *exception)
2424 % A description of each parameter follows:
2426 % o image: the image.
2428 % o exception: return any errors or warnings in this structure.
2431 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2440 assert(image != (Image *) NULL);
2441 assert(image->signature == MagickSignature);
2442 if (image->debug != MagickFalse)
2443 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2444 images=NewImageList();
2445 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2447 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2448 channel_mask=SetPixelChannelMask(separate_image,RedChannel);
2449 (void) SeparateImage(separate_image);
2450 (void) SetPixelChannelMap(separate_image,channel_mask);
2451 AppendImageToList(&images,separate_image);
2453 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2455 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2456 channel_mask=SetPixelChannelMask(separate_image,GreenChannel);
2457 (void) SeparateImage(separate_image);
2458 (void) SetPixelChannelMap(separate_image,channel_mask);
2459 AppendImageToList(&images,separate_image);
2461 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2463 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2464 channel_mask=SetPixelChannelMask(separate_image,BlueChannel);
2465 (void) SeparateImage(separate_image);
2466 (void) SetPixelChannelMap(separate_image,channel_mask);
2467 AppendImageToList(&images,separate_image);
2469 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2470 (image->colorspace == CMYKColorspace))
2472 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2473 channel_mask=SetPixelChannelMask(separate_image,BlackChannel);
2474 (void) SeparateImage(separate_image);
2475 (void) SetPixelChannelMap(separate_image,channel_mask);
2476 AppendImageToList(&images,separate_image);
2478 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2480 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2481 channel_mask=SetPixelChannelMask(separate_image,AlphaChannel);
2482 (void) SeparateImage(separate_image);
2483 (void) SetPixelChannelMap(separate_image,channel_mask);
2484 AppendImageToList(&images,separate_image);
2490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2494 % S e t I m a g e A l p h a C h a n n e l %
2498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2500 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2503 % The format of the SetImageAlphaChannel method is:
2505 % MagickBooleanType SetImageAlphaChannel(Image *image,
2506 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2508 % A description of each parameter follows:
2510 % o image: the image.
2512 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2513 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2514 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2515 % TransparentAlphaChannel.
2517 % o exception: return any errors or warnings in this structure.
2520 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2521 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2529 assert(image != (Image *) NULL);
2530 if (image->debug != MagickFalse)
2531 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2532 assert(image->signature == MagickSignature);
2536 case ActivateAlphaChannel:
2538 image->matte=MagickTrue;
2541 case BackgroundAlphaChannel:
2556 Set transparent pixels to background color.
2558 if (image->matte == MagickFalse)
2560 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2562 GetPixelInfo(image,&background);
2563 SetPixelInfoPacket(image,&image->background_color,&background);
2564 if (image->colorspace == CMYKColorspace)
2565 ConvertRGBToCMYK(&background);
2566 SetPacketPixelInfo(image,&background,&pixel);
2567 image_view=AcquireCacheView(image);
2568 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2569 #pragma omp parallel for schedule(dynamic,4) shared(status)
2571 for (y=0; y < (ssize_t) image->rows; y++)
2579 if (status == MagickFalse)
2581 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2583 if (q == (Quantum *) NULL)
2588 for (x=0; x < (ssize_t) image->columns; x++)
2590 if (GetPixelAlpha(image,q) == TransparentAlpha)
2592 SetPixelRed(image,pixel.red,q);
2593 SetPixelGreen(image,pixel.green,q);
2594 SetPixelBlue(image,pixel.blue,q);
2595 if (image->colorspace == CMYKColorspace)
2596 SetPixelBlack(image,pixel.black,q);
2598 q+=GetPixelChannels(image);
2600 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2603 image_view=DestroyCacheView(image_view);
2606 case DeactivateAlphaChannel:
2608 image->matte=MagickFalse;
2611 case ShapeAlphaChannel:
2612 case CopyAlphaChannel:
2615 Special usage case for SeparateImage(): copy grayscale color to
2618 channel_mask=SetPixelChannelMask(image,GrayChannel);
2619 status=SeparateImage(image);
2620 (void) SetPixelChannelMask(image,channel_mask);
2621 image->matte=MagickTrue; /* make sure transparency is now on! */
2622 if (alpha_type == ShapeAlphaChannel)
2628 Reset all color channels to background color.
2630 GetPixelInfo(image,&background);
2631 SetPixelInfoPacket(image,&(image->background_color),&background);
2632 (void) LevelImageColors(image,&background,&background,MagickTrue,
2637 case ExtractAlphaChannel:
2639 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2640 status=SeparateImage(image);
2641 (void) SetPixelChannelMask(image,channel_mask);
2642 image->matte=MagickFalse;
2645 case OpaqueAlphaChannel:
2647 status=SetImageOpacity(image,OpaqueAlpha);
2648 image->matte=MagickTrue;
2651 case TransparentAlphaChannel:
2653 status=SetImageOpacity(image,TransparentAlpha);
2654 image->matte=MagickTrue;
2657 case SetAlphaChannel:
2659 if (image->matte == MagickFalse)
2661 status=SetImageOpacity(image,OpaqueAlpha);
2662 image->matte=MagickTrue;
2666 case UndefinedAlphaChannel:
2669 if (status == MagickFalse)
2671 return(SyncImagePixelCache(image,exception));
2675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2679 % S e t I m a g e B a c k g r o u n d C o l o r %
2683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2685 % SetImageBackgroundColor() initializes the image pixels to the image
2686 % background color. The background color is defined by the background_color
2687 % member of the image structure.
2689 % The format of the SetImage method is:
2691 % MagickBooleanType SetImageBackgroundColor(Image *image)
2693 % A description of each parameter follows:
2695 % o image: the image.
2698 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2718 assert(image != (Image *) NULL);
2719 if (image->debug != MagickFalse)
2720 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2721 assert(image->signature == MagickSignature);
2722 exception=(&image->exception);
2723 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2724 return(MagickFalse);
2725 if (image->background_color.alpha != OpaqueAlpha)
2726 image->matte=MagickTrue;
2727 GetPixelInfo(image,&background);
2728 SetPixelInfoPacket(image,&image->background_color,&background);
2729 if (image->colorspace == CMYKColorspace)
2730 ConvertRGBToCMYK(&background);
2731 SetPacketPixelInfo(image,&background,&pixel);
2733 Set image background color.
2737 image_view=AcquireCacheView(image);
2738 for (y=0; y < (ssize_t) image->rows; y++)
2746 if (status == MagickFalse)
2748 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2749 if (q == (Quantum *) NULL)
2754 for (x=0; x < (ssize_t) image->columns; x++)
2756 SetPixelPacket(image,&pixel,q);
2757 if (image->colorspace == CMYKColorspace)
2758 SetPixelBlack(image,pixel.black,q);
2759 q+=GetPixelChannels(image);
2761 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2764 image_view=DestroyCacheView(image_view);
2769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2773 % S e t I m a g e C o l o r %
2777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2779 % SetImageColor() set the entire image canvas to the specified color.
2781 % The format of the SetImageColor method is:
2783 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color)
2785 % A description of each parameter follows:
2787 % o image: the image.
2789 % o background: the image color.
2792 MagickExport MagickBooleanType SetImageColor(Image *image,
2793 const PixelInfo *color)
2807 assert(image != (Image *) NULL);
2808 if (image->debug != MagickFalse)
2809 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2810 assert(image->signature == MagickSignature);
2811 assert(color != (const PixelInfo *) NULL);
2812 image->colorspace=color->colorspace;
2813 image->matte=color->matte;
2814 image->fuzz=color->fuzz;
2815 image->depth=color->depth;
2817 exception=(&image->exception);
2818 image_view=AcquireCacheView(image);
2819 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2820 #pragma omp parallel for schedule(dynamic,4) shared(status)
2822 for (y=0; y < (ssize_t) image->rows; y++)
2830 if (status == MagickFalse)
2832 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2833 if (q == (Quantum *) NULL)
2838 for (x=0; x < (ssize_t) image->columns; x++)
2840 SetPixelPixelInfo(image,color,q);
2841 q+=GetPixelChannels(image);
2843 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2846 image_view=DestroyCacheView(image_view);
2851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2855 % S e t I m a g e S t o r a g e C l a s s %
2859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2861 % SetImageStorageClass() sets the image class: DirectClass for true color
2862 % images or PseudoClass for colormapped images.
2864 % The format of the SetImageStorageClass method is:
2866 % MagickBooleanType SetImageStorageClass(Image *image,
2867 % const ClassType storage_class,ExceptionInfo *exception)
2869 % A description of each parameter follows:
2871 % o image: the image.
2873 % o storage_class: The image class.
2875 % o exception: return any errors or warnings in this structure.
2878 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2879 const ClassType storage_class,ExceptionInfo *exception)
2881 image->storage_class=storage_class;
2882 return(SyncImagePixelCache(image,exception));
2886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2890 % S e t I m a g e C l i p M a s k %
2894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2896 % SetImageClipMask() associates a clip path with the image. The clip path
2897 % must be the same dimensions as the image. Set any pixel component of
2898 % the clip path to TransparentAlpha to prevent that corresponding image
2899 % pixel component from being updated when SyncAuthenticPixels() is applied.
2901 % The format of the SetImageClipMask method is:
2903 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2905 % A description of each parameter follows:
2907 % o image: the image.
2909 % o clip_mask: the image clip path.
2912 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2913 const Image *clip_mask)
2915 assert(image != (Image *) NULL);
2916 if (image->debug != MagickFalse)
2917 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2918 assert(image->signature == MagickSignature);
2919 if (clip_mask != (const Image *) NULL)
2920 if ((clip_mask->columns != image->columns) ||
2921 (clip_mask->rows != image->rows))
2922 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2923 if (image->clip_mask != (Image *) NULL)
2924 image->clip_mask=DestroyImage(image->clip_mask);
2925 image->clip_mask=NewImageList();
2926 if (clip_mask == (Image *) NULL)
2928 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
2929 return(MagickFalse);
2930 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2931 if (image->clip_mask == (Image *) NULL)
2932 return(MagickFalse);
2937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2941 % S e t I m a g e E x t e n t %
2945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2947 % SetImageExtent() sets the image size (i.e. columns & rows).
2949 % The format of the SetImageExtent method is:
2951 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2952 % const size_t rows,ExceptionInfo *exception)
2954 % A description of each parameter follows:
2956 % o image: the image.
2958 % o columns: The image width in pixels.
2960 % o rows: The image height in pixels.
2962 % o exception: return any errors or warnings in this structure.
2965 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2966 const size_t rows,ExceptionInfo *exception)
2968 if ((columns == 0) || (rows == 0))
2969 return(MagickFalse);
2970 image->columns=columns;
2972 return(SyncImagePixelCache(image,exception));
2976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2980 + S e t I m a g e I n f o %
2984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2986 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2987 % It is set to a type of image format based on the prefix or suffix of the
2988 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2989 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2990 % precendence over the suffix. Use an optional index enclosed in brackets
2991 % after a file name to specify a desired scene of a multi-resolution image
2992 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2993 % indicates success.
2995 % The format of the SetImageInfo method is:
2997 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2998 % const unsigned int frames,ExceptionInfo *exception)
3000 % A description of each parameter follows:
3002 % o image_info: the image info.
3004 % o frames: the number of images you intend to write.
3006 % o exception: return any errors or warnings in this structure.
3009 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
3010 const unsigned int frames,ExceptionInfo *exception)
3013 extension[MaxTextExtent],
3014 filename[MaxTextExtent],
3015 magic[MaxTextExtent],
3017 subimage[MaxTextExtent];
3041 magick[2*MaxTextExtent];
3044 Look for 'image.format' in filename.
3046 assert(image_info != (ImageInfo *) NULL);
3047 assert(image_info->signature == MagickSignature);
3048 if (image_info->debug != MagickFalse)
3049 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3050 image_info->filename);
3054 GetPathComponent(image_info->filename,SubimagePath,subimage);
3055 if (*subimage != '\0')
3058 Look for scene specification (e.g. img0001.pcd[4]).
3060 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3062 if (IsGeometry(subimage) != MagickFalse)
3063 (void) CloneString(&image_info->extract,subimage);
3071 (void) CloneString(&image_info->scenes,subimage);
3072 image_info->scene=StringToUnsignedLong(image_info->scenes);
3073 image_info->number_scenes=image_info->scene;
3074 p=image_info->scenes;
3075 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3077 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3080 first=(size_t) strtol(p,&q,10);
3082 while (isspace((int) ((unsigned char) *q)) != 0)
3085 last=(size_t) strtol(q+1,&q,10);
3088 if (first < image_info->scene)
3089 image_info->scene=first;
3090 if (last > image_info->number_scenes)
3091 image_info->number_scenes=last;
3094 image_info->number_scenes-=image_info->scene-1;
3099 GetPathComponent(image_info->filename,ExtensionPath,extension);
3100 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3101 if (*extension != '\0')
3102 if ((LocaleCompare(extension,"gz") == 0) ||
3103 (LocaleCompare(extension,"Z") == 0) ||
3104 (LocaleCompare(extension,"wmz") == 0))
3107 path[MaxTextExtent];
3109 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3110 path[strlen(path)-strlen(extension)-1]='\0';
3111 GetPathComponent(path,ExtensionPath,extension);
3114 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3115 if (*extension != '\0')
3116 if (LocaleCompare(extension,"bz2") == 0)
3119 path[MaxTextExtent];
3121 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3122 path[strlen(path)-strlen(extension)-1]='\0';
3123 GetPathComponent(path,ExtensionPath,extension);
3126 image_info->affirm=MagickFalse;
3127 sans_exception=AcquireExceptionInfo();
3128 if (*extension != '\0')
3137 *format_type_formats[] =
3160 User specified image format.
3162 (void) CopyMagickString(magic,extension,MaxTextExtent);
3165 Look for explicit image formats.
3167 format_type=UndefinedFormatType;
3169 while ((format_type == UndefinedFormatType) &&
3170 (format_type_formats[i] != (char *) NULL))
3172 if ((*magic == *format_type_formats[i]) &&
3173 (LocaleCompare(magic,format_type_formats[i]) == 0))
3174 format_type=ExplicitFormatType;
3177 magick_info=GetMagickInfo(magic,sans_exception);
3178 if ((magick_info != (const MagickInfo *) NULL) &&
3179 (magick_info->format_type != UndefinedFormatType))
3180 format_type=magick_info->format_type;
3181 if (format_type == UndefinedFormatType)
3182 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3184 if (format_type == ExplicitFormatType)
3186 image_info->affirm=MagickTrue;
3187 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3189 if (LocaleCompare(magic,"RGB") == 0)
3190 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3193 Look for explicit 'format:image' in filename.
3196 GetPathComponent(image_info->filename,MagickPath,magic);
3198 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3202 User specified image format.
3205 if (IsMagickConflict(magic) == MagickFalse)
3207 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3208 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3209 image_info->affirm=MagickTrue;
3211 image_info->temporary=MagickTrue;
3214 magick_info=GetMagickInfo(magic,sans_exception);
3215 sans_exception=DestroyExceptionInfo(sans_exception);
3216 if ((magick_info == (const MagickInfo *) NULL) ||
3217 (GetMagickEndianSupport(magick_info) == MagickFalse))
3218 image_info->endian=UndefinedEndian;
3219 GetPathComponent(image_info->filename,CanonicalPath,filename);
3220 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3221 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3224 Test for multiple image support (e.g. image%02d.png).
3226 (void) InterpretImageFilename(image_info,(Image *) NULL,
3227 image_info->filename,(int) image_info->scene,filename);
3228 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3229 (strchr(filename,'%') == (char *) NULL))
3230 image_info->adjoin=MagickFalse;
3232 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3235 Some image formats do not support multiple frames per file.
3237 magick_info=GetMagickInfo(magic,exception);
3238 if (magick_info != (const MagickInfo *) NULL)
3239 if (GetMagickAdjoin(magick_info) == MagickFalse)
3240 image_info->adjoin=MagickFalse;
3242 if (image_info->affirm != MagickFalse)
3247 Determine the image format from the first few bytes of the file.
3249 image=AcquireImage(image_info);
3250 (void) CopyMagickString(image->filename,image_info->filename,
3252 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3253 if (status == MagickFalse)
3255 image=DestroyImage(image);
3256 return(MagickFalse);
3258 if ((IsBlobSeekable(image) == MagickFalse) ||
3259 (IsBlobExempt(image) != MagickFalse))
3262 Copy standard input or pipe to temporary file.
3265 status=ImageToFile(image,filename,exception);
3266 (void) CloseBlob(image);
3267 if (status == MagickFalse)
3269 image=DestroyImage(image);
3270 return(MagickFalse);
3272 SetImageInfoFile(image_info,(FILE *) NULL);
3273 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3274 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3275 if (status == MagickFalse)
3277 image=DestroyImage(image);
3278 return(MagickFalse);
3280 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3281 image_info->temporary=MagickTrue;
3283 (void) ResetMagickMemory(magick,0,sizeof(magick));
3284 count=ReadBlob(image,2*MaxTextExtent,magick);
3285 (void) CloseBlob(image);
3286 image=DestroyImage(image);
3288 Check magic.xml configuration file.
3290 sans_exception=AcquireExceptionInfo();
3291 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3292 if ((magic_info != (const MagicInfo *) NULL) &&
3293 (GetMagicName(magic_info) != (char *) NULL))
3295 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3297 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3298 if ((magick_info == (const MagickInfo *) NULL) ||
3299 (GetMagickEndianSupport(magick_info) == MagickFalse))
3300 image_info->endian=UndefinedEndian;
3301 sans_exception=DestroyExceptionInfo(sans_exception);
3304 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3305 if ((magick_info == (const MagickInfo *) NULL) ||
3306 (GetMagickEndianSupport(magick_info) == MagickFalse))
3307 image_info->endian=UndefinedEndian;
3308 sans_exception=DestroyExceptionInfo(sans_exception);
3314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3318 % S e t I m a g e I n f o B l o b %
3322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3324 % SetImageInfoBlob() sets the image info blob member.
3326 % The format of the SetImageInfoBlob method is:
3328 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3329 % const size_t length)
3331 % A description of each parameter follows:
3333 % o image_info: the image info.
3337 % o length: the blob length.
3340 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3341 const size_t length)
3343 assert(image_info != (ImageInfo *) NULL);
3344 assert(image_info->signature == MagickSignature);
3345 if (image_info->debug != MagickFalse)
3346 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3347 image_info->filename);
3348 image_info->blob=(void *) blob;
3349 image_info->length=length;
3353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3357 % S e t I m a g e I n f o F i l e %
3361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3363 % SetImageInfoFile() sets the image info file member.
3365 % The format of the SetImageInfoFile method is:
3367 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3369 % A description of each parameter follows:
3371 % o image_info: the image info.
3376 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3378 assert(image_info != (ImageInfo *) NULL);
3379 assert(image_info->signature == MagickSignature);
3380 if (image_info->debug != MagickFalse)
3381 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3382 image_info->filename);
3383 image_info->file=file;
3387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3391 % S e t I m a g e M a s k %
3395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3397 % SetImageMask() associates a mask with the image. The mask must be the same
3398 % dimensions as the image.
3400 % The format of the SetImageMask method is:
3402 % MagickBooleanType SetImageMask(Image *image,const Image *mask)
3404 % A description of each parameter follows:
3406 % o image: the image.
3408 % o mask: the image mask.
3411 MagickExport MagickBooleanType SetImageMask(Image *image,
3414 assert(image != (Image *) NULL);
3415 if (image->debug != MagickFalse)
3416 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3417 assert(image->signature == MagickSignature);
3418 if (mask != (const Image *) NULL)
3419 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3420 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3421 if (image->mask != (Image *) NULL)
3422 image->mask=DestroyImage(image->mask);
3423 image->mask=NewImageList();
3424 if (mask == (Image *) NULL)
3426 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
3427 return(MagickFalse);
3428 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3429 if (image->mask == (Image *) NULL)
3430 return(MagickFalse);
3435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3439 % S e t I m a g e O p a c i t y %
3443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3445 % SetImageOpacity() sets the opacity levels of the image.
3447 % The format of the SetImageOpacity method is:
3449 % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3451 % A description of each parameter follows:
3453 % o image: the image.
3455 % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3456 % fully transparent.
3459 MagickExport MagickBooleanType SetImageOpacity(Image *image,
3460 const Quantum opacity)
3474 assert(image != (Image *) NULL);
3475 if (image->debug != MagickFalse)
3476 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3477 assert(image->signature == MagickSignature);
3478 image->matte=opacity != OpaqueAlpha ? MagickTrue : MagickFalse;
3480 exception=(&image->exception);
3481 image_view=AcquireCacheView(image);
3482 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3483 #pragma omp parallel for schedule(dynamic,4) shared(status)
3485 for (y=0; y < (ssize_t) image->rows; y++)
3493 if (status == MagickFalse)
3495 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3496 if (q == (Quantum *) NULL)
3501 for (x=0; x < (ssize_t) image->columns; x++)
3503 SetPixelAlpha(image,opacity,q);
3504 q+=GetPixelChannels(image);
3506 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3509 image_view=DestroyCacheView(image_view);
3514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3518 % S e t I m a g e T y p e %
3522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3524 % SetImageType() sets the type of image. Choose from these types:
3526 % Bilevel Grayscale GrayscaleMatte
3527 % Palette PaletteMatte TrueColor
3528 % TrueColorMatte ColorSeparation ColorSeparationMatte
3531 % The format of the SetImageType method is:
3533 % MagickBooleanType SetImageType(Image *image,const ImageType type)
3535 % A description of each parameter follows:
3537 % o image: the image.
3539 % o type: Image type.
3542 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3559 assert(image != (Image *) NULL);
3560 if (image->debug != MagickFalse)
3561 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3562 assert(image->signature == MagickSignature);
3564 image_info=AcquireImageInfo();
3565 image_info->dither=image->dither;
3566 artifact=GetImageArtifact(image,"dither");
3567 if (artifact != (const char *) NULL)
3568 (void) SetImageOption(image_info,"dither",artifact);
3569 exception=(&image->exception);
3574 if (IsImageGray(image,&image->exception) == MagickFalse)
3575 status=TransformImageColorspace(image,GRAYColorspace);
3576 if (IsImageMonochrome(image,&image->exception) == MagickFalse)
3578 quantize_info=AcquireQuantizeInfo(image_info);
3579 quantize_info->number_colors=2;
3580 quantize_info->colorspace=GRAYColorspace;
3581 status=QuantizeImage(quantize_info,image);
3582 quantize_info=DestroyQuantizeInfo(quantize_info);
3584 image->matte=MagickFalse;
3589 if (IsImageGray(image,&image->exception) == MagickFalse)
3590 status=TransformImageColorspace(image,GRAYColorspace);
3591 image->matte=MagickFalse;
3594 case GrayscaleMatteType:
3596 if (IsImageGray(image,&image->exception) == MagickFalse)
3597 status=TransformImageColorspace(image,GRAYColorspace);
3598 if (image->matte == MagickFalse)
3599 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3604 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3605 status=TransformImageColorspace(image,RGBColorspace);
3606 if ((image->storage_class == DirectClass) || (image->colors > 256))
3608 quantize_info=AcquireQuantizeInfo(image_info);
3609 quantize_info->number_colors=256;
3610 status=QuantizeImage(quantize_info,image);
3611 quantize_info=DestroyQuantizeInfo(quantize_info);
3613 image->matte=MagickFalse;
3616 case PaletteBilevelMatteType:
3621 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3622 status=TransformImageColorspace(image,RGBColorspace);
3623 if (image->matte == MagickFalse)
3624 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3625 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3626 (void) BilevelImage(image,(double) QuantumRange/2.0);
3627 (void) SetPixelChannelMask(image,channel_mask);
3628 quantize_info=AcquireQuantizeInfo(image_info);
3629 status=QuantizeImage(quantize_info,image);
3630 quantize_info=DestroyQuantizeInfo(quantize_info);
3633 case PaletteMatteType:
3635 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3636 status=TransformImageColorspace(image,RGBColorspace);
3637 if (image->matte == MagickFalse)
3638 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3639 quantize_info=AcquireQuantizeInfo(image_info);
3640 quantize_info->colorspace=TransparentColorspace;
3641 status=QuantizeImage(quantize_info,image);
3642 quantize_info=DestroyQuantizeInfo(quantize_info);
3647 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3648 status=TransformImageColorspace(image,RGBColorspace);
3649 if (image->storage_class != DirectClass)
3650 status=SetImageStorageClass(image,DirectClass,&image->exception);
3651 image->matte=MagickFalse;
3654 case TrueColorMatteType:
3656 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3657 status=TransformImageColorspace(image,RGBColorspace);
3658 if (image->storage_class != DirectClass)
3659 status=SetImageStorageClass(image,DirectClass,&image->exception);
3660 if (image->matte == MagickFalse)
3661 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3664 case ColorSeparationType:
3666 if (image->colorspace != CMYKColorspace)
3668 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3669 status=TransformImageColorspace(image,RGBColorspace);
3670 status=TransformImageColorspace(image,CMYKColorspace);
3672 if (image->storage_class != DirectClass)
3673 status=SetImageStorageClass(image,DirectClass,&image->exception);
3674 image->matte=MagickFalse;
3677 case ColorSeparationMatteType:
3679 if (image->colorspace != CMYKColorspace)
3681 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3682 status=TransformImageColorspace(image,RGBColorspace);
3683 status=TransformImageColorspace(image,CMYKColorspace);
3685 if (image->storage_class != DirectClass)
3686 status=SetImageStorageClass(image,DirectClass,&image->exception);
3687 if (image->matte == MagickFalse)
3688 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3696 image_info=DestroyImageInfo(image_info);
3701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3705 % 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 %
3709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3711 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3712 % image and returns the previous setting. A virtual pixel is any pixel access
3713 % that is outside the boundaries of the image cache.
3715 % The format of the SetImageVirtualPixelMethod() method is:
3717 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3718 % const VirtualPixelMethod virtual_pixel_method)
3720 % A description of each parameter follows:
3722 % o image: the image.
3724 % o virtual_pixel_method: choose the type of virtual pixel.
3727 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3728 const VirtualPixelMethod virtual_pixel_method)
3730 assert(image != (const Image *) NULL);
3731 assert(image->signature == MagickSignature);
3732 if (image->debug != MagickFalse)
3733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3734 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3742 % S m u s h I m a g e s %
3746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3748 % SmushImages() takes all images from the current image pointer to the end
3749 % of the image list and smushes them to each other top-to-bottom if the
3750 % stack parameter is true, otherwise left-to-right.
3752 % The current gravity setting now effects how the image is justified in the
3755 % The format of the SmushImages method is:
3757 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3758 % ExceptionInfo *exception)
3760 % A description of each parameter follows:
3762 % o images: the image sequence.
3764 % o stack: A value other than 0 stacks the images top-to-bottom.
3766 % o offset: minimum distance in pixels between images.
3768 % o exception: return any errors or warnings in this structure.
3772 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3773 const ssize_t offset,ExceptionInfo *exception)
3787 register const Quantum
3800 if (images->previous == (Image *) NULL)
3803 SetGeometry(smush_image,&right_geometry);
3804 GravityAdjustGeometry(right_image->columns,right_image->rows,
3805 right_image->gravity,&right_geometry);
3806 left_image=images->previous;
3807 SetGeometry(smush_image,&left_geometry);
3808 GravityAdjustGeometry(left_image->columns,left_image->rows,
3809 left_image->gravity,&left_geometry);
3810 gap=right_image->columns;
3811 left_view=AcquireCacheView(left_image);
3812 right_view=AcquireCacheView(right_image);
3813 for (y=0; y < (ssize_t) smush_image->rows; y++)
3815 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3817 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3818 if ((p == (const Quantum *) NULL) ||
3819 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3820 ((left_image->columns-x-1) >= gap))
3823 i=(ssize_t) left_image->columns-x-1;
3824 for (x=0; x < (ssize_t) right_image->columns; x++)
3826 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3828 if ((p == (const Quantum *) NULL) ||
3829 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3830 ((x+i) >= (ssize_t) gap))
3833 if ((x+i) < (ssize_t) gap)
3836 right_view=DestroyCacheView(right_view);
3837 left_view=DestroyCacheView(left_view);
3838 if (y < (ssize_t) smush_image->rows)
3840 return((ssize_t) gap-offset);
3843 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3844 const ssize_t offset,ExceptionInfo *exception)
3858 register const Quantum
3871 if (images->previous == (Image *) NULL)
3873 bottom_image=images;
3874 SetGeometry(smush_image,&bottom_geometry);
3875 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3876 bottom_image->gravity,&bottom_geometry);
3877 top_image=images->previous;
3878 SetGeometry(smush_image,&top_geometry);
3879 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3881 gap=bottom_image->rows;
3882 top_view=AcquireCacheView(top_image);
3883 bottom_view=AcquireCacheView(bottom_image);
3884 for (x=0; x < (ssize_t) smush_image->columns; x++)
3886 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3888 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3889 if ((p == (const Quantum *) NULL) ||
3890 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3891 ((top_image->rows-y-1) >= gap))
3894 i=(ssize_t) top_image->rows-y-1;
3895 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3897 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3899 if ((p == (const Quantum *) NULL) ||
3900 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3901 ((y+i) >= (ssize_t) gap))
3904 if ((y+i) < (ssize_t) gap)
3907 bottom_view=DestroyCacheView(bottom_view);
3908 top_view=DestroyCacheView(top_view);
3909 if (x < (ssize_t) smush_image->columns)
3911 return((ssize_t) gap-offset);
3914 MagickExport Image *SmushImages(const Image *images,
3915 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3917 #define SmushImageTag "Smush/Image"
3939 register const Image
3952 Compute maximum area of smushed area.
3954 assert(images != (Image *) NULL);
3955 assert(images->signature == MagickSignature);
3956 if (images->debug != MagickFalse)
3957 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3958 assert(exception != (ExceptionInfo *) NULL);
3959 assert(exception->signature == MagickSignature);
3963 width=image->columns;
3965 next=GetNextImageInList(image);
3966 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3968 if (next->matte != MagickFalse)
3971 if (stack != MagickFalse)
3973 if (next->columns > width)
3974 width=next->columns;
3976 if (next->previous != (Image *) NULL)
3980 width+=next->columns;
3981 if (next->previous != (Image *) NULL)
3983 if (next->rows > height)
3989 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3990 if (smush_image == (Image *) NULL)
3991 return((Image *) NULL);
3992 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3994 smush_image=DestroyImage(smush_image);
3995 return((Image *) NULL);
3997 smush_image->matte=matte;
3998 (void) SetImageBackgroundColor(smush_image);
4002 smush_view=AcquireCacheView(smush_image);
4003 for (n=0; n < (MagickOffsetType) number_images; n++)
4005 SetGeometry(smush_image,&geometry);
4006 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4007 if (stack != MagickFalse)
4009 x_offset-=geometry.x;
4010 y_offset-=SmushYGap(smush_image,image,offset,exception);
4014 x_offset-=SmushXGap(smush_image,image,offset,exception);
4015 y_offset-=geometry.y;
4017 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
4018 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4019 if (proceed == MagickFalse)
4021 if (stack == MagickFalse)
4023 x_offset+=(ssize_t) image->columns;
4029 y_offset+=(ssize_t) image->rows;
4031 image=GetNextImageInList(image);
4033 if (stack == MagickFalse)
4034 smush_image->columns=(size_t) x_offset;
4036 smush_image->rows=(size_t) y_offset;
4037 smush_view=DestroyCacheView(smush_view);
4038 if (status == MagickFalse)
4039 smush_image=DestroyImage(smush_image);
4040 return(smush_image);
4044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4048 % S t r i p I m a g e %
4052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4054 % StripImage() strips an image of all profiles and comments.
4056 % The format of the StripImage method is:
4058 % MagickBooleanType StripImage(Image *image)
4060 % A description of each parameter follows:
4062 % o image: the image.
4065 MagickExport MagickBooleanType StripImage(Image *image)
4067 assert(image != (Image *) NULL);
4068 if (image->debug != MagickFalse)
4069 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4070 DestroyImageProfiles(image);
4071 (void) DeleteImageProperty(image,"comment");
4072 (void) DeleteImageProperty(image,"date:create");
4073 (void) DeleteImageProperty(image,"date:modify");
4074 (void) SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4083 + S y n c I m a g e %
4087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4089 % SyncImage() initializes the red, green, and blue intensities of each pixel
4090 % as defined by the colormap index.
4092 % The format of the SyncImage method is:
4094 % MagickBooleanType SyncImage(Image *image)
4096 % A description of each parameter follows:
4098 % o image: the image.
4102 static inline Quantum PushColormapIndex(Image *image,
4103 const size_t index,MagickBooleanType *range_exception)
4105 if (index < image->colors)
4106 return((Quantum) index);
4107 *range_exception=MagickTrue;
4108 return((Quantum) 0);
4111 MagickExport MagickBooleanType SyncImage(Image *image)
4126 assert(image != (Image *) NULL);
4127 if (image->debug != MagickFalse)
4128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4129 assert(image->signature == MagickSignature);
4130 if (image->storage_class == DirectClass)
4131 return(MagickFalse);
4132 range_exception=MagickFalse;
4134 exception=(&image->exception);
4135 image_view=AcquireCacheView(image);
4136 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4137 #pragma omp parallel for schedule(dynamic,4) shared(status)
4139 for (y=0; y < (ssize_t) image->rows; y++)
4150 if (status == MagickFalse)
4152 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4153 if (q == (Quantum *) NULL)
4158 for (x=0; x < (ssize_t) image->columns; x++)
4160 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4162 SetPixelPacket(image,image->colormap+(ssize_t) index,q);
4163 q+=GetPixelChannels(image);
4165 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4168 image_view=DestroyCacheView(image_view);
4169 if (range_exception != MagickFalse)
4170 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4171 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4180 % S y n c I m a g e S e t t i n g s %
4184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4186 % SyncImageSettings() sync the image info options to the image.
4188 % The format of the SyncImageSettings method is:
4190 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4192 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4195 % A description of each parameter follows:
4197 % o image_info: the image info.
4199 % o image: the image.
4203 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4209 assert(image_info != (const ImageInfo *) NULL);
4210 assert(image_info->signature == MagickSignature);
4211 assert(images != (Image *) NULL);
4212 assert(images->signature == MagickSignature);
4213 if (images->debug != MagickFalse)
4214 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4216 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4217 (void) SyncImageSettings(image_info,image);
4218 (void) DeleteImageOption(image_info,"page");
4222 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4226 property[MaxTextExtent];
4244 assert(image_info != (const ImageInfo *) NULL);
4245 assert(image_info->signature == MagickSignature);
4246 assert(image != (Image *) NULL);
4247 assert(image->signature == MagickSignature);
4248 if (image->debug != MagickFalse)
4249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4250 option=GetImageOption(image_info,"background");
4251 if (option != (const char *) NULL)
4252 (void) QueryColorDatabase(option,&image->background_color,
4254 option=GetImageOption(image_info,"bias");
4255 if (option != (const char *) NULL)
4256 image->bias=SiPrefixToDouble(option,QuantumRange);
4257 option=GetImageOption(image_info,"black-point-compensation");
4258 if (option != (const char *) NULL)
4259 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4260 MagickBooleanOptions,MagickFalse,option);
4261 option=GetImageOption(image_info,"blue-primary");
4262 if (option != (const char *) NULL)
4264 flags=ParseGeometry(option,&geometry_info);
4265 image->chromaticity.blue_primary.x=geometry_info.rho;
4266 image->chromaticity.blue_primary.y=geometry_info.sigma;
4267 if ((flags & SigmaValue) == 0)
4268 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4270 option=GetImageOption(image_info,"bordercolor");
4271 if (option != (const char *) NULL)
4272 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4273 option=GetImageOption(image_info,"colors");
4274 if (option != (const char *) NULL)
4275 image->colors=StringToUnsignedLong(option);
4276 option=GetImageOption(image_info,"compose");
4277 if (option != (const char *) NULL)
4278 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4279 MagickFalse,option);
4280 option=GetImageOption(image_info,"compress");
4281 if (option != (const char *) NULL)
4282 image->compression=(CompressionType) ParseCommandOption(
4283 MagickCompressOptions,MagickFalse,option);
4284 option=GetImageOption(image_info,"debug");
4285 if (option != (const char *) NULL)
4286 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4287 MagickFalse,option);
4288 option=GetImageOption(image_info,"density");
4289 if (option != (const char *) NULL)
4297 flags=ParseGeometry(option,&geometry_info);
4298 image->x_resolution=geometry_info.rho;
4299 image->y_resolution=geometry_info.sigma;
4300 if ((flags & SigmaValue) == 0)
4301 image->y_resolution=image->x_resolution;
4303 option=GetImageOption(image_info,"depth");
4304 if (option != (const char *) NULL)
4305 image->depth=StringToUnsignedLong(option);
4306 option=GetImageOption(image_info,"endian");
4307 if (option != (const char *) NULL)
4308 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4309 MagickFalse,option);
4310 option=GetImageOption(image_info,"filter");
4311 if (option != (const char *) NULL)
4312 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4313 MagickFalse,option);
4314 option=GetImageOption(image_info,"fuzz");
4315 if (option != (const char *) NULL)
4316 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4317 option=GetImageOption(image_info,"gravity");
4318 if (option != (const char *) NULL)
4319 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4320 MagickFalse,option);
4321 option=GetImageOption(image_info,"green-primary");
4322 if (option != (const char *) NULL)
4324 flags=ParseGeometry(option,&geometry_info);
4325 image->chromaticity.green_primary.x=geometry_info.rho;
4326 image->chromaticity.green_primary.y=geometry_info.sigma;
4327 if ((flags & SigmaValue) == 0)
4328 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4330 option=GetImageOption(image_info,"intent");
4331 if (option != (const char *) NULL)
4332 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4333 MagickIntentOptions,MagickFalse,option);
4334 option=GetImageOption(image_info,"interlace");
4335 if (option != (const char *) NULL)
4336 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4337 MagickFalse,option);
4338 option=GetImageOption(image_info,"interpolate");
4339 if (option != (const char *) NULL)
4340 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
4341 MagickInterpolateOptions,MagickFalse,option);
4342 option=GetImageOption(image_info,"loop");
4343 if (option != (const char *) NULL)
4344 image->iterations=StringToUnsignedLong(option);
4345 option=GetImageOption(image_info,"mattecolor");
4346 if (option != (const char *) NULL)
4347 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4348 option=GetImageOption(image_info,"orient");
4349 if (option != (const char *) NULL)
4350 image->orientation=(OrientationType) ParseCommandOption(
4351 MagickOrientationOptions,MagickFalse,option);
4352 option=GetImageOption(image_info,"page");
4353 if (option != (const char *) NULL)
4358 geometry=GetPageGeometry(option);
4359 flags=ParseAbsoluteGeometry(geometry,&image->page);
4360 geometry=DestroyString(geometry);
4362 option=GetImageOption(image_info,"quality");
4363 if (option != (const char *) NULL)
4364 image->quality=StringToUnsignedLong(option);
4365 option=GetImageOption(image_info,"red-primary");
4366 if (option != (const char *) NULL)
4368 flags=ParseGeometry(option,&geometry_info);
4369 image->chromaticity.red_primary.x=geometry_info.rho;
4370 image->chromaticity.red_primary.y=geometry_info.sigma;
4371 if ((flags & SigmaValue) == 0)
4372 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4374 if (image_info->quality != UndefinedCompressionQuality)
4375 image->quality=image_info->quality;
4376 option=GetImageOption(image_info,"scene");
4377 if (option != (const char *) NULL)
4378 image->scene=StringToUnsignedLong(option);
4379 option=GetImageOption(image_info,"taint");
4380 if (option != (const char *) NULL)
4381 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4382 MagickFalse,option);
4383 option=GetImageOption(image_info,"tile-offset");
4384 if (option != (const char *) NULL)
4389 geometry=GetPageGeometry(option);
4390 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4391 geometry=DestroyString(geometry);
4393 option=GetImageOption(image_info,"transparent-color");
4394 if (option != (const char *) NULL)
4395 (void) QueryColorDatabase(option,&image->transparent_color,
4397 option=GetImageOption(image_info,"type");
4398 if (option != (const char *) NULL)
4399 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4401 option=GetImageOption(image_info,"units");
4402 if (option != (const char *) NULL)
4403 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4404 MagickFalse,option);
4406 units = image_info->units;
4407 if (units != UndefinedResolution)
4409 if (image->units != units)
4410 switch (image->units)
4412 case PixelsPerInchResolution:
4414 if (units == PixelsPerCentimeterResolution)
4416 image->x_resolution/=2.54;
4417 image->y_resolution/=2.54;
4421 case PixelsPerCentimeterResolution:
4423 if (units == PixelsPerInchResolution)
4425 image->x_resolution=(double) ((size_t) (100.0*2.54*
4426 image->x_resolution+0.5))/100.0;
4427 image->y_resolution=(double) ((size_t) (100.0*2.54*
4428 image->y_resolution+0.5))/100.0;
4437 option=GetImageOption(image_info,"white-point");
4438 if (option != (const char *) NULL)
4440 flags=ParseGeometry(option,&geometry_info);
4441 image->chromaticity.white_point.x=geometry_info.rho;
4442 image->chromaticity.white_point.y=geometry_info.sigma;
4443 if ((flags & SigmaValue) == 0)
4444 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4446 ResetImageOptionIterator(image_info);
4447 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4449 value=GetImageOption(image_info,option);
4450 if (value != (const char *) NULL)
4452 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4453 (void) SetImageArtifact(image,property,value);
4455 option=GetNextImageOption(image_info);