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 "magick/studio.h"
44 #include "magick/animate.h"
45 #include "magick/artifact.h"
46 #include "magick/blob.h"
47 #include "magick/blob-private.h"
48 #include "magick/cache.h"
49 #include "magick/cache-private.h"
50 #include "magick/cache-view.h"
51 #include "magick/client.h"
52 #include "magick/color.h"
53 #include "magick/color-private.h"
54 #include "magick/colormap.h"
55 #include "magick/colorspace.h"
56 #include "magick/colorspace-private.h"
57 #include "magick/composite.h"
58 #include "magick/composite-private.h"
59 #include "magick/compress.h"
60 #include "magick/constitute.h"
61 #include "magick/deprecate.h"
62 #include "magick/display.h"
63 #include "magick/draw.h"
64 #include "magick/enhance.h"
65 #include "magick/exception.h"
66 #include "magick/exception-private.h"
67 #include "magick/gem.h"
68 #include "magick/geometry.h"
69 #include "magick/histogram.h"
70 #include "magick/image-private.h"
71 #include "magick/list.h"
72 #include "magick/magic.h"
73 #include "magick/magick.h"
74 #include "magick/memory_.h"
75 #include "magick/module.h"
76 #include "magick/monitor.h"
77 #include "magick/monitor-private.h"
78 #include "magick/option.h"
79 #include "magick/paint.h"
80 #include "magick/pixel-private.h"
81 #include "magick/profile.h"
82 #include "magick/property.h"
83 #include "magick/quantize.h"
84 #include "magick/random_.h"
85 #include "magick/segment.h"
86 #include "magick/semaphore.h"
87 #include "magick/signature-private.h"
88 #include "magick/statistic.h"
89 #include "magick/string_.h"
90 #include "magick/string-private.h"
91 #include "magick/thread-private.h"
92 #include "magick/threshold.h"
93 #include "magick/timer.h"
94 #include "magick/utility.h"
95 #include "magick/version.h"
96 #include "magick/xwindow-private.h"
102 BackgroundColor[] = "#ffffff", /* white */
103 BorderColor[] = "#dfdfdf", /* gray */
104 DefaultTileFrame[] = "15x15+3+3",
105 DefaultTileGeometry[] = "120x120+4+3>",
106 DefaultTileLabel[] = "%f\n%G\n%b",
107 ForegroundColor[] = "#000", /* black */
108 LoadImageTag[] = "Load/Image",
109 LoadImagesTag[] = "Load/Images",
110 MatteColor[] = "#bdbdbd", /* gray */
111 PSDensityGeometry[] = "72.0x72.0",
112 PSPageGeometry[] = "612x792",
113 SaveImageTag[] = "Save/Image",
114 SaveImagesTag[] = "Save/Images",
115 TransparentColor[] = "#00000000"; /* transparent black */
118 DefaultResolution = 72.0;
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 % A c q u i r e I m a g e %
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % AcquireImage() returns a pointer to an image structure initialized to
134 % The format of the AcquireImage method is:
136 % Image *AcquireImage(const ImageInfo *image_info)
138 % A description of each parameter follows:
140 % o image_info: Many of the image default values are set from this
141 % structure. For example, filename, compression, depth, background color,
145 MagickExport Image *AcquireImage(const ImageInfo *image_info)
157 Allocate image structure.
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
160 image=(Image *) AcquireMagickMemory(sizeof(*image));
161 if (image == (Image *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 (void) ResetMagickMemory(image,0,sizeof(*image));
165 Initialize Image structure.
167 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
168 image->storage_class=DirectClass;
169 image->depth=MAGICKCORE_QUANTUM_DEPTH;
170 image->colorspace=RGBColorspace;
171 image->interlace=NoInterlace;
172 image->ticks_per_second=UndefinedTicksPerSecond;
173 image->compose=OverCompositeOp;
175 GetExceptionInfo(&image->exception);
176 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
178 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
179 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
180 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
182 image->x_resolution=DefaultResolution;
183 image->y_resolution=DefaultResolution;
184 image->units=PixelsPerInchResolution;
185 GetTimerInfo(&image->timer);
186 image->ping=MagickFalse;
187 image->cache=AcquirePixelCache(0);
188 image->blob=CloneBlobInfo((BlobInfo *) NULL);
189 image->debug=IsEventLogging();
190 image->reference_count=1;
191 image->semaphore=AllocateSemaphoreInfo();
192 image->signature=MagickSignature;
193 if (image_info == (ImageInfo *) NULL)
198 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
200 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
201 (void) CopyMagickString(image->magick_filename,image_info->filename,
203 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
204 if (image_info->size != (char *) NULL)
206 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
207 image->columns=image->extract_info.width;
208 image->rows=image->extract_info.height;
209 image->offset=image->extract_info.x;
210 image->extract_info.x=0;
211 image->extract_info.y=0;
213 if (image_info->extract != (char *) NULL)
218 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
219 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
221 image->extract_info=geometry;
222 Swap(image->columns,image->extract_info.width);
223 Swap(image->rows,image->extract_info.height);
226 image->compression=image_info->compression;
227 image->quality=image_info->quality;
228 image->endian=image_info->endian;
229 image->interlace=image_info->interlace;
230 image->units=image_info->units;
231 if (image_info->density != (char *) NULL)
236 flags=ParseGeometry(image_info->density,&geometry_info);
237 image->x_resolution=geometry_info.rho;
238 image->y_resolution=geometry_info.sigma;
239 if ((flags & SigmaValue) == 0)
240 image->y_resolution=image->x_resolution;
242 if (image_info->page != (char *) NULL)
247 image->page=image->extract_info;
248 geometry=GetPageGeometry(image_info->page);
249 (void) ParseAbsoluteGeometry(geometry,&image->page);
250 geometry=DestroyString(geometry);
252 if (image_info->depth != 0)
253 image->depth=image_info->depth;
254 image->dither=image_info->dither;
255 image->background_color=image_info->background_color;
256 image->border_color=image_info->border_color;
257 image->matte_color=image_info->matte_color;
258 image->transparent_color=image_info->transparent_color;
259 image->ping=image_info->ping;
260 image->progress_monitor=image_info->progress_monitor;
261 image->client_data=image_info->client_data;
262 if (image_info->cache != (void *) NULL)
263 ClonePixelCacheMethods(image->cache,image_info->cache);
264 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
265 (void) SyncImageSettings(image_info,image);
266 option=GetImageOption(image_info,"delay");
267 if (option != (const char *) NULL)
272 flags=ParseGeometry(option,&geometry_info);
273 if ((flags & GreaterValue) != 0)
275 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
276 image->delay=(size_t) floor(geometry_info.rho+0.5);
279 if ((flags & LessValue) != 0)
281 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
282 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
285 image->delay=(size_t) floor(geometry_info.rho+0.5);
286 if ((flags & SigmaValue) != 0)
287 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
289 option=GetImageOption(image_info,"dispose");
290 if (option != (const char *) NULL)
291 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 % A c q u i r e I m a g e I n f o %
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 % AcquireImageInfo() allocates the ImageInfo structure.
309 % The format of the AcquireImageInfo method is:
311 % ImageInfo *AcquireImageInfo(void)
314 MagickExport ImageInfo *AcquireImageInfo(void)
319 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
320 if (image_info == (ImageInfo *) NULL)
321 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
322 GetImageInfo(image_info);
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % A c q u i r e N e x t I m a g e %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % AcquireNextImage() initializes the next image in a sequence to
338 % default values. The next member of image points to the newly allocated
339 % image. If there is a memory shortage, next is assigned NULL.
341 % The format of the AcquireNextImage method is:
343 % void AcquireNextImage(const ImageInfo *image_info,Image *image)
345 % A description of each parameter follows:
347 % o image_info: Many of the image default values are set from this
348 % structure. For example, filename, compression, depth, background color,
351 % o image: the image.
354 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
357 Allocate image structure.
359 assert(image != (Image *) NULL);
360 assert(image->signature == MagickSignature);
361 if (image->debug != MagickFalse)
362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
363 image->next=AcquireImage(image_info);
364 if (GetNextImageInList(image) == (Image *) NULL)
366 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
368 if (image_info != (ImageInfo *) NULL)
369 (void) CopyMagickString(GetNextImageInList(image)->filename,
370 image_info->filename,MaxTextExtent);
371 DestroyBlob(GetNextImageInList(image));
372 image->next->blob=ReferenceBlob(image->blob);
373 image->next->endian=image->endian;
374 image->next->scene=image->scene+1;
375 image->next->previous=image;
379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 % A p p e n d I m a g e s %
387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 % AppendImages() takes all images from the current image pointer to the end
390 % of the image list and appends them to each other top-to-bottom if the
391 % stack parameter is true, otherwise left-to-right.
393 % The current gravity setting now effects how the image is justified in the
396 % The format of the AppendImages method is:
398 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
399 % ExceptionInfo *exception)
401 % A description of each parameter follows:
403 % o images: the image sequence.
405 % o stack: A value other than 0 stacks the images top-to-bottom.
407 % o exception: return any errors or warnings in this structure.
410 MagickExport Image *AppendImages(const Image *images,
411 const MagickBooleanType stack,ExceptionInfo *exception)
413 #define AppendImageTag "Append/Image"
450 Compute maximum area of appended area.
452 assert(images != (Image *) NULL);
453 assert(images->signature == MagickSignature);
454 if (images->debug != MagickFalse)
455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
456 assert(exception != (ExceptionInfo *) NULL);
457 assert(exception->signature == MagickSignature);
461 width=image->columns;
463 next=GetNextImageInList(image);
464 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
466 if (next->matte != MagickFalse)
469 if (stack != MagickFalse)
471 if (next->columns > width)
476 width+=next->columns;
477 if (next->rows > height)
483 append_image=CloneImage(image,width,height,MagickTrue,exception);
484 if (append_image == (Image *) NULL)
485 return((Image *) NULL);
486 if (SetImageStorageClass(append_image,DirectClass) == MagickFalse)
488 InheritException(exception,&append_image->exception);
489 append_image=DestroyImage(append_image);
490 return((Image *) NULL);
492 append_image->matte=matte;
493 (void) SetImageBackgroundColor(append_image);
497 append_view=AcquireCacheView(append_image);
498 for (n=0; n < (MagickOffsetType) number_images; n++)
500 SetGeometry(append_image,&geometry);
501 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
502 if (stack != MagickFalse)
503 x_offset-=geometry.x;
505 y_offset-=geometry.y;
506 image_view=AcquireCacheView(image);
507 #if defined(MAGICKCORE_OPENMP_SUPPORT)
508 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
510 for (y=0; y < (ssize_t) image->rows; y++)
515 register const IndexPacket
518 register const PixelPacket
522 *restrict append_indexes;
530 if (status == MagickFalse)
532 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
533 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
534 image->columns,1,exception);
535 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
540 indexes=GetCacheViewVirtualIndexQueue(image_view);
541 append_indexes=GetCacheViewAuthenticIndexQueue(append_view);
542 for (x=0; x < (ssize_t) image->columns; x++)
544 SetRedPixelComponent(q,GetRedPixelComponent(p));
545 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
546 SetBluePixelComponent(q,GetBluePixelComponent(p));
547 SetOpacityPixelComponent(q,OpaqueOpacity);
548 if (image->matte != MagickFalse)
549 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
550 if ((image->colorspace == CMYKColorspace) &&
551 (append_image->colorspace == CMYKColorspace))
552 SetIndexPixelComponent(append_indexes+x,GetIndexPixelComponent(
557 sync=SyncCacheViewAuthenticPixels(append_view,exception);
558 if (sync == MagickFalse)
561 image_view=DestroyCacheView(image_view);
562 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
563 if (proceed == MagickFalse)
565 if (stack == MagickFalse)
567 x_offset+=(ssize_t) image->columns;
573 y_offset+=(ssize_t) image->rows;
575 image=GetNextImageInList(image);
577 append_view=DestroyCacheView(append_view);
578 if (status == MagickFalse)
579 append_image=DestroyImage(append_image);
580 return(append_image);
584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
588 % C a t c h I m a g e E x c e p t i o n %
592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
594 % CatchImageException() returns if no exceptions are found in the image
595 % sequence, otherwise it determines the most severe exception and reports
596 % it as a warning or error depending on the severity.
598 % The format of the CatchImageException method is:
600 % ExceptionType CatchImageException(Image *image)
602 % A description of each parameter follows:
604 % o image: An image sequence.
607 MagickExport ExceptionType CatchImageException(Image *image)
615 assert(image != (const Image *) NULL);
616 assert(image->signature == MagickSignature);
617 if (image->debug != MagickFalse)
618 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
619 exception=AcquireExceptionInfo();
620 GetImageException(image,exception);
621 CatchException(exception);
622 severity=exception->severity;
623 exception=DestroyExceptionInfo(exception);
628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
632 % C l i p I m a g e P a t h %
636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
638 % ClipImagePath() sets the image clip mask based any clipping path information
641 % The format of the ClipImagePath method is:
643 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
644 % const MagickBooleanType inside)
646 % A description of each parameter follows:
648 % o image: the image.
650 % o pathname: name of clipping path resource. If name is preceded by #, use
651 % clipping path numbered by name.
653 % o inside: if non-zero, later operations take effect inside clipping path.
654 % Otherwise later operations take effect outside clipping path.
658 MagickExport MagickBooleanType ClipImage(Image *image)
660 return(ClipImagePath(image,"#1",MagickTrue));
663 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
664 const MagickBooleanType inside)
666 #define ClipImagePathTag "ClipPath/Image"
680 assert(image != (const Image *) NULL);
681 assert(image->signature == MagickSignature);
682 if (image->debug != MagickFalse)
683 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
684 assert(pathname != NULL);
685 property=AcquireString(pathname);
686 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
688 value=GetImageProperty(image,property);
689 property=DestroyString(property);
690 if (value == (const char *) NULL)
692 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
696 image_info=AcquireImageInfo();
697 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
698 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
699 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
700 image_info=DestroyImageInfo(image_info);
701 if (clip_mask == (Image *) NULL)
703 if (clip_mask->storage_class == PseudoClass)
705 (void) SyncImage(clip_mask);
706 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
709 if (inside == MagickFalse)
710 (void) NegateImage(clip_mask,MagickFalse);
711 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
712 "8BIM:1999,2998:%s\nPS",pathname);
713 (void) SetImageClipMask(image,clip_mask);
714 clip_mask=DestroyImage(clip_mask);
719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723 % C l o n e I m a g e %
727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
729 % CloneImage() copies an image and returns the copy as a new image object.
731 % If the specified columns and rows is 0, an exact copy of the image is
732 % returned, otherwise the pixel data is undefined and must be initialized
733 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
734 % failure, a NULL image is returned and exception describes the reason for the
737 % The format of the CloneImage method is:
739 % Image *CloneImage(const Image *image,const size_t columns,
740 % const size_t rows,const MagickBooleanType orphan,
741 % ExceptionInfo *exception)
743 % A description of each parameter follows:
745 % o image: the image.
747 % o columns: the number of columns in the cloned image.
749 % o rows: the number of rows in the cloned image.
751 % o detach: With a value other than 0, the cloned image is detached from
752 % its parent I/O stream.
754 % o exception: return any errors or warnings in this structure.
757 MagickExport Image *CloneImage(const Image *image,const size_t columns,
758 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
772 assert(image != (const Image *) NULL);
773 assert(image->signature == MagickSignature);
774 if (image->debug != MagickFalse)
775 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
776 assert(exception != (ExceptionInfo *) NULL);
777 assert(exception->signature == MagickSignature);
778 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
779 if (clone_image == (Image *) NULL)
780 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
781 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
782 clone_image->signature=MagickSignature;
783 clone_image->storage_class=image->storage_class;
784 clone_image->channels=image->channels;
785 clone_image->colorspace=image->colorspace;
786 clone_image->matte=image->matte;
787 clone_image->columns=image->columns;
788 clone_image->rows=image->rows;
789 clone_image->dither=image->dither;
790 if (image->colormap != (PixelPacket *) NULL)
793 Allocate and copy the image colormap.
795 clone_image->colors=image->colors;
796 length=(size_t) image->colors;
797 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
798 sizeof(*clone_image->colormap));
799 if (clone_image->colormap == (PixelPacket *) NULL)
800 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
801 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
802 sizeof(*clone_image->colormap));
804 (void) CloneImageProfiles(clone_image,image);
805 (void) CloneImageProperties(clone_image,image);
806 (void) CloneImageArtifacts(clone_image,image);
807 GetTimerInfo(&clone_image->timer);
808 GetExceptionInfo(&clone_image->exception);
809 InheritException(&clone_image->exception,&image->exception);
810 if (image->ascii85 != (void *) NULL)
811 Ascii85Initialize(clone_image);
812 clone_image->magick_columns=image->magick_columns;
813 clone_image->magick_rows=image->magick_rows;
814 clone_image->type=image->type;
815 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
817 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
818 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
819 clone_image->progress_monitor=image->progress_monitor;
820 clone_image->client_data=image->client_data;
821 clone_image->reference_count=1;
822 clone_image->next=image->next;
823 clone_image->previous=image->previous;
824 clone_image->list=NewImageList();
825 clone_image->clip_mask=NewImageList();
826 clone_image->mask=NewImageList();
827 if (detach == MagickFalse)
828 clone_image->blob=ReferenceBlob(image->blob);
831 clone_image->next=NewImageList();
832 clone_image->previous=NewImageList();
833 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
835 clone_image->ping=image->ping;
836 clone_image->debug=IsEventLogging();
837 clone_image->semaphore=AllocateSemaphoreInfo();
838 if ((columns == 0) && (rows == 0))
840 if (image->montage != (char *) NULL)
841 (void) CloneString(&clone_image->montage,image->montage);
842 if (image->directory != (char *) NULL)
843 (void) CloneString(&clone_image->directory,image->directory);
844 if (image->clip_mask != (Image *) NULL)
845 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
847 if (image->mask != (Image *) NULL)
848 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
849 clone_image->cache=ReferencePixelCache(image->cache);
852 if ((columns == image->columns) && (rows == image->rows))
854 if (image->clip_mask != (Image *) NULL)
855 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
857 if (image->mask != (Image *) NULL)
858 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
860 scale=(MagickRealType) columns/(MagickRealType) image->columns;
861 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
862 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
863 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
864 scale=(MagickRealType) rows/(MagickRealType) image->rows;
865 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
866 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
867 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
868 clone_image->columns=columns;
869 clone_image->rows=rows;
870 clone_image->cache=ClonePixelCache(image->cache);
875 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
879 % C l o n e I m a g e I n f o %
883 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885 % CloneImageInfo() makes a copy of the given image info structure. If
886 % NULL is specified, a new image info structure is created initialized to
889 % The format of the CloneImageInfo method is:
891 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
893 % A description of each parameter follows:
895 % o image_info: the image info.
898 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
903 clone_info=AcquireImageInfo();
904 if (image_info == (ImageInfo *) NULL)
906 clone_info->compression=image_info->compression;
907 clone_info->temporary=image_info->temporary;
908 clone_info->adjoin=image_info->adjoin;
909 clone_info->antialias=image_info->antialias;
910 clone_info->scene=image_info->scene;
911 clone_info->number_scenes=image_info->number_scenes;
912 clone_info->depth=image_info->depth;
913 if (image_info->size != (char *) NULL)
914 (void) CloneString(&clone_info->size,image_info->size);
915 if (image_info->extract != (char *) NULL)
916 (void) CloneString(&clone_info->extract,image_info->extract);
917 if (image_info->scenes != (char *) NULL)
918 (void) CloneString(&clone_info->scenes,image_info->scenes);
919 if (image_info->page != (char *) NULL)
920 (void) CloneString(&clone_info->page,image_info->page);
921 clone_info->interlace=image_info->interlace;
922 clone_info->endian=image_info->endian;
923 clone_info->units=image_info->units;
924 clone_info->quality=image_info->quality;
925 if (image_info->sampling_factor != (char *) NULL)
926 (void) CloneString(&clone_info->sampling_factor,
927 image_info->sampling_factor);
928 if (image_info->server_name != (char *) NULL)
929 (void) CloneString(&clone_info->server_name,image_info->server_name);
930 if (image_info->font != (char *) NULL)
931 (void) CloneString(&clone_info->font,image_info->font);
932 if (image_info->texture != (char *) NULL)
933 (void) CloneString(&clone_info->texture,image_info->texture);
934 if (image_info->density != (char *) NULL)
935 (void) CloneString(&clone_info->density,image_info->density);
936 clone_info->pointsize=image_info->pointsize;
937 clone_info->fuzz=image_info->fuzz;
938 clone_info->pen=image_info->pen;
939 clone_info->background_color=image_info->background_color;
940 clone_info->border_color=image_info->border_color;
941 clone_info->matte_color=image_info->matte_color;
942 clone_info->transparent_color=image_info->transparent_color;
943 clone_info->dither=image_info->dither;
944 clone_info->monochrome=image_info->monochrome;
945 clone_info->colors=image_info->colors;
946 clone_info->colorspace=image_info->colorspace;
947 clone_info->type=image_info->type;
948 clone_info->orientation=image_info->orientation;
949 clone_info->preview_type=image_info->preview_type;
950 clone_info->group=image_info->group;
951 clone_info->ping=image_info->ping;
952 clone_info->verbose=image_info->verbose;
953 if (image_info->view != (char *) NULL)
954 (void) CloneString(&clone_info->view,image_info->view);
955 if (image_info->authenticate != (char *) NULL)
956 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
957 (void) CloneImageOptions(clone_info,image_info);
958 clone_info->progress_monitor=image_info->progress_monitor;
959 clone_info->client_data=image_info->client_data;
960 clone_info->cache=image_info->cache;
961 if (image_info->cache != (void *) NULL)
962 clone_info->cache=ReferencePixelCache(image_info->cache);
963 if (image_info->profile != (void *) NULL)
964 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
965 image_info->profile);
966 SetImageInfoFile(clone_info,image_info->file);
967 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
968 clone_info->stream=image_info->stream;
969 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
970 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
971 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
972 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
973 (void) CopyMagickString(clone_info->filename,image_info->filename,
975 clone_info->subimage=image_info->scene; /* deprecated */
976 clone_info->subrange=image_info->number_scenes; /* deprecated */
977 clone_info->channel=image_info->channel;
978 clone_info->debug=IsEventLogging();
979 clone_info->signature=image_info->signature;
984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
988 % C o m b i n e I m a g e s %
992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994 % CombineImages() combines one or more images into a single image. The
995 % grayscale value of the pixels of each image in the sequence is assigned in
996 % order to the specified channels of the combined image. The typical
997 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
999 % The format of the CombineImages method is:
1001 % Image *CombineImages(const Image *image,const ChannelType channel,
1002 % ExceptionInfo *exception)
1004 % A description of each parameter follows:
1006 % o image: the image.
1008 % o exception: return any errors or warnings in this structure.
1011 MagickExport Image *CombineImages(const Image *image,const ChannelType channel,
1012 ExceptionInfo *exception)
1014 #define CombineImageTag "Combine/Image"
1035 Ensure the image are the same size.
1037 assert(image != (const Image *) NULL);
1038 assert(image->signature == MagickSignature);
1039 if (image->debug != MagickFalse)
1040 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1041 assert(exception != (ExceptionInfo *) NULL);
1042 assert(exception->signature == MagickSignature);
1043 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1045 if ((next->columns != image->columns) || (next->rows != image->rows))
1046 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1048 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1049 if (combine_image == (Image *) NULL)
1050 return((Image *) NULL);
1051 if (SetImageStorageClass(combine_image,DirectClass) == MagickFalse)
1053 InheritException(exception,&combine_image->exception);
1054 combine_image=DestroyImage(combine_image);
1055 return((Image *) NULL);
1057 if ((channel & OpacityChannel) != 0)
1058 combine_image->matte=MagickTrue;
1059 (void) SetImageBackgroundColor(combine_image);
1065 combine_view=AcquireCacheView(combine_image);
1066 for (y=0; y < (ssize_t) combine_image->rows; y++)
1077 register const PixelPacket
1080 register PixelPacket
1086 if (status == MagickFalse)
1088 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1090 if (pixels == (PixelPacket *) NULL)
1096 if (((channel & RedChannel) != 0) && (next != (Image *) NULL))
1098 image_view=AcquireCacheView(next);
1099 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1100 if (p == (const PixelPacket *) NULL)
1103 for (x=0; x < (ssize_t) combine_image->columns; x++)
1105 SetRedPixelComponent(q,PixelIntensityToQuantum(p));
1109 image_view=DestroyCacheView(image_view);
1110 next=GetNextImageInList(next);
1112 if (((channel & GreenChannel) != 0) && (next != (Image *) NULL))
1114 image_view=AcquireCacheView(next);
1115 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1116 if (p == (const PixelPacket *) NULL)
1119 for (x=0; x < (ssize_t) combine_image->columns; x++)
1121 SetGreenPixelComponent(q,PixelIntensityToQuantum(p));
1125 image_view=DestroyCacheView(image_view);
1126 next=GetNextImageInList(next);
1128 if (((channel & BlueChannel) != 0) && (next != (Image *) NULL))
1130 image_view=AcquireCacheView(next);
1131 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1132 if (p == (const PixelPacket *) NULL)
1135 for (x=0; x < (ssize_t) combine_image->columns; x++)
1137 SetBluePixelComponent(q,PixelIntensityToQuantum(p));
1141 image_view=DestroyCacheView(image_view);
1142 next=GetNextImageInList(next);
1144 if (((channel & OpacityChannel) != 0) && (next != (Image *) NULL))
1146 image_view=AcquireCacheView(next);
1147 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1148 if (p == (const PixelPacket *) NULL)
1151 for (x=0; x < (ssize_t) combine_image->columns; x++)
1153 SetOpacityPixelComponent(q,PixelIntensityToQuantum(p));
1157 image_view=DestroyCacheView(image_view);
1158 next=GetNextImageInList(next);
1160 if (((channel & IndexChannel) != 0) &&
1161 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1166 image_view=AcquireCacheView(next);
1167 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1168 if (p == (const PixelPacket *) NULL)
1170 indexes=GetCacheViewAuthenticIndexQueue(combine_view);
1171 for (x=0; x < (ssize_t) combine_image->columns; x++)
1173 SetIndexPixelComponent(indexes+x,PixelIntensityToQuantum(p));
1176 image_view=DestroyCacheView(image_view);
1177 next=GetNextImageInList(next);
1179 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1181 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1186 proceed=SetImageProgress(image,CombineImageTag,progress++,
1187 combine_image->rows);
1188 if (proceed == MagickFalse)
1192 combine_view=DestroyCacheView(combine_view);
1193 if (status == MagickFalse)
1194 combine_image=DestroyImage(combine_image);
1195 return(combine_image);
1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1203 % D e s t r o y I m a g e %
1207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1209 % DestroyImage() dereferences an image, deallocating memory associated with
1210 % the image if the reference count becomes zero.
1212 % The format of the DestroyImage method is:
1214 % Image *DestroyImage(Image *image)
1216 % A description of each parameter follows:
1218 % o image: the image.
1221 MagickExport Image *DestroyImage(Image *image)
1229 assert(image != (Image *) NULL);
1230 assert(image->signature == MagickSignature);
1231 if (image->debug != MagickFalse)
1232 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1233 destroy=MagickFalse;
1234 LockSemaphoreInfo(image->semaphore);
1235 image->reference_count--;
1236 if (image->reference_count == 0)
1238 UnlockSemaphoreInfo(image->semaphore);
1239 if (destroy == MagickFalse)
1240 return((Image *) NULL);
1244 DestroyImagePixels(image);
1245 if (image->clip_mask != (Image *) NULL)
1246 image->clip_mask=DestroyImage(image->clip_mask);
1247 if (image->mask != (Image *) NULL)
1248 image->mask=DestroyImage(image->mask);
1249 if (image->montage != (char *) NULL)
1250 image->montage=DestroyString(image->montage);
1251 if (image->directory != (char *) NULL)
1252 image->directory=DestroyString(image->directory);
1253 if (image->colormap != (PixelPacket *) NULL)
1254 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1255 if (image->geometry != (char *) NULL)
1256 image->geometry=DestroyString(image->geometry);
1257 DestroyImageProfiles(image);
1258 DestroyImageProperties(image);
1259 DestroyImageArtifacts(image);
1260 if (image->ascii85 != (Ascii85Info*) NULL)
1261 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1263 (void) DestroyExceptionInfo(&image->exception);
1264 if (image->semaphore != (SemaphoreInfo *) NULL)
1265 DestroySemaphoreInfo(&image->semaphore);
1266 image->signature=(~MagickSignature);
1267 image=(Image *) RelinquishMagickMemory(image);
1272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1276 % D e s t r o y I m a g e I n f o %
1280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1282 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1285 % The format of the DestroyImageInfo method is:
1287 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1289 % A description of each parameter follows:
1291 % o image_info: the image info.
1294 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1296 assert(image_info != (ImageInfo *) NULL);
1297 assert(image_info->signature == MagickSignature);
1298 if (image_info->debug != MagickFalse)
1299 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1300 image_info->filename);
1301 if (image_info->size != (char *) NULL)
1302 image_info->size=DestroyString(image_info->size);
1303 if (image_info->extract != (char *) NULL)
1304 image_info->extract=DestroyString(image_info->extract);
1305 if (image_info->scenes != (char *) NULL)
1306 image_info->scenes=DestroyString(image_info->scenes);
1307 if (image_info->page != (char *) NULL)
1308 image_info->page=DestroyString(image_info->page);
1309 if (image_info->sampling_factor != (char *) NULL)
1310 image_info->sampling_factor=DestroyString(
1311 image_info->sampling_factor);
1312 if (image_info->server_name != (char *) NULL)
1313 image_info->server_name=DestroyString(
1314 image_info->server_name);
1315 if (image_info->font != (char *) NULL)
1316 image_info->font=DestroyString(image_info->font);
1317 if (image_info->texture != (char *) NULL)
1318 image_info->texture=DestroyString(image_info->texture);
1319 if (image_info->density != (char *) NULL)
1320 image_info->density=DestroyString(image_info->density);
1321 if (image_info->view != (char *) NULL)
1322 image_info->view=DestroyString(image_info->view);
1323 if (image_info->authenticate != (char *) NULL)
1324 image_info->authenticate=DestroyString(
1325 image_info->authenticate);
1326 DestroyImageOptions(image_info);
1327 if (image_info->cache != (void *) NULL)
1328 image_info->cache=DestroyPixelCache(image_info->cache);
1329 if (image_info->profile != (StringInfo *) NULL)
1330 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1331 image_info->profile);
1332 image_info->signature=(~MagickSignature);
1333 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1342 + D i s a s s o c i a t e I m a g e S t r e a m %
1346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1348 % DisassociateImageStream() disassociates the image stream.
1350 % The format of the DisassociateImageStream method is:
1352 % MagickBooleanType DisassociateImageStream(const Image *image)
1354 % A description of each parameter follows:
1356 % o image: the image.
1359 MagickExport void DisassociateImageStream(Image *image)
1361 assert(image != (const Image *) NULL);
1362 assert(image->signature == MagickSignature);
1363 if (image->debug != MagickFalse)
1364 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1365 (void) DetachBlob(image->blob);
1369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1373 % G e t I m a g e A l p h a C h a n n e l %
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1379 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1380 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1383 % The format of the GetImageAlphaChannel method is:
1385 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1387 % A description of each parameter follows:
1389 % o image: the image.
1392 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1394 assert(image != (const Image *) NULL);
1395 if (image->debug != MagickFalse)
1396 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1397 assert(image->signature == MagickSignature);
1398 return(image->matte);
1402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1406 % G e t I m a g e C l i p M a s k %
1410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412 % GetImageClipMask() returns the clip path associated with the image.
1414 % The format of the GetImageClipMask method is:
1416 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1418 % A description of each parameter follows:
1420 % o image: the image.
1423 MagickExport Image *GetImageClipMask(const Image *image,
1424 ExceptionInfo *exception)
1426 assert(image != (const Image *) NULL);
1427 if (image->debug != MagickFalse)
1428 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1429 assert(image->signature == MagickSignature);
1430 if (image->clip_mask == (Image *) NULL)
1431 return((Image *) NULL);
1432 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1440 % G e t I m a g e E x c e p t i o n %
1444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1446 % GetImageException() traverses an image sequence and returns any
1447 % error more severe than noted by the exception parameter.
1449 % The format of the GetImageException method is:
1451 % void GetImageException(Image *image,ExceptionInfo *exception)
1453 % A description of each parameter follows:
1455 % o image: Specifies a pointer to a list of one or more images.
1457 % o exception: return the highest severity exception.
1460 MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1465 assert(image != (Image *) NULL);
1466 assert(image->signature == MagickSignature);
1467 if (image->debug != MagickFalse)
1468 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1469 assert(exception != (ExceptionInfo *) NULL);
1470 assert(exception->signature == MagickSignature);
1471 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1473 if (next->exception.severity == UndefinedException)
1475 if (next->exception.severity > exception->severity)
1476 InheritException(exception,&next->exception);
1477 next->exception.severity=UndefinedException;
1482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1486 % G e t I m a g e I n f o %
1490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1492 % GetImageInfo() initializes image_info to default values.
1494 % The format of the GetImageInfo method is:
1496 % void GetImageInfo(ImageInfo *image_info)
1498 % A description of each parameter follows:
1500 % o image_info: the image info.
1503 MagickExport void GetImageInfo(ImageInfo *image_info)
1512 File and image dimension members.
1514 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1515 assert(image_info != (ImageInfo *) NULL);
1516 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1517 image_info->adjoin=MagickTrue;
1518 image_info->interlace=NoInterlace;
1519 image_info->channel=DefaultChannels;
1520 image_info->quality=UndefinedCompressionQuality;
1521 image_info->antialias=MagickTrue;
1522 image_info->dither=MagickTrue;
1523 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1524 if (synchronize != (const char *) NULL)
1525 image_info->synchronize=IsMagickTrue(synchronize);
1526 exception=AcquireExceptionInfo();
1527 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1529 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1530 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1531 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1533 exception=DestroyExceptionInfo(exception);
1534 image_info->debug=IsEventLogging();
1535 image_info->signature=MagickSignature;
1539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1543 % G e t I m a g e I n f o F i l e %
1547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1549 % GetImageInfoFile() returns the image info file member.
1551 % The format of the GetImageInfoFile method is:
1553 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1555 % A description of each parameter follows:
1557 % o image_info: the image info.
1560 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1562 return(image_info->file);
1566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1570 % G e t I m a g e M a s k %
1574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1576 % GetImageMask() returns the mask associated with the image.
1578 % The format of the GetImageMask method is:
1580 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1582 % A description of each parameter follows:
1584 % o image: the image.
1587 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1589 assert(image != (const Image *) NULL);
1590 if (image->debug != MagickFalse)
1591 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1592 assert(image->signature == MagickSignature);
1593 if (image->mask == (Image *) NULL)
1594 return((Image *) NULL);
1595 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1603 % G e t I m a g e C h a n n e l s %
1607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1609 % GetImageChannels() returns the number of pixel channels associated with the
1612 % The format of the GetChannels method is:
1614 % size_t GetImageChannels(Image *image)
1616 % A description of each parameter follows:
1618 % o image: the image.
1621 MagickExport size_t GetImageChannels(Image *image)
1623 assert(image != (Image *) NULL);
1624 assert(image->signature == MagickSignature);
1625 if (image->debug != MagickFalse)
1626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1627 return(image->channels);
1631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1635 + G e t I m a g e R e f e r e n c e C o u n t %
1639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1641 % GetImageReferenceCount() returns the image reference count.
1643 % The format of the GetReferenceCount method is:
1645 % ssize_t GetImageReferenceCount(Image *image)
1647 % A description of each parameter follows:
1649 % o image: the image.
1652 MagickExport ssize_t GetImageReferenceCount(Image *image)
1657 assert(image != (Image *) NULL);
1658 assert(image->signature == MagickSignature);
1659 if (image->debug != MagickFalse)
1660 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1661 LockSemaphoreInfo(image->semaphore);
1662 reference_count=image->reference_count;
1663 UnlockSemaphoreInfo(image->semaphore);
1664 return(reference_count);
1668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1672 % 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 %
1676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1678 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1679 % image. A virtual pixel is any pixel access that is outside the boundaries
1680 % of the image cache.
1682 % The format of the GetImageVirtualPixelMethod() method is:
1684 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1686 % A description of each parameter follows:
1688 % o image: the image.
1691 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1693 assert(image != (Image *) NULL);
1694 assert(image->signature == MagickSignature);
1695 if (image->debug != MagickFalse)
1696 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1697 return(GetPixelCacheVirtualMethod(image));
1701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1705 % I n t e r p r e t I m a g e F i l e n a m e %
1709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1711 % InterpretImageFilename() interprets embedded characters in an image filename.
1712 % The filename length is returned.
1714 % The format of the InterpretImageFilename method is:
1716 % size_t InterpretImageFilename(const ImageInfo *image_info,
1717 % Image *image,const char *format,int value,char *filename)
1719 % A description of each parameter follows.
1721 % o image_info: the image info..
1723 % o image: the image.
1725 % o format: A filename describing the format to use to write the numeric
1726 % argument. Only the first numeric format identifier is replaced.
1728 % o value: Numeric value to substitute into format filename.
1730 % o filename: return the formatted filename in this character buffer.
1733 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1734 Image *image,const char *format,int value,char *filename)
1748 canonical=MagickFalse;
1749 (void) CopyMagickString(filename,format,MaxTextExtent);
1750 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1763 value=(ssize_t) strtol(q,&q,10);
1775 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1776 (p-format)),p,value);
1778 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1779 canonical=MagickTrue;
1788 pattern[MaxTextExtent];
1805 if (strchr(p,']') == (char *) NULL)
1809 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1820 if (LocaleNCompare(pattern,"filename:",9) != 0)
1822 value=(const char *) NULL;
1823 if ((image_info != (const ImageInfo *) NULL) &&
1824 (image != (const Image *) NULL))
1825 value=GetMagickProperty(image_info,image,pattern);
1827 if (image != (Image *) NULL)
1828 value=GetImageProperty(image,pattern);
1830 if (image_info != (ImageInfo *) NULL)
1831 value=GetImageOption(image_info,pattern);
1832 if (value == (const char *) NULL)
1837 (void) CopyMagickString(filename+(p-format),value,(size_t)
1838 (MaxTextExtent-(p-format)));
1840 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1841 canonical=MagickTrue;
1851 for (q=filename; *q != '\0'; q++)
1852 if ((*q == '%') && (*(q+1) == '%'))
1854 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1855 canonical=MagickTrue;
1857 if (canonical == MagickFalse)
1858 (void) CopyMagickString(filename,format,MaxTextExtent);
1859 return(strlen(filename));
1863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1867 % I s H i g h D y n a m i c R a n g e I m a g e %
1871 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1873 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1874 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1877 % The format of the IsHighDynamicRangeImage method is:
1879 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1880 % ExceptionInfo *exception)
1882 % A description of each parameter follows:
1884 % o image: the image.
1886 % o exception: return any errors or warnings in this structure.
1889 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1890 ExceptionInfo *exception)
1892 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1895 return(MagickFalse);
1909 assert(image != (Image *) NULL);
1910 assert(image->signature == MagickSignature);
1911 if (image->debug != MagickFalse)
1912 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1914 GetMagickPixelPacket(image,&zero);
1915 image_view=AcquireCacheView(image);
1916 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1917 #pragma omp parallel for schedule(dynamic,4) shared(status)
1919 for (y=0; y < (ssize_t) image->rows; y++)
1924 register const IndexPacket
1927 register const PixelPacket
1933 if (status == MagickFalse)
1935 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1936 if (p == (const PixelPacket *) NULL)
1941 indexes=GetCacheViewVirtualIndexQueue(image_view);
1943 for (x=0; x < (ssize_t) image->columns; x++)
1945 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1946 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1947 (pixel.red != (QuantumAny) pixel.red))
1949 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1950 (pixel.green != (QuantumAny) pixel.green))
1952 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1953 (pixel.blue != (QuantumAny) pixel.blue))
1955 if (pixel.matte != MagickFalse)
1957 if ((pixel.opacity < 0.0) || (pixel.opacity > QuantumRange) ||
1958 (pixel.opacity != (QuantumAny) pixel.opacity))
1961 if (pixel.colorspace == CMYKColorspace)
1963 if ((pixel.index < 0.0) || (pixel.index > QuantumRange) ||
1964 (pixel.index != (QuantumAny) pixel.index))
1969 if (x < (ssize_t) image->columns)
1972 image_view=DestroyCacheView(image_view);
1973 return(status != MagickFalse ? MagickFalse : MagickTrue);
1978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1982 % I s I m a g e O b j e c t %
1986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1988 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1989 % set of image objects.
1991 % The format of the IsImageObject method is:
1993 % MagickBooleanType IsImageObject(const Image *image)
1995 % A description of each parameter follows:
1997 % o image: the image.
2000 MagickExport MagickBooleanType IsImageObject(const Image *image)
2002 register const Image
2005 assert(image != (Image *) NULL);
2006 if (image->debug != MagickFalse)
2007 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2008 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2009 if (p->signature != MagickSignature)
2010 return(MagickFalse);
2015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2019 % I s T a i n t I m a g e %
2023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2025 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
2026 % since it was first constituted.
2028 % The format of the IsTaintImage method is:
2030 % MagickBooleanType IsTaintImage(const Image *image)
2032 % A description of each parameter follows:
2034 % o image: the image.
2037 MagickExport MagickBooleanType IsTaintImage(const Image *image)
2040 magick[MaxTextExtent],
2041 filename[MaxTextExtent];
2043 register const Image
2046 assert(image != (Image *) NULL);
2047 if (image->debug != MagickFalse)
2048 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2049 assert(image->signature == MagickSignature);
2050 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2051 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2052 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2054 if (p->taint != MagickFalse)
2056 if (LocaleCompare(p->magick,magick) != 0)
2058 if (LocaleCompare(p->filename,filename) != 0)
2061 return(MagickFalse);
2065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2069 % M o d i f y I m a g e %
2073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2075 % ModifyImage() ensures that there is only a single reference to the image
2076 % to be modified, updating the provided image pointer to point to a clone of
2077 % the original image if necessary.
2079 % The format of the ModifyImage method is:
2081 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2083 % A description of each parameter follows:
2085 % o image: the image.
2087 % o exception: return any errors or warnings in this structure.
2090 MagickExport MagickBooleanType ModifyImage(Image **image,
2091 ExceptionInfo *exception)
2096 assert(image != (Image **) NULL);
2097 assert(*image != (Image *) NULL);
2098 assert((*image)->signature == MagickSignature);
2099 if ((*image)->debug != MagickFalse)
2100 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2101 if (GetImageReferenceCount(*image) <= 1)
2103 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2104 LockSemaphoreInfo((*image)->semaphore);
2105 (*image)->reference_count--;
2106 UnlockSemaphoreInfo((*image)->semaphore);
2112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2116 % N e w M a g i c k I m a g e %
2120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2122 % NewMagickImage() creates a blank image canvas of the specified size and
2125 % The format of the NewMagickImage method is:
2127 % Image *NewMagickImage(const ImageInfo *image_info,
2128 % const size_t width,const size_t height,
2129 % const MagickPixelPacket *background)
2131 % A description of each parameter follows:
2133 % o image: the image.
2135 % o width: the image width.
2137 % o height: the image height.
2139 % o background: the image color.
2142 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2143 const size_t width,const size_t height,
2144 const MagickPixelPacket *background)
2161 assert(image_info != (const ImageInfo *) NULL);
2162 if (image_info->debug != MagickFalse)
2163 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2164 assert(image_info->signature == MagickSignature);
2165 assert(background != (const MagickPixelPacket *) NULL);
2166 image=AcquireImage(image_info);
2167 image->columns=width;
2169 image->colorspace=background->colorspace;
2170 image->matte=background->matte;
2171 image->fuzz=background->fuzz;
2172 image->depth=background->depth;
2174 exception=(&image->exception);
2175 image_view=AcquireCacheView(image);
2176 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2177 #pragma omp parallel for schedule(dynamic,4) shared(status)
2179 for (y=0; y < (ssize_t) image->rows; y++)
2181 register IndexPacket
2184 register PixelPacket
2190 if (status == MagickFalse)
2192 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2193 if (q == (PixelPacket *) NULL)
2198 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2199 for (x=0; x < (ssize_t) image->columns; x++)
2201 SetPixelPacket(image,background,q,indexes+x);
2204 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2207 image_view=DestroyCacheView(image_view);
2208 if (status == MagickFalse)
2209 image=DestroyImage(image);
2214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2218 % R e f e r e n c e I m a g e %
2222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2224 % ReferenceImage() increments the reference count associated with an image
2225 % returning a pointer to the image.
2227 % The format of the ReferenceImage method is:
2229 % Image *ReferenceImage(Image *image)
2231 % A description of each parameter follows:
2233 % o image: the image.
2236 MagickExport Image *ReferenceImage(Image *image)
2238 assert(image != (Image *) NULL);
2239 if (image->debug != MagickFalse)
2240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2241 assert(image->signature == MagickSignature);
2242 LockSemaphoreInfo(image->semaphore);
2243 image->reference_count++;
2244 UnlockSemaphoreInfo(image->semaphore);
2249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2253 % R e s e t I m a g e P a g e %
2257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2259 % ResetImagePage() resets the image page canvas and position.
2261 % The format of the ResetImagePage method is:
2263 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2265 % A description of each parameter follows:
2267 % o image: the image.
2269 % o page: the relative page specification.
2272 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2280 assert(image != (Image *) NULL);
2281 assert(image->signature == MagickSignature);
2282 if (image->debug != MagickFalse)
2283 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2284 flags=ParseAbsoluteGeometry(page,&geometry);
2285 if ((flags & WidthValue) != 0)
2287 if ((flags & HeightValue) == 0)
2288 geometry.height=geometry.width;
2289 image->page.width=geometry.width;
2290 image->page.height=geometry.height;
2292 if ((flags & AspectValue) != 0)
2294 if ((flags & XValue) != 0)
2295 image->page.x+=geometry.x;
2296 if ((flags & YValue) != 0)
2297 image->page.y+=geometry.y;
2301 if ((flags & XValue) != 0)
2303 image->page.x=geometry.x;
2304 if ((image->page.width == 0) && (geometry.x > 0))
2305 image->page.width=image->columns+geometry.x;
2307 if ((flags & YValue) != 0)
2309 image->page.y=geometry.y;
2310 if ((image->page.height == 0) && (geometry.y > 0))
2311 image->page.height=image->rows+geometry.y;
2318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2322 % S e p a r a t e I m a g e C h a n n e l %
2326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2328 % SeparateImageChannel() separates a channel from the image and returns it as
2329 % a grayscale image. A channel is a particular color component of each pixel
2332 % The format of the SeparateImageChannel method is:
2334 % MagickBooleanType SeparateImageChannel(Image *image,
2335 % const ChannelType channel)
2337 % A description of each parameter follows:
2339 % o image: the image.
2341 % o channel: Identify which channel to extract: RedChannel, GreenChannel,
2342 % BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2343 % YellowChannel, or BlackChannel.
2346 MagickExport MagickBooleanType SeparateImageChannel(Image *image,
2347 const ChannelType channel)
2349 #define SeparateImageTag "Separate/Image"
2366 assert(image != (Image *) NULL);
2367 assert(image->signature == MagickSignature);
2368 if (image->debug != MagickFalse)
2369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2370 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2371 return(MagickFalse);
2373 Separate image channels.
2376 if (channel == GrayChannels)
2377 image->matte=MagickTrue;
2379 exception=(&image->exception);
2380 image_view=AcquireCacheView(image);
2381 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2382 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2384 for (y=0; y < (ssize_t) image->rows; y++)
2386 register IndexPacket
2389 register PixelPacket
2395 if (status == MagickFalse)
2397 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2398 if (q == (PixelPacket *) NULL)
2403 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2408 for (x=0; x < (ssize_t) image->columns; x++)
2410 SetGreenPixelComponent(q,GetRedPixelComponent(q));
2411 SetBluePixelComponent(q,GetRedPixelComponent(q));
2418 for (x=0; x < (ssize_t) image->columns; x++)
2420 SetRedPixelComponent(q,GetGreenPixelComponent(q));
2421 SetBluePixelComponent(q,GetGreenPixelComponent(q));
2428 for (x=0; x < (ssize_t) image->columns; x++)
2430 SetRedPixelComponent(q,GetBluePixelComponent(q));
2431 SetGreenPixelComponent(q,GetBluePixelComponent(q));
2436 case OpacityChannel:
2438 for (x=0; x < (ssize_t) image->columns; x++)
2440 SetRedPixelComponent(q,GetOpacityPixelComponent(q));
2441 SetGreenPixelComponent(q,GetOpacityPixelComponent(q));
2442 SetBluePixelComponent(q,GetOpacityPixelComponent(q));
2449 if ((image->storage_class != PseudoClass) &&
2450 (image->colorspace != CMYKColorspace))
2452 for (x=0; x < (ssize_t) image->columns; x++)
2454 SetRedPixelComponent(q,GetIndexPixelComponent(indexes+x));
2455 SetGreenPixelComponent(q,GetIndexPixelComponent(indexes+x));
2456 SetBluePixelComponent(q,GetIndexPixelComponent(indexes+x));
2461 case TrueAlphaChannel:
2463 for (x=0; x < (ssize_t) image->columns; x++)
2465 SetRedPixelComponent(q,GetAlphaPixelComponent(q));
2466 SetGreenPixelComponent(q,GetAlphaPixelComponent(q));
2467 SetBluePixelComponent(q,GetAlphaPixelComponent(q));
2474 for (x=0; x < (ssize_t) image->columns; x++)
2476 SetAlphaPixelComponent(q,PixelIntensityToQuantum(q));
2484 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2486 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2491 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2492 #pragma omp critical (MagickCore_SeparateImageChannel)
2494 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2495 if (proceed == MagickFalse)
2499 image_view=DestroyCacheView(image_view);
2500 if (channel != GrayChannels)
2501 image->matte=MagickFalse;
2502 (void) SetImageColorspace(image,RGBColorspace);
2507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2511 % S e p a r a t e I m a g e s %
2515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2517 % SeparateImages() returns a separate grayscale image for each channel
2520 % The format of the SeparateImages method is:
2522 % MagickBooleanType SeparateImages(const Image *image,
2523 % const ChannelType channel,ExceptionInfo *exception)
2525 % A description of each parameter follows:
2527 % o image: the image.
2529 % o channel: Identify which channels to extract: RedChannel, GreenChannel,
2530 % BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2531 % YellowChannel, or BlackChannel.
2533 % o exception: return any errors or warnings in this structure.
2536 MagickExport Image *SeparateImages(const Image *image,const ChannelType channel,
2537 ExceptionInfo *exception)
2543 assert(image != (Image *) NULL);
2544 assert(image->signature == MagickSignature);
2545 if (image->debug != MagickFalse)
2546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2547 images=NewImageList();
2548 if ((channel & RedChannel) != 0)
2550 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2551 (void) SeparateImageChannel(separate_image,RedChannel);
2552 AppendImageToList(&images,separate_image);
2554 if ((channel & GreenChannel) != 0)
2556 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2557 (void) SeparateImageChannel(separate_image,GreenChannel);
2558 AppendImageToList(&images,separate_image);
2560 if ((channel & BlueChannel) != 0)
2562 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2563 (void) SeparateImageChannel(separate_image,BlueChannel);
2564 AppendImageToList(&images,separate_image);
2566 if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace))
2568 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2569 (void) SeparateImageChannel(separate_image,BlackChannel);
2570 AppendImageToList(&images,separate_image);
2572 if ((channel & OpacityChannel) != 0)
2574 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2575 (void) SeparateImageChannel(separate_image,OpacityChannel);
2576 AppendImageToList(&images,separate_image);
2582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2586 % S e t I m a g e A l p h a C h a n n e l %
2590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2592 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2595 % The format of the SetImageAlphaChannel method is:
2597 % MagickBooleanType SetImageAlphaChannel(Image *image,
2598 % const AlphaChannelType alpha_type)
2600 % A description of each parameter follows:
2602 % o image: the image.
2604 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2605 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2606 % OpaqueAlphaChannel, ResetAlphaChannel, SetAlphaChannel,
2607 % ShapeAlphaChannel, and TransparentAlphaChannel.
2610 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2611 const AlphaChannelType alpha_type)
2616 assert(image != (Image *) NULL);
2617 if (image->debug != MagickFalse)
2618 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2619 assert(image->signature == MagickSignature);
2623 case ActivateAlphaChannel:
2625 image->matte=MagickTrue;
2628 case BackgroundAlphaChannel:
2652 Set transparent pixels to background color.
2654 if (image->matte == MagickFalse)
2656 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2658 GetMagickPixelPacket(image,&background);
2659 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2661 if (image->colorspace == CMYKColorspace)
2662 ConvertRGBToCMYK(&background);
2664 SetPixelPacket(image,&background,&pixel,&index);
2666 exception=(&image->exception);
2667 image_view=AcquireCacheView(image);
2668 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2669 #pragma omp parallel for schedule(dynamic,4) shared(status)
2671 for (y=0; y < (ssize_t) image->rows; y++)
2673 register IndexPacket
2676 register PixelPacket
2682 if (status == MagickFalse)
2684 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2686 if (q == (PixelPacket *) NULL)
2691 for (x=0; x < (ssize_t) image->columns; x++)
2693 if (q->opacity == TransparentOpacity)
2695 SetRedPixelComponent(q,pixel.red);
2696 SetGreenPixelComponent(q,pixel.green);
2697 SetBluePixelComponent(q,pixel.blue);
2701 if (image->colorspace == CMYKColorspace)
2703 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2704 for (x=0; x < (ssize_t) image->columns; x++)
2705 SetIndexPixelComponent(indexes+x,index);
2707 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2710 image_view=DestroyCacheView(image_view);
2713 case DeactivateAlphaChannel:
2715 image->matte=MagickFalse;
2718 case ShapeAlphaChannel:
2719 case CopyAlphaChannel:
2722 Special usage case for SeparateImageChannel(): copy grayscale color to
2725 status=SeparateImageChannel(image,GrayChannels);
2726 image->matte=MagickTrue; /* make sure transparency is now on! */
2727 if (alpha_type == ShapeAlphaChannel)
2733 Reset all color channels to background color.
2735 GetMagickPixelPacket(image,&background);
2736 SetMagickPixelPacket(image,&(image->background_color),(IndexPacket *)
2738 (void) LevelColorsImage(image,&background,&background,MagickTrue);
2742 case ExtractAlphaChannel:
2744 status=SeparateImageChannel(image,TrueAlphaChannel);
2745 image->matte=MagickFalse;
2748 case ResetAlphaChannel: /* deprecated */
2749 case OpaqueAlphaChannel:
2751 status=SetImageOpacity(image,OpaqueOpacity);
2752 image->matte=MagickTrue;
2755 case TransparentAlphaChannel:
2757 status=SetImageOpacity(image,TransparentOpacity);
2758 image->matte=MagickTrue;
2761 case SetAlphaChannel:
2763 if (image->matte == MagickFalse)
2765 status=SetImageOpacity(image,OpaqueOpacity);
2766 image->matte=MagickTrue;
2770 case UndefinedAlphaChannel:
2777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2781 % S e t I m a g e B a c k g r o u n d C o l o r %
2785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2787 % SetImageBackgroundColor() initializes the image pixels to the image
2788 % background color. The background color is defined by the background_color
2789 % member of the image structure.
2791 % The format of the SetImage method is:
2793 % MagickBooleanType SetImageBackgroundColor(Image *image)
2795 % A description of each parameter follows:
2797 % o image: the image.
2800 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2823 assert(image != (Image *) NULL);
2824 if (image->debug != MagickFalse)
2825 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2826 assert(image->signature == MagickSignature);
2827 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2828 return(MagickFalse);
2829 if (image->background_color.opacity != OpaqueOpacity)
2830 image->matte=MagickTrue;
2831 GetMagickPixelPacket(image,&background);
2832 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2834 if (image->colorspace == CMYKColorspace)
2835 ConvertRGBToCMYK(&background);
2837 SetPixelPacket(image,&background,&pixel,&index);
2839 Set image background color.
2842 exception=(&image->exception);
2843 image_view=AcquireCacheView(image);
2844 for (y=0; y < (ssize_t) image->rows; y++)
2846 register PixelPacket
2852 if (status == MagickFalse)
2854 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2855 if (q == (PixelPacket *) NULL)
2860 for (x=0; x < (ssize_t) image->columns; x++)
2862 if (image->colorspace == CMYKColorspace)
2864 register IndexPacket
2867 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2868 for (x=0; x < (ssize_t) image->columns; x++)
2869 SetIndexPixelComponent(indexes+x,index);
2871 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2874 image_view=DestroyCacheView(image_view);
2879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2883 % S e t I m a g e C h a n n e l s %
2887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2889 % SetImageChannels() sets the number of pixels channels associated with the
2892 % The format of the SetImageChannels method is:
2894 % MagickBooleanType SetImageChannels(Image *image,const size_t channels)
2896 % A description of each parameter follows:
2898 % o image: the image.
2900 % o channels: The number of pixel channels.
2903 MagickExport MagickBooleanType SetImageChannels(Image *image,
2904 const size_t channels)
2906 image->channels=channels;
2911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2915 % S e t I m a g e C o l o r %
2919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2921 % SetImageColor() set the entire image canvas to the specified color.
2923 % The format of the SetImageColor method is:
2925 % MagickBooleanType SetImageColor(Image *image,
2926 % const MagickPixelPacket *color)
2928 % A description of each parameter follows:
2930 % o image: the image.
2932 % o background: the image color.
2935 MagickExport MagickBooleanType SetImageColor(Image *image,
2936 const MagickPixelPacket *color)
2950 assert(image != (Image *) NULL);
2951 if (image->debug != MagickFalse)
2952 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2953 assert(image->signature == MagickSignature);
2954 assert(color != (const MagickPixelPacket *) NULL);
2955 image->colorspace=color->colorspace;
2956 image->matte=color->matte;
2957 image->fuzz=color->fuzz;
2958 image->depth=color->depth;
2960 exception=(&image->exception);
2961 image_view=AcquireCacheView(image);
2962 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2963 #pragma omp parallel for schedule(dynamic,4) shared(status)
2965 for (y=0; y < (ssize_t) image->rows; y++)
2967 register IndexPacket
2970 register PixelPacket
2976 if (status == MagickFalse)
2978 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2979 if (q == (PixelPacket *) NULL)
2984 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2985 for (x=0; x < (ssize_t) image->columns; x++)
2987 SetPixelPacket(image,color,q,indexes+x);
2990 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2993 image_view=DestroyCacheView(image_view);
2998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3002 % S e t I m a g e S t o r a g e C l a s s %
3006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3008 % SetImageStorageClass() sets the image class: DirectClass for true color
3009 % images or PseudoClass for colormapped images.
3011 % The format of the SetImageStorageClass method is:
3013 % MagickBooleanType SetImageStorageClass(Image *image,
3014 % const ClassType storage_class)
3016 % A description of each parameter follows:
3018 % o image: the image.
3020 % o storage_class: The image class.
3023 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
3024 const ClassType storage_class)
3026 image->storage_class=storage_class;
3031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3035 % S e t I m a g e C l i p M a s k %
3039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3041 % SetImageClipMask() associates a clip path with the image. The clip path
3042 % must be the same dimensions as the image. Set any pixel component of
3043 % the clip path to TransparentOpacity to prevent that corresponding image
3044 % pixel component from being updated when SyncAuthenticPixels() is applied.
3046 % The format of the SetImageClipMask method is:
3048 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
3050 % A description of each parameter follows:
3052 % o image: the image.
3054 % o clip_mask: the image clip path.
3057 MagickExport MagickBooleanType SetImageClipMask(Image *image,
3058 const Image *clip_mask)
3060 assert(image != (Image *) NULL);
3061 if (image->debug != MagickFalse)
3062 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3063 assert(image->signature == MagickSignature);
3064 if (clip_mask != (const Image *) NULL)
3065 if ((clip_mask->columns != image->columns) ||
3066 (clip_mask->rows != image->rows))
3067 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3068 if (image->clip_mask != (Image *) NULL)
3069 image->clip_mask=DestroyImage(image->clip_mask);
3070 image->clip_mask=NewImageList();
3071 if (clip_mask == (Image *) NULL)
3073 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3074 return(MagickFalse);
3075 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
3076 if (image->clip_mask == (Image *) NULL)
3077 return(MagickFalse);
3082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3086 % S e t I m a g e E x t e n t %
3090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3092 % SetImageExtent() sets the image size (i.e. columns & rows).
3094 % The format of the SetImageExtent method is:
3096 % MagickBooleanType SetImageExtent(Image *image,
3097 % const size_t columns,const size_t rows)
3099 % A description of each parameter follows:
3101 % o image: the image.
3103 % o columns: The image width in pixels.
3105 % o rows: The image height in pixels.
3108 MagickExport MagickBooleanType SetImageExtent(Image *image,
3109 const size_t columns,const size_t rows)
3111 if ((columns == 0) || (rows == 0))
3112 return(MagickFalse);
3113 image->columns=columns;
3119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3123 + S e t I m a g e I n f o %
3127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3129 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
3130 % It is set to a type of image format based on the prefix or suffix of the
3131 % filename. For example, `ps:image' returns PS indicating a Postscript image.
3132 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
3133 % precendence over the suffix. Use an optional index enclosed in brackets
3134 % after a file name to specify a desired scene of a multi-resolution image
3135 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
3136 % indicates success.
3138 % The format of the SetImageInfo method is:
3140 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
3141 % const unsigned int frames,ExceptionInfo *exception)
3143 % A description of each parameter follows:
3145 % o image_info: the image info.
3147 % o frames: the number of images you intend to write.
3149 % o exception: return any errors or warnings in this structure.
3152 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
3153 const unsigned int frames,ExceptionInfo *exception)
3156 extension[MaxTextExtent],
3157 filename[MaxTextExtent],
3158 magic[MaxTextExtent],
3160 subimage[MaxTextExtent];
3184 magick[2*MaxTextExtent];
3187 Look for 'image.format' in filename.
3189 assert(image_info != (ImageInfo *) NULL);
3190 assert(image_info->signature == MagickSignature);
3191 if (image_info->debug != MagickFalse)
3192 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3193 image_info->filename);
3197 GetPathComponent(image_info->filename,SubimagePath,subimage);
3198 if (*subimage != '\0')
3201 Look for scene specification (e.g. img0001.pcd[4]).
3203 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3205 if (IsGeometry(subimage) != MagickFalse)
3206 (void) CloneString(&image_info->extract,subimage);
3214 (void) CloneString(&image_info->scenes,subimage);
3215 image_info->scene=StringToUnsignedLong(image_info->scenes);
3216 image_info->number_scenes=image_info->scene;
3217 p=image_info->scenes;
3218 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3220 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3223 first=(size_t) strtol(p,&q,10);
3225 while (isspace((int) ((unsigned char) *q)) != 0)
3228 last=(size_t) strtol(q+1,&q,10);
3231 if (first < image_info->scene)
3232 image_info->scene=first;
3233 if (last > image_info->number_scenes)
3234 image_info->number_scenes=last;
3237 image_info->number_scenes-=image_info->scene-1;
3238 image_info->subimage=image_info->scene;
3239 image_info->subrange=image_info->number_scenes;
3244 GetPathComponent(image_info->filename,ExtensionPath,extension);
3245 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3246 if (*extension != '\0')
3247 if ((LocaleCompare(extension,"gz") == 0) ||
3248 (LocaleCompare(extension,"Z") == 0) ||
3249 (LocaleCompare(extension,"wmz") == 0))
3252 path[MaxTextExtent];
3254 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3255 path[strlen(path)-strlen(extension)-1]='\0';
3256 GetPathComponent(path,ExtensionPath,extension);
3259 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3260 if (*extension != '\0')
3261 if (LocaleCompare(extension,"bz2") == 0)
3264 path[MaxTextExtent];
3266 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3267 path[strlen(path)-strlen(extension)-1]='\0';
3268 GetPathComponent(path,ExtensionPath,extension);
3271 image_info->affirm=MagickFalse;
3272 sans_exception=AcquireExceptionInfo();
3273 if (*extension != '\0')
3282 *format_type_formats[] =
3305 User specified image format.
3307 (void) CopyMagickString(magic,extension,MaxTextExtent);
3310 Look for explicit image formats.
3312 format_type=UndefinedFormatType;
3314 while ((format_type == UndefinedFormatType) &&
3315 (format_type_formats[i] != (char *) NULL))
3317 if ((*magic == *format_type_formats[i]) &&
3318 (LocaleCompare(magic,format_type_formats[i]) == 0))
3319 format_type=ExplicitFormatType;
3322 magick_info=GetMagickInfo(magic,sans_exception);
3323 if ((magick_info != (const MagickInfo *) NULL) &&
3324 (magick_info->format_type != UndefinedFormatType))
3325 format_type=magick_info->format_type;
3326 if (format_type == UndefinedFormatType)
3327 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3329 if (format_type == ExplicitFormatType)
3331 image_info->affirm=MagickTrue;
3332 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3334 if (LocaleCompare(magic,"RGB") == 0)
3335 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3338 Look for explicit 'format:image' in filename.
3341 GetPathComponent(image_info->filename,MagickPath,magic);
3343 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3347 User specified image format.
3350 if (IsMagickConflict(magic) == MagickFalse)
3352 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3353 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3354 image_info->affirm=MagickTrue;
3356 image_info->temporary=MagickTrue;
3359 magick_info=GetMagickInfo(magic,sans_exception);
3360 sans_exception=DestroyExceptionInfo(sans_exception);
3361 if ((magick_info == (const MagickInfo *) NULL) ||
3362 (GetMagickEndianSupport(magick_info) == MagickFalse))
3363 image_info->endian=UndefinedEndian;
3364 GetPathComponent(image_info->filename,CanonicalPath,filename);
3365 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3366 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3369 Test for multiple image support (e.g. image%02d.png).
3371 (void) InterpretImageFilename(image_info,(Image *) NULL,
3372 image_info->filename,(int) image_info->scene,filename);
3373 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3374 (strchr(filename,'%') == (char *) NULL))
3375 image_info->adjoin=MagickFalse;
3377 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3380 Some image formats do not support multiple frames per file.
3382 magick_info=GetMagickInfo(magic,exception);
3383 if (magick_info != (const MagickInfo *) NULL)
3384 if (GetMagickAdjoin(magick_info) == MagickFalse)
3385 image_info->adjoin=MagickFalse;
3387 if (image_info->affirm != MagickFalse)
3392 Determine the image format from the first few bytes of the file.
3394 image=AcquireImage(image_info);
3395 (void) CopyMagickString(image->filename,image_info->filename,
3397 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3398 if (status == MagickFalse)
3400 image=DestroyImage(image);
3401 return(MagickFalse);
3403 if ((IsBlobSeekable(image) == MagickFalse) ||
3404 (IsBlobExempt(image) != MagickFalse))
3407 Copy standard input or pipe to temporary file.
3410 status=ImageToFile(image,filename,exception);
3411 (void) CloseBlob(image);
3412 if (status == MagickFalse)
3414 image=DestroyImage(image);
3415 return(MagickFalse);
3417 SetImageInfoFile(image_info,(FILE *) NULL);
3418 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3419 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3420 if (status == MagickFalse)
3422 image=DestroyImage(image);
3423 return(MagickFalse);
3425 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3426 image_info->temporary=MagickTrue;
3428 (void) ResetMagickMemory(magick,0,sizeof(magick));
3429 count=ReadBlob(image,2*MaxTextExtent,magick);
3430 (void) CloseBlob(image);
3431 image=DestroyImage(image);
3433 Check magic.xml configuration file.
3435 sans_exception=AcquireExceptionInfo();
3436 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3437 if ((magic_info != (const MagicInfo *) NULL) &&
3438 (GetMagicName(magic_info) != (char *) NULL))
3440 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3442 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3443 if ((magick_info == (const MagickInfo *) NULL) ||
3444 (GetMagickEndianSupport(magick_info) == MagickFalse))
3445 image_info->endian=UndefinedEndian;
3446 sans_exception=DestroyExceptionInfo(sans_exception);
3449 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3450 if ((magick_info == (const MagickInfo *) NULL) ||
3451 (GetMagickEndianSupport(magick_info) == MagickFalse))
3452 image_info->endian=UndefinedEndian;
3453 sans_exception=DestroyExceptionInfo(sans_exception);
3459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3463 % S e t I m a g e I n f o B l o b %
3467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3469 % SetImageInfoBlob() sets the image info blob member.
3471 % The format of the SetImageInfoBlob method is:
3473 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3474 % const size_t length)
3476 % A description of each parameter follows:
3478 % o image_info: the image info.
3482 % o length: the blob length.
3485 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3486 const size_t length)
3488 assert(image_info != (ImageInfo *) NULL);
3489 assert(image_info->signature == MagickSignature);
3490 if (image_info->debug != MagickFalse)
3491 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3492 image_info->filename);
3493 image_info->blob=(void *) blob;
3494 image_info->length=length;
3498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3502 % S e t I m a g e I n f o F i l e %
3506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3508 % SetImageInfoFile() sets the image info file member.
3510 % The format of the SetImageInfoFile method is:
3512 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3514 % A description of each parameter follows:
3516 % o image_info: the image info.
3521 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3523 assert(image_info != (ImageInfo *) NULL);
3524 assert(image_info->signature == MagickSignature);
3525 if (image_info->debug != MagickFalse)
3526 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3527 image_info->filename);
3528 image_info->file=file;
3532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3536 % S e t I m a g e M a s k %
3540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3542 % SetImageMask() associates a mask with the image. The mask must be the same
3543 % dimensions as the image.
3545 % The format of the SetImageMask method is:
3547 % MagickBooleanType SetImageMask(Image *image,const Image *mask)
3549 % A description of each parameter follows:
3551 % o image: the image.
3553 % o mask: the image mask.
3556 MagickExport MagickBooleanType SetImageMask(Image *image,
3559 assert(image != (Image *) NULL);
3560 if (image->debug != MagickFalse)
3561 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3562 assert(image->signature == MagickSignature);
3563 if (mask != (const Image *) NULL)
3564 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3565 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3566 if (image->mask != (Image *) NULL)
3567 image->mask=DestroyImage(image->mask);
3568 image->mask=NewImageList();
3569 if (mask == (Image *) NULL)
3571 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3572 return(MagickFalse);
3573 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3574 if (image->mask == (Image *) NULL)
3575 return(MagickFalse);
3580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3584 % S e t I m a g e O p a c i t y %
3588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3590 % SetImageOpacity() sets the opacity levels of the image.
3592 % The format of the SetImageOpacity method is:
3594 % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3596 % A description of each parameter follows:
3598 % o image: the image.
3600 % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3601 % fully transparent.
3604 MagickExport MagickBooleanType SetImageOpacity(Image *image,
3605 const Quantum opacity)
3619 assert(image != (Image *) NULL);
3620 if (image->debug != MagickFalse)
3621 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3622 assert(image->signature == MagickSignature);
3623 image->matte=opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
3625 exception=(&image->exception);
3626 image_view=AcquireCacheView(image);
3627 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3628 #pragma omp parallel for schedule(dynamic,4) shared(status)
3630 for (y=0; y < (ssize_t) image->rows; y++)
3632 register PixelPacket
3638 if (status == MagickFalse)
3640 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3641 if (q == (PixelPacket *) NULL)
3646 for (x=0; x < (ssize_t) image->columns; x++)
3648 SetOpacityPixelComponent(q,opacity);
3651 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3654 image_view=DestroyCacheView(image_view);
3659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3663 % S e t I m a g e T y p e %
3667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3669 % SetImageType() sets the type of image. Choose from these types:
3671 % Bilevel Grayscale GrayscaleMatte
3672 % Palette PaletteMatte TrueColor
3673 % TrueColorMatte ColorSeparation ColorSeparationMatte
3676 % The format of the SetImageType method is:
3678 % MagickBooleanType SetImageType(Image *image,const ImageType type)
3680 % A description of each parameter follows:
3682 % o image: the image.
3684 % o type: Image type.
3687 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3701 assert(image != (Image *) NULL);
3702 if (image->debug != MagickFalse)
3703 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3704 assert(image->signature == MagickSignature);
3706 image_info=AcquireImageInfo();
3707 image_info->dither=image->dither;
3708 artifact=GetImageArtifact(image,"dither");
3709 if (artifact != (const char *) NULL)
3710 (void) SetImageOption(image_info,"dither",artifact);
3715 if (IsGrayImage(image,&image->exception) == MagickFalse)
3716 status=TransformImageColorspace(image,GRAYColorspace);
3717 if (IsMonochromeImage(image,&image->exception) == MagickFalse)
3719 quantize_info=AcquireQuantizeInfo(image_info);
3720 quantize_info->number_colors=2;
3721 quantize_info->colorspace=GRAYColorspace;
3722 status=QuantizeImage(quantize_info,image);
3723 quantize_info=DestroyQuantizeInfo(quantize_info);
3725 image->matte=MagickFalse;
3730 if (IsGrayImage(image,&image->exception) == MagickFalse)
3731 status=TransformImageColorspace(image,GRAYColorspace);
3732 image->matte=MagickFalse;
3735 case GrayscaleMatteType:
3737 if (IsGrayImage(image,&image->exception) == MagickFalse)
3738 status=TransformImageColorspace(image,GRAYColorspace);
3739 if (image->matte == MagickFalse)
3740 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3745 if (image->colorspace != RGBColorspace)
3746 status=TransformImageColorspace(image,RGBColorspace);
3747 if ((image->storage_class == DirectClass) || (image->colors > 256))
3749 quantize_info=AcquireQuantizeInfo(image_info);
3750 quantize_info->number_colors=256;
3751 status=QuantizeImage(quantize_info,image);
3752 quantize_info=DestroyQuantizeInfo(quantize_info);
3754 image->matte=MagickFalse;
3757 case PaletteBilevelMatteType:
3759 if (image->colorspace != RGBColorspace)
3760 status=TransformImageColorspace(image,RGBColorspace);
3761 if (image->matte == MagickFalse)
3762 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3763 (void) BilevelImageChannel(image,AlphaChannel,(double) QuantumRange/2.0);
3764 quantize_info=AcquireQuantizeInfo(image_info);
3765 status=QuantizeImage(quantize_info,image);
3766 quantize_info=DestroyQuantizeInfo(quantize_info);
3769 case PaletteMatteType:
3771 if (image->colorspace != RGBColorspace)
3772 status=TransformImageColorspace(image,RGBColorspace);
3773 if (image->matte == MagickFalse)
3774 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3775 quantize_info=AcquireQuantizeInfo(image_info);
3776 quantize_info->colorspace=TransparentColorspace;
3777 status=QuantizeImage(quantize_info,image);
3778 quantize_info=DestroyQuantizeInfo(quantize_info);
3783 if (image->colorspace != RGBColorspace)
3784 status=TransformImageColorspace(image,RGBColorspace);
3785 if (image->storage_class != DirectClass)
3786 status=SetImageStorageClass(image,DirectClass);
3787 image->matte=MagickFalse;
3790 case TrueColorMatteType:
3792 if (image->colorspace != RGBColorspace)
3793 status=TransformImageColorspace(image,RGBColorspace);
3794 if (image->storage_class != DirectClass)
3795 status=SetImageStorageClass(image,DirectClass);
3796 if (image->matte == MagickFalse)
3797 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3800 case ColorSeparationType:
3802 if (image->colorspace != CMYKColorspace)
3804 if (image->colorspace != RGBColorspace)
3805 status=TransformImageColorspace(image,RGBColorspace);
3806 status=TransformImageColorspace(image,CMYKColorspace);
3808 if (image->storage_class != DirectClass)
3809 status=SetImageStorageClass(image,DirectClass);
3810 image->matte=MagickFalse;
3813 case ColorSeparationMatteType:
3815 if (image->colorspace != CMYKColorspace)
3817 if (image->colorspace != RGBColorspace)
3818 status=TransformImageColorspace(image,RGBColorspace);
3819 status=TransformImageColorspace(image,CMYKColorspace);
3821 if (image->storage_class != DirectClass)
3822 status=SetImageStorageClass(image,DirectClass);
3823 if (image->matte == MagickFalse)
3824 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3832 image_info=DestroyImageInfo(image_info);
3837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3841 % 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 %
3845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3847 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3848 % image and returns the previous setting. A virtual pixel is any pixel access
3849 % that is outside the boundaries of the image cache.
3851 % The format of the SetImageVirtualPixelMethod() method is:
3853 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3854 % const VirtualPixelMethod virtual_pixel_method)
3856 % A description of each parameter follows:
3858 % o image: the image.
3860 % o virtual_pixel_method: choose the type of virtual pixel.
3863 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3864 const VirtualPixelMethod virtual_pixel_method)
3866 assert(image != (const Image *) NULL);
3867 assert(image->signature == MagickSignature);
3868 if (image->debug != MagickFalse)
3869 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3870 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3878 % S m u s h I m a g e s %
3882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3884 % SmushImages() takes all images from the current image pointer to the end
3885 % of the image list and smushes them to each other top-to-bottom if the
3886 % stack parameter is true, otherwise left-to-right.
3888 % The current gravity setting now effects how the image is justified in the
3891 % The format of the SmushImages method is:
3893 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3894 % ExceptionInfo *exception)
3896 % A description of each parameter follows:
3898 % o images: the image sequence.
3900 % o stack: A value other than 0 stacks the images top-to-bottom.
3902 % o offset: minimum distance in pixels between images.
3904 % o exception: return any errors or warnings in this structure.
3908 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3909 const ssize_t offset,ExceptionInfo *exception)
3923 register const PixelPacket
3936 if (images->previous == (Image *) NULL)
3939 SetGeometry(smush_image,&right_geometry);
3940 GravityAdjustGeometry(right_image->columns,right_image->rows,
3941 right_image->gravity,&right_geometry);
3942 left_image=images->previous;
3943 SetGeometry(smush_image,&left_geometry);
3944 GravityAdjustGeometry(left_image->columns,left_image->rows,
3945 left_image->gravity,&left_geometry);
3946 gap=right_image->columns;
3947 left_view=AcquireCacheView(left_image);
3948 right_view=AcquireCacheView(right_image);
3949 for (y=0; y < (ssize_t) smush_image->rows; y++)
3951 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3953 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3954 if ((p == (const PixelPacket *) NULL) ||
3955 (GetOpacityPixelComponent(p) != TransparentOpacity) ||
3956 ((left_image->columns-x-1) >= gap))
3959 i=(ssize_t) left_image->columns-x-1;
3960 for (x=0; x < (ssize_t) right_image->columns; x++)
3962 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3964 if ((p == (const PixelPacket *) NULL) ||
3965 (GetOpacityPixelComponent(p) != TransparentOpacity) || ((x+i) >= (ssize_t) gap))
3968 if ((x+i) < (ssize_t) gap)
3971 right_view=DestroyCacheView(right_view);
3972 left_view=DestroyCacheView(left_view);
3973 if (y < (ssize_t) smush_image->rows)
3975 return((ssize_t) gap-offset);
3978 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3979 const ssize_t offset,ExceptionInfo *exception)
3993 register const PixelPacket
4006 if (images->previous == (Image *) NULL)
4008 bottom_image=images;
4009 SetGeometry(smush_image,&bottom_geometry);
4010 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
4011 bottom_image->gravity,&bottom_geometry);
4012 top_image=images->previous;
4013 SetGeometry(smush_image,&top_geometry);
4014 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
4016 gap=bottom_image->rows;
4017 top_view=AcquireCacheView(top_image);
4018 bottom_view=AcquireCacheView(bottom_image);
4019 for (x=0; x < (ssize_t) smush_image->columns; x++)
4021 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
4023 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
4024 if ((p == (const PixelPacket *) NULL) ||
4025 (GetOpacityPixelComponent(p) != TransparentOpacity) || ((top_image->rows-y-1) >= gap))
4028 i=(ssize_t) top_image->rows-y-1;
4029 for (y=0; y < (ssize_t) bottom_image->rows; y++)
4031 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
4033 if ((p == (const PixelPacket *) NULL) ||
4034 (GetOpacityPixelComponent(p) != TransparentOpacity) || ((y+i) >= (ssize_t) gap))
4037 if ((y+i) < (ssize_t) gap)
4040 bottom_view=DestroyCacheView(bottom_view);
4041 top_view=DestroyCacheView(top_view);
4042 if (x < (ssize_t) smush_image->columns)
4044 return((ssize_t) gap-offset);
4047 MagickExport Image *SmushImages(const Image *images,
4048 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
4050 #define SmushImageTag "Smush/Image"
4072 register const Image
4085 Compute maximum area of smushed area.
4087 assert(images != (Image *) NULL);
4088 assert(images->signature == MagickSignature);
4089 if (images->debug != MagickFalse)
4090 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4091 assert(exception != (ExceptionInfo *) NULL);
4092 assert(exception->signature == MagickSignature);
4096 width=image->columns;
4098 next=GetNextImageInList(image);
4099 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
4101 if (next->matte != MagickFalse)
4104 if (stack != MagickFalse)
4106 if (next->columns > width)
4107 width=next->columns;
4109 if (next->previous != (Image *) NULL)
4113 width+=next->columns;
4114 if (next->previous != (Image *) NULL)
4116 if (next->rows > height)
4122 smush_image=CloneImage(image,width,height,MagickTrue,exception);
4123 if (smush_image == (Image *) NULL)
4124 return((Image *) NULL);
4125 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
4127 InheritException(exception,&smush_image->exception);
4128 smush_image=DestroyImage(smush_image);
4129 return((Image *) NULL);
4131 smush_image->matte=matte;
4132 (void) SetImageBackgroundColor(smush_image);
4136 smush_view=AcquireCacheView(smush_image);
4137 for (n=0; n < (MagickOffsetType) number_images; n++)
4139 SetGeometry(smush_image,&geometry);
4140 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4141 if (stack != MagickFalse)
4143 x_offset-=geometry.x;
4144 y_offset-=SmushYGap(smush_image,image,offset,exception);
4148 x_offset-=SmushXGap(smush_image,image,offset,exception);
4149 y_offset-=geometry.y;
4151 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
4152 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4153 if (proceed == MagickFalse)
4155 if (stack == MagickFalse)
4157 x_offset+=(ssize_t) image->columns;
4163 y_offset+=(ssize_t) image->rows;
4165 image=GetNextImageInList(image);
4167 if (stack == MagickFalse)
4168 smush_image->columns=(size_t) x_offset;
4170 smush_image->rows=(size_t) y_offset;
4171 smush_view=DestroyCacheView(smush_view);
4172 if (status == MagickFalse)
4173 smush_image=DestroyImage(smush_image);
4174 return(smush_image);
4178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4182 % S t r i p I m a g e %
4186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4188 % StripImage() strips an image of all profiles and comments.
4190 % The format of the StripImage method is:
4192 % MagickBooleanType StripImage(Image *image)
4194 % A description of each parameter follows:
4196 % o image: the image.
4199 MagickExport MagickBooleanType StripImage(Image *image)
4201 assert(image != (Image *) NULL);
4202 if (image->debug != MagickFalse)
4203 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4204 DestroyImageProfiles(image);
4205 (void) DeleteImageProperty(image,"comment");
4206 (void) DeleteImageProperty(image,"date:create");
4207 (void) DeleteImageProperty(image,"date:modify");
4208 (void) SetImageArtifact(image,"png:include-chunk","none,gama");
4213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4217 + S y n c I m a g e %
4221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4223 % SyncImage() initializes the red, green, and blue intensities of each pixel
4224 % as defined by the colormap index.
4226 % The format of the SyncImage method is:
4228 % MagickBooleanType SyncImage(Image *image)
4230 % A description of each parameter follows:
4232 % o image: the image.
4236 static inline IndexPacket PushColormapIndex(Image *image,
4237 const size_t index,MagickBooleanType *range_exception)
4239 if (index < image->colors)
4240 return((IndexPacket) index);
4241 *range_exception=MagickTrue;
4242 return((IndexPacket) 0);
4245 MagickExport MagickBooleanType SyncImage(Image *image)
4260 assert(image != (Image *) NULL);
4261 if (image->debug != MagickFalse)
4262 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4263 assert(image->signature == MagickSignature);
4264 if (image->storage_class == DirectClass)
4265 return(MagickFalse);
4266 range_exception=MagickFalse;
4268 exception=(&image->exception);
4269 image_view=AcquireCacheView(image);
4270 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4271 #pragma omp parallel for schedule(dynamic,4) shared(status)
4273 for (y=0; y < (ssize_t) image->rows; y++)
4278 register IndexPacket
4281 register PixelPacket
4287 if (status == MagickFalse)
4289 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4290 if (q == (PixelPacket *) NULL)
4295 indexes=GetCacheViewAuthenticIndexQueue(image_view);
4296 for (x=0; x < (ssize_t) image->columns; x++)
4298 index=PushColormapIndex(image,(size_t) GetIndexPixelComponent(indexes+x),
4300 if (image->matte == MagickFalse)
4301 SetRGBPixelComponents(q,image->colormap+(ssize_t) index)
4303 SetRGBOPixelComponents(q,image->colormap+(ssize_t) index);
4306 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4309 image_view=DestroyCacheView(image_view);
4310 if (range_exception != MagickFalse)
4311 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4312 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4321 % S y n c I m a g e S e t t i n g s %
4325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4327 % SyncImageSettings() sync the image info options to the image.
4329 % The format of the SyncImageSettings method is:
4331 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4333 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4336 % A description of each parameter follows:
4338 % o image_info: the image info.
4340 % o image: the image.
4344 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4350 assert(image_info != (const ImageInfo *) NULL);
4351 assert(image_info->signature == MagickSignature);
4352 assert(images != (Image *) NULL);
4353 assert(images->signature == MagickSignature);
4354 if (images->debug != MagickFalse)
4355 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4357 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4358 (void) SyncImageSettings(image_info,image);
4359 (void) DeleteImageOption(image_info,"page");
4363 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4367 property[MaxTextExtent];
4385 assert(image_info != (const ImageInfo *) NULL);
4386 assert(image_info->signature == MagickSignature);
4387 assert(image != (Image *) NULL);
4388 assert(image->signature == MagickSignature);
4389 if (image->debug != MagickFalse)
4390 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4391 option=GetImageOption(image_info,"background");
4392 if (option != (const char *) NULL)
4393 (void) QueryColorDatabase(option,&image->background_color,
4395 option=GetImageOption(image_info,"bias");
4396 if (option != (const char *) NULL)
4397 image->bias=SiPrefixToDouble(option,QuantumRange);
4398 option=GetImageOption(image_info,"black-point-compensation");
4399 if (option != (const char *) NULL)
4400 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4401 MagickBooleanOptions,MagickFalse,option);
4402 option=GetImageOption(image_info,"blue-primary");
4403 if (option != (const char *) NULL)
4405 flags=ParseGeometry(option,&geometry_info);
4406 image->chromaticity.blue_primary.x=geometry_info.rho;
4407 image->chromaticity.blue_primary.y=geometry_info.sigma;
4408 if ((flags & SigmaValue) == 0)
4409 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4411 option=GetImageOption(image_info,"bordercolor");
4412 if (option != (const char *) NULL)
4413 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4414 option=GetImageOption(image_info,"colors");
4415 if (option != (const char *) NULL)
4416 image->colors=StringToUnsignedLong(option);
4417 option=GetImageOption(image_info,"compose");
4418 if (option != (const char *) NULL)
4419 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4420 MagickFalse,option);
4421 option=GetImageOption(image_info,"compress");
4422 if (option != (const char *) NULL)
4423 image->compression=(CompressionType) ParseCommandOption(
4424 MagickCompressOptions,MagickFalse,option);
4425 option=GetImageOption(image_info,"debug");
4426 if (option != (const char *) NULL)
4427 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4428 MagickFalse,option);
4429 option=GetImageOption(image_info,"density");
4430 if (option != (const char *) NULL)
4438 flags=ParseGeometry(option,&geometry_info);
4439 image->x_resolution=geometry_info.rho;
4440 image->y_resolution=geometry_info.sigma;
4441 if ((flags & SigmaValue) == 0)
4442 image->y_resolution=image->x_resolution;
4444 option=GetImageOption(image_info,"depth");
4445 if (option != (const char *) NULL)
4446 image->depth=StringToUnsignedLong(option);
4447 option=GetImageOption(image_info,"endian");
4448 if (option != (const char *) NULL)
4449 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4450 MagickFalse,option);
4451 option=GetImageOption(image_info,"filter");
4452 if (option != (const char *) NULL)
4453 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4454 MagickFalse,option);
4455 option=GetImageOption(image_info,"fuzz");
4456 if (option != (const char *) NULL)
4457 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4458 option=GetImageOption(image_info,"gravity");
4459 if (option != (const char *) NULL)
4460 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4461 MagickFalse,option);
4462 option=GetImageOption(image_info,"green-primary");
4463 if (option != (const char *) NULL)
4465 flags=ParseGeometry(option,&geometry_info);
4466 image->chromaticity.green_primary.x=geometry_info.rho;
4467 image->chromaticity.green_primary.y=geometry_info.sigma;
4468 if ((flags & SigmaValue) == 0)
4469 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4471 option=GetImageOption(image_info,"intent");
4472 if (option != (const char *) NULL)
4473 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4474 MagickIntentOptions,MagickFalse,option);
4475 option=GetImageOption(image_info,"interlace");
4476 if (option != (const char *) NULL)
4477 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4478 MagickFalse,option);
4479 option=GetImageOption(image_info,"interpolate");
4480 if (option != (const char *) NULL)
4481 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
4482 MagickInterpolateOptions,MagickFalse,option);
4483 option=GetImageOption(image_info,"loop");
4484 if (option != (const char *) NULL)
4485 image->iterations=StringToUnsignedLong(option);
4486 option=GetImageOption(image_info,"mattecolor");
4487 if (option != (const char *) NULL)
4488 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4489 option=GetImageOption(image_info,"orient");
4490 if (option != (const char *) NULL)
4491 image->orientation=(OrientationType) ParseCommandOption(
4492 MagickOrientationOptions,MagickFalse,option);
4493 option=GetImageOption(image_info,"page");
4494 if (option != (const char *) NULL)
4499 geometry=GetPageGeometry(option);
4500 flags=ParseAbsoluteGeometry(geometry,&image->page);
4501 geometry=DestroyString(geometry);
4503 option=GetImageOption(image_info,"quality");
4504 if (option != (const char *) NULL)
4505 image->quality=StringToUnsignedLong(option);
4506 option=GetImageOption(image_info,"red-primary");
4507 if (option != (const char *) NULL)
4509 flags=ParseGeometry(option,&geometry_info);
4510 image->chromaticity.red_primary.x=geometry_info.rho;
4511 image->chromaticity.red_primary.y=geometry_info.sigma;
4512 if ((flags & SigmaValue) == 0)
4513 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4515 if (image_info->quality != UndefinedCompressionQuality)
4516 image->quality=image_info->quality;
4517 option=GetImageOption(image_info,"scene");
4518 if (option != (const char *) NULL)
4519 image->scene=StringToUnsignedLong(option);
4520 option=GetImageOption(image_info,"taint");
4521 if (option != (const char *) NULL)
4522 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4523 MagickFalse,option);
4524 option=GetImageOption(image_info,"tile-offset");
4525 if (option != (const char *) NULL)
4530 geometry=GetPageGeometry(option);
4531 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4532 geometry=DestroyString(geometry);
4534 option=GetImageOption(image_info,"transparent-color");
4535 if (option != (const char *) NULL)
4536 (void) QueryColorDatabase(option,&image->transparent_color,
4538 option=GetImageOption(image_info,"type");
4539 if (option != (const char *) NULL)
4540 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4542 option=GetImageOption(image_info,"units");
4543 if (option != (const char *) NULL)
4544 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4545 MagickFalse,option);
4547 units = image_info->units;
4548 if (units != UndefinedResolution)
4550 if (image->units != units)
4551 switch (image->units)
4553 case PixelsPerInchResolution:
4555 if (units == PixelsPerCentimeterResolution)
4557 image->x_resolution/=2.54;
4558 image->y_resolution/=2.54;
4562 case PixelsPerCentimeterResolution:
4564 if (units == PixelsPerInchResolution)
4566 image->x_resolution=(double) ((size_t) (100.0*2.54*
4567 image->x_resolution+0.5))/100.0;
4568 image->y_resolution=(double) ((size_t) (100.0*2.54*
4569 image->y_resolution+0.5))/100.0;
4578 option=GetImageOption(image_info,"white-point");
4579 if (option != (const char *) NULL)
4581 flags=ParseGeometry(option,&geometry_info);
4582 image->chromaticity.white_point.x=geometry_info.rho;
4583 image->chromaticity.white_point.y=geometry_info.sigma;
4584 if ((flags & SigmaValue) == 0)
4585 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4587 ResetImageOptionIterator(image_info);
4588 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4590 value=GetImageOption(image_info,option);
4591 if (value != (const char *) NULL)
4593 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4594 (void) SetImageArtifact(image,property,value);
4596 option=GetNextImageOption(image_info);