2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII M M AAA GGGG EEEEE %
8 % I M M M AAAAA G GG EEE %
10 % IIIII M M A A GGGG EEEEE %
13 % MagickCore Image Methods %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/resource_.h"
87 #include "MagickCore/segment.h"
88 #include "MagickCore/semaphore.h"
89 #include "MagickCore/signature-private.h"
90 #include "MagickCore/statistic.h"
91 #include "MagickCore/string_.h"
92 #include "MagickCore/string-private.h"
93 #include "MagickCore/thread-private.h"
94 #include "MagickCore/threshold.h"
95 #include "MagickCore/timer.h"
96 #include "MagickCore/token.h"
97 #include "MagickCore/utility.h"
98 #include "MagickCore/utility-private.h"
99 #include "MagickCore/version.h"
100 #include "MagickCore/xwindow-private.h"
103 Constant declaration.
106 BackgroundColor[] = "#ffffff", /* white */
107 BorderColor[] = "#dfdfdf", /* gray */
108 DefaultTileFrame[] = "15x15+3+3",
109 DefaultTileGeometry[] = "120x120+4+3>",
110 DefaultTileLabel[] = "%f\n%G\n%b",
111 ForegroundColor[] = "#000", /* black */
112 LoadImageTag[] = "Load/Image",
113 LoadImagesTag[] = "Load/Images",
114 MatteColor[] = "#bdbdbd", /* gray */
115 PSDensityGeometry[] = "72.0x72.0",
116 PSPageGeometry[] = "612x792",
117 SaveImageTag[] = "Save/Image",
118 SaveImagesTag[] = "Save/Images",
119 TransparentColor[] = "#00000000"; /* transparent black */
122 DefaultResolution = 72.0;
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % A c q u i r e I m a g e %
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % AcquireImage() returns a pointer to an image structure initialized to
138 % The format of the AcquireImage method is:
140 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
142 % A description of each parameter follows:
144 % o image_info: Many of the image default values are set from this
145 % structure. For example, filename, compression, depth, background color,
148 % o exception: return any errors or warnings in this structure.
151 MagickExport Image *AcquireImage(const ImageInfo *image_info,
152 ExceptionInfo *exception)
164 Allocate image structure.
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
167 image=(Image *) AcquireMagickMemory(sizeof(*image));
168 if (image == (Image *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(image,0,sizeof(*image));
172 Initialize Image structure.
174 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
175 image->storage_class=DirectClass;
176 image->depth=MAGICKCORE_QUANTUM_DEPTH;
177 image->colorspace=sRGBColorspace;
178 image->rendering_intent=PerceptualIntent;
179 image->gamma=1.000f/2.200f;
180 image->chromaticity.red_primary.x=0.6400f;
181 image->chromaticity.red_primary.y=0.3300f;
182 image->chromaticity.red_primary.z=0.0300f;
183 image->chromaticity.green_primary.x=0.3000f;
184 image->chromaticity.green_primary.y=0.6000f;
185 image->chromaticity.green_primary.z=0.1000f;
186 image->chromaticity.blue_primary.x=0.1500f;
187 image->chromaticity.blue_primary.y=0.0600f;
188 image->chromaticity.blue_primary.z=0.7900f;
189 image->chromaticity.white_point.x=0.3127f;
190 image->chromaticity.white_point.y=0.3290f;
191 image->chromaticity.white_point.z=0.3583f;
192 image->interlace=NoInterlace;
193 image->ticks_per_second=UndefinedTicksPerSecond;
194 image->compose=OverCompositeOp;
195 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
196 &image->background_color,exception);
197 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
199 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
201 (void) QueryColorCompliance(TransparentColor,AllCompliance,
202 &image->transparent_color,exception);
203 GetTimerInfo(&image->timer);
204 image->cache=AcquirePixelCache(0);
205 image->channel_mask=DefaultChannels;
206 image->channel_map=AcquirePixelChannelMap();
207 image->blob=CloneBlobInfo((BlobInfo *) NULL);
208 image->debug=IsEventLogging();
209 image->reference_count=1;
210 image->semaphore=AllocateSemaphoreInfo();
211 image->signature=MagickSignature;
212 if (image_info == (ImageInfo *) NULL)
217 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
219 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
220 (void) CopyMagickString(image->magick_filename,image_info->filename,
222 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
223 if (image_info->size != (char *) NULL)
225 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
226 image->columns=image->extract_info.width;
227 image->rows=image->extract_info.height;
228 image->offset=image->extract_info.x;
229 image->extract_info.x=0;
230 image->extract_info.y=0;
232 if (image_info->extract != (char *) NULL)
237 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
238 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
240 image->extract_info=geometry;
241 Swap(image->columns,image->extract_info.width);
242 Swap(image->rows,image->extract_info.height);
245 image->compression=image_info->compression;
246 image->quality=image_info->quality;
247 image->endian=image_info->endian;
248 image->interlace=image_info->interlace;
249 image->units=image_info->units;
250 if (image_info->density != (char *) NULL)
255 flags=ParseGeometry(image_info->density,&geometry_info);
256 image->resolution.x=geometry_info.rho;
257 image->resolution.y=geometry_info.sigma;
258 if ((flags & SigmaValue) == 0)
259 image->resolution.y=image->resolution.x;
261 if (image_info->page != (char *) NULL)
266 image->page=image->extract_info;
267 geometry=GetPageGeometry(image_info->page);
268 (void) ParseAbsoluteGeometry(geometry,&image->page);
269 geometry=DestroyString(geometry);
271 if (image_info->depth != 0)
272 image->depth=image_info->depth;
273 image->dither=image_info->dither;
274 image->background_color=image_info->background_color;
275 image->border_color=image_info->border_color;
276 image->matte_color=image_info->matte_color;
277 image->transparent_color=image_info->transparent_color;
278 image->ping=image_info->ping;
279 image->progress_monitor=image_info->progress_monitor;
280 image->client_data=image_info->client_data;
281 if (image_info->cache != (void *) NULL)
282 ClonePixelCacheMethods(image->cache,image_info->cache);
283 (void) SyncImageSettings(image_info,image,exception);
284 option=GetImageOption(image_info,"delay");
285 if (option != (const char *) NULL)
290 flags=ParseGeometry(option,&geometry_info);
291 if ((flags & GreaterValue) != 0)
293 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
294 image->delay=(size_t) floor(geometry_info.rho+0.5);
297 if ((flags & LessValue) != 0)
299 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
300 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
303 image->delay=(size_t) floor(geometry_info.rho+0.5);
304 if ((flags & SigmaValue) != 0)
305 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
307 option=GetImageOption(image_info,"dispose");
308 if (option != (const char *) NULL)
309 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 % A c q u i r e I m a g e I n f o %
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 % AcquireImageInfo() allocates the ImageInfo structure.
327 % The format of the AcquireImageInfo method is:
329 % ImageInfo *AcquireImageInfo(void)
332 MagickExport ImageInfo *AcquireImageInfo(void)
337 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
338 if (image_info == (ImageInfo *) NULL)
339 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
340 GetImageInfo(image_info);
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349 % A c q u i r e N e x t I m a g e %
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
355 % AcquireNextImage() initializes the next image in a sequence to
356 % default values. The next member of image points to the newly allocated
357 % image. If there is a memory shortage, next is assigned NULL.
359 % The format of the AcquireNextImage method is:
361 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
362 % ExceptionInfo *exception)
364 % A description of each parameter follows:
366 % o image_info: Many of the image default values are set from this
367 % structure. For example, filename, compression, depth, background color,
370 % o image: the image.
372 % o exception: return any errors or warnings in this structure.
375 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
376 ExceptionInfo *exception)
379 Allocate image structure.
381 assert(image != (Image *) NULL);
382 assert(image->signature == MagickSignature);
383 if (image->debug != MagickFalse)
384 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
385 image->next=AcquireImage(image_info,exception);
386 if (GetNextImageInList(image) == (Image *) NULL)
388 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
390 if (image_info != (ImageInfo *) NULL)
391 (void) CopyMagickString(GetNextImageInList(image)->filename,
392 image_info->filename,MaxTextExtent);
393 DestroyBlob(GetNextImageInList(image));
394 image->next->blob=ReferenceBlob(image->blob);
395 image->next->endian=image->endian;
396 image->next->scene=image->scene+1;
397 image->next->previous=image;
401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405 % A p p e n d I m a g e s %
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 % AppendImages() takes all images from the current image pointer to the end
412 % of the image list and appends them to each other top-to-bottom if the
413 % stack parameter is true, otherwise left-to-right.
415 % The current gravity setting effects how the image is justified in the
418 % The format of the AppendImages method is:
420 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
421 % ExceptionInfo *exception)
423 % A description of each parameter follows:
425 % o images: the image sequence.
427 % o stack: A value other than 0 stacks the images top-to-bottom.
429 % o exception: return any errors or warnings in this structure.
432 MagickExport Image *AppendImages(const Image *images,
433 const MagickBooleanType stack,ExceptionInfo *exception)
435 #define AppendImageTag "Append/Image"
468 Compute maximum area of appended area.
470 assert(images != (Image *) NULL);
471 assert(images->signature == MagickSignature);
472 if (images->debug != MagickFalse)
473 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
474 assert(exception != (ExceptionInfo *) NULL);
475 assert(exception->signature == MagickSignature);
478 width=images->columns;
480 next=GetNextImageInList(images);
481 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
483 if (next->matte != MagickFalse)
486 if (stack != MagickFalse)
488 if (next->columns > width)
493 width+=next->columns;
494 if (next->rows > height)
500 append_image=CloneImage(images,width,height,MagickTrue,exception);
501 if (append_image == (Image *) NULL)
502 return((Image *) NULL);
503 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
505 append_image=DestroyImage(append_image);
506 return((Image *) NULL);
508 append_image->matte=matte;
509 (void) SetImageBackgroundColor(append_image,exception);
514 append_view=AcquireAuthenticCacheView(append_image,exception);
515 for (n=0; n < (MagickOffsetType) number_images; n++)
523 image=CloneImage(next,0,0,MagickTrue,exception);
524 if (image == (Image *) NULL)
526 (void) TransformImageColorspace(image,append_image->colorspace,exception);
527 SetGeometry(append_image,&geometry);
528 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
529 if (stack != MagickFalse)
530 x_offset-=geometry.x;
532 y_offset-=geometry.y;
533 image_view=AcquireVirtualCacheView(image,exception);
534 #if defined(MAGICKCORE_OPENMP_SUPPORT)
535 #pragma omp parallel for schedule(static) shared(status) \
536 dynamic_number_threads(image,image->columns,image->rows,1)
538 for (y=0; y < (ssize_t) image->rows; y++)
546 register const Quantum
555 if (status == MagickFalse)
557 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
558 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
559 image->columns,1,exception);
560 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
565 GetPixelInfo(image,&pixel);
566 for (x=0; x < (ssize_t) image->columns; x++)
568 if (GetPixelMask(image,p) != 0)
570 p+=GetPixelChannels(image);
571 q+=GetPixelChannels(append_image);
574 GetPixelInfoPixel(image,p,&pixel);
575 SetPixelInfoPixel(append_image,&pixel,q);
576 p+=GetPixelChannels(image);
577 q+=GetPixelChannels(append_image);
579 sync=SyncCacheViewAuthenticPixels(append_view,exception);
580 if (sync == MagickFalse)
583 image_view=DestroyCacheView(image_view);
584 if (stack == MagickFalse)
586 x_offset+=(ssize_t) image->columns;
592 y_offset+=(ssize_t) image->rows;
594 image=DestroyImage(image);
595 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
596 if (proceed == MagickFalse)
598 next=GetNextImageInList(next);
600 append_view=DestroyCacheView(append_view);
601 if (status == MagickFalse)
602 append_image=DestroyImage(append_image);
603 return(append_image);
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
611 % C a t c h I m a g e E x c e p t i o n %
615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 % CatchImageException() returns if no exceptions are found in the image
618 % sequence, otherwise it determines the most severe exception and reports
619 % it as a warning or error depending on the severity.
621 % The format of the CatchImageException method is:
623 % ExceptionType CatchImageException(Image *image)
625 % A description of each parameter follows:
627 % o image: An image sequence.
630 MagickExport ExceptionType CatchImageException(Image *image)
638 assert(image != (const Image *) NULL);
639 assert(image->signature == MagickSignature);
640 if (image->debug != MagickFalse)
641 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
642 exception=AcquireExceptionInfo();
643 CatchException(exception);
644 severity=exception->severity;
645 exception=DestroyExceptionInfo(exception);
650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % C l i p I m a g e P a t h %
658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660 % ClipImagePath() sets the image clip mask based any clipping path information
663 % The format of the ClipImagePath method is:
665 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
666 % const MagickBooleanType inside,ExceptionInfo *exception)
668 % A description of each parameter follows:
670 % o image: the image.
672 % o pathname: name of clipping path resource. If name is preceded by #, use
673 % clipping path numbered by name.
675 % o inside: if non-zero, later operations take effect inside clipping path.
676 % Otherwise later operations take effect outside clipping path.
678 % o exception: return any errors or warnings in this structure.
682 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
684 return(ClipImagePath(image,"#1",MagickTrue,exception));
687 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
688 const MagickBooleanType inside,ExceptionInfo *exception)
690 #define ClipImagePathTag "ClipPath/Image"
704 assert(image != (const Image *) NULL);
705 assert(image->signature == MagickSignature);
706 if (image->debug != MagickFalse)
707 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
708 assert(pathname != NULL);
709 property=AcquireString(pathname);
710 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
712 value=GetImageProperty(image,property,exception);
713 property=DestroyString(property);
714 if (value == (const char *) NULL)
716 ThrowFileException(exception,OptionError,"NoClipPathDefined",
720 image_info=AcquireImageInfo();
721 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
722 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
723 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
724 image_info=DestroyImageInfo(image_info);
725 if (clip_mask == (Image *) NULL)
727 if (clip_mask->storage_class == PseudoClass)
729 (void) SyncImage(clip_mask,exception);
730 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
733 if (inside == MagickFalse)
734 (void) NegateImage(clip_mask,MagickFalse,exception);
735 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
736 "8BIM:1999,2998:%s\nPS",pathname);
737 (void) SetImageMask(image,clip_mask,exception);
738 clip_mask=DestroyImage(clip_mask);
743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
747 % C l o n e I m a g e %
751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 % CloneImage() copies an image and returns the copy as a new image object.
755 % If the specified columns and rows is 0, an exact copy of the image is
756 % returned, otherwise the pixel data is undefined and must be initialized
757 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
758 % failure, a NULL image is returned and exception describes the reason for the
761 % The format of the CloneImage method is:
763 % Image *CloneImage(const Image *image,const size_t columns,
764 % const size_t rows,const MagickBooleanType orphan,
765 % ExceptionInfo *exception)
767 % A description of each parameter follows:
769 % o image: the image.
771 % o columns: the number of columns in the cloned image.
773 % o rows: the number of rows in the cloned image.
775 % o detach: With a value other than 0, the cloned image is detached from
776 % its parent I/O stream.
778 % o exception: return any errors or warnings in this structure.
781 MagickExport Image *CloneImage(const Image *image,const size_t columns,
782 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
796 assert(image != (const Image *) NULL);
797 assert(image->signature == MagickSignature);
798 if (image->debug != MagickFalse)
799 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
800 assert(exception != (ExceptionInfo *) NULL);
801 assert(exception->signature == MagickSignature);
802 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
803 if (clone_image == (Image *) NULL)
804 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
805 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
806 clone_image->signature=MagickSignature;
807 clone_image->storage_class=image->storage_class;
808 clone_image->number_channels=image->number_channels;
809 clone_image->number_meta_channels=image->number_meta_channels;
810 clone_image->metacontent_extent=image->metacontent_extent;
811 clone_image->colorspace=image->colorspace;
812 clone_image->mask=image->mask;
813 clone_image->matte=image->matte;
814 clone_image->columns=image->columns;
815 clone_image->rows=image->rows;
816 clone_image->dither=image->dither;
817 if (image->colormap != (PixelInfo *) NULL)
820 Allocate and copy the image colormap.
822 clone_image->colors=image->colors;
823 length=(size_t) image->colors;
824 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
825 sizeof(*clone_image->colormap));
826 if (clone_image->colormap == (PixelInfo *) NULL)
827 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
828 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
829 sizeof(*clone_image->colormap));
831 (void) CloneImageProfiles(clone_image,image);
832 (void) CloneImageProperties(clone_image,image);
833 (void) CloneImageArtifacts(clone_image,image);
834 GetTimerInfo(&clone_image->timer);
835 if (image->ascii85 != (void *) NULL)
836 Ascii85Initialize(clone_image);
837 clone_image->magick_columns=image->magick_columns;
838 clone_image->magick_rows=image->magick_rows;
839 clone_image->type=image->type;
840 clone_image->channel_mask=image->channel_mask;
841 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
842 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
844 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
845 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
846 clone_image->progress_monitor=image->progress_monitor;
847 clone_image->client_data=image->client_data;
848 clone_image->reference_count=1;
849 clone_image->next=image->next;
850 clone_image->previous=image->previous;
851 clone_image->list=NewImageList();
852 if (detach == MagickFalse)
853 clone_image->blob=ReferenceBlob(image->blob);
856 clone_image->next=NewImageList();
857 clone_image->previous=NewImageList();
858 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
860 clone_image->ping=image->ping;
861 clone_image->debug=IsEventLogging();
862 clone_image->semaphore=AllocateSemaphoreInfo();
863 if ((columns == 0) && (rows == 0))
865 if (image->montage != (char *) NULL)
866 (void) CloneString(&clone_image->montage,image->montage);
867 if (image->directory != (char *) NULL)
868 (void) CloneString(&clone_image->directory,image->directory);
869 clone_image->cache=ReferencePixelCache(image->cache);
872 scale=(double) columns/(double) image->columns;
873 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
874 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
875 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
876 scale=(double) rows/(double) image->rows;
877 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
878 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
879 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
880 clone_image->columns=columns;
881 clone_image->rows=rows;
882 clone_image->cache=ClonePixelCache(image->cache);
887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891 % C l o n e I m a g e I n f o %
895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897 % CloneImageInfo() makes a copy of the given image info structure. If
898 % NULL is specified, a new image info structure is created initialized to
901 % The format of the CloneImageInfo method is:
903 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
905 % A description of each parameter follows:
907 % o image_info: the image info.
910 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
915 clone_info=AcquireImageInfo();
916 if (image_info == (ImageInfo *) NULL)
918 clone_info->compression=image_info->compression;
919 clone_info->temporary=image_info->temporary;
920 clone_info->adjoin=image_info->adjoin;
921 clone_info->antialias=image_info->antialias;
922 clone_info->scene=image_info->scene;
923 clone_info->number_scenes=image_info->number_scenes;
924 clone_info->depth=image_info->depth;
925 (void) CloneString(&clone_info->size,image_info->size);
926 (void) CloneString(&clone_info->extract,image_info->extract);
927 (void) CloneString(&clone_info->scenes,image_info->scenes);
928 (void) CloneString(&clone_info->page,image_info->page);
929 clone_info->interlace=image_info->interlace;
930 clone_info->endian=image_info->endian;
931 clone_info->units=image_info->units;
932 clone_info->quality=image_info->quality;
933 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
934 (void) CloneString(&clone_info->server_name,image_info->server_name);
935 (void) CloneString(&clone_info->font,image_info->font);
936 (void) CloneString(&clone_info->texture,image_info->texture);
937 (void) CloneString(&clone_info->density,image_info->density);
938 clone_info->pointsize=image_info->pointsize;
939 clone_info->fuzz=image_info->fuzz;
940 clone_info->background_color=image_info->background_color;
941 clone_info->border_color=image_info->border_color;
942 clone_info->matte_color=image_info->matte_color;
943 clone_info->transparent_color=image_info->transparent_color;
944 clone_info->dither=image_info->dither;
945 clone_info->monochrome=image_info->monochrome;
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 (void) CloneString(&clone_info->view,image_info->view);
954 clone_info->progress_monitor=image_info->progress_monitor;
955 clone_info->client_data=image_info->client_data;
956 clone_info->cache=image_info->cache;
957 if (image_info->cache != (void *) NULL)
958 clone_info->cache=ReferencePixelCache(image_info->cache);
959 if (image_info->profile != (void *) NULL)
960 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
961 image_info->profile);
962 SetImageInfoFile(clone_info,image_info->file);
963 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
964 clone_info->stream=image_info->stream;
965 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
966 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
967 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
968 (void) CopyMagickString(clone_info->filename,image_info->filename,
970 clone_info->channel=image_info->channel;
971 (void) CloneImageOptions(clone_info,image_info);
972 clone_info->debug=IsEventLogging();
973 clone_info->signature=image_info->signature;
978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
982 % D e s t r o y I m a g e %
986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
988 % DestroyImage() dereferences an image, deallocating memory associated with
989 % the image if the reference count becomes zero.
991 % The format of the DestroyImage method is:
993 % Image *DestroyImage(Image *image)
995 % A description of each parameter follows:
997 % o image: the image.
1000 MagickExport Image *DestroyImage(Image *image)
1008 assert(image != (Image *) NULL);
1009 assert(image->signature == MagickSignature);
1010 if (image->debug != MagickFalse)
1011 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1012 destroy=MagickFalse;
1013 LockSemaphoreInfo(image->semaphore);
1014 image->reference_count--;
1015 if (image->reference_count == 0)
1017 UnlockSemaphoreInfo(image->semaphore);
1018 if (destroy == MagickFalse)
1019 return((Image *) NULL);
1023 DestroyImagePixels(image);
1024 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1025 if (image->montage != (char *) NULL)
1026 image->montage=DestroyString(image->montage);
1027 if (image->directory != (char *) NULL)
1028 image->directory=DestroyString(image->directory);
1029 if (image->colormap != (PixelInfo *) NULL)
1030 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1031 if (image->geometry != (char *) NULL)
1032 image->geometry=DestroyString(image->geometry);
1033 DestroyImageProfiles(image);
1034 DestroyImageProperties(image);
1035 DestroyImageArtifacts(image);
1036 if (image->ascii85 != (Ascii85Info*) NULL)
1037 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1039 if (image->semaphore != (SemaphoreInfo *) NULL)
1040 DestroySemaphoreInfo(&image->semaphore);
1041 image->signature=(~MagickSignature);
1042 image=(Image *) RelinquishMagickMemory(image);
1047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1051 % D e s t r o y I m a g e I n f o %
1055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1057 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1060 % The format of the DestroyImageInfo method is:
1062 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1064 % A description of each parameter follows:
1066 % o image_info: the image info.
1069 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1071 assert(image_info != (ImageInfo *) NULL);
1072 assert(image_info->signature == MagickSignature);
1073 if (image_info->debug != MagickFalse)
1074 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1075 image_info->filename);
1076 if (image_info->size != (char *) NULL)
1077 image_info->size=DestroyString(image_info->size);
1078 if (image_info->extract != (char *) NULL)
1079 image_info->extract=DestroyString(image_info->extract);
1080 if (image_info->scenes != (char *) NULL)
1081 image_info->scenes=DestroyString(image_info->scenes);
1082 if (image_info->page != (char *) NULL)
1083 image_info->page=DestroyString(image_info->page);
1084 if (image_info->sampling_factor != (char *) NULL)
1085 image_info->sampling_factor=DestroyString(
1086 image_info->sampling_factor);
1087 if (image_info->server_name != (char *) NULL)
1088 image_info->server_name=DestroyString(
1089 image_info->server_name);
1090 if (image_info->font != (char *) NULL)
1091 image_info->font=DestroyString(image_info->font);
1092 if (image_info->texture != (char *) NULL)
1093 image_info->texture=DestroyString(image_info->texture);
1094 if (image_info->density != (char *) NULL)
1095 image_info->density=DestroyString(image_info->density);
1096 if (image_info->view != (char *) NULL)
1097 image_info->view=DestroyString(image_info->view);
1098 if (image_info->cache != (void *) NULL)
1099 image_info->cache=DestroyPixelCache(image_info->cache);
1100 if (image_info->profile != (StringInfo *) NULL)
1101 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1102 image_info->profile);
1103 DestroyImageOptions(image_info);
1104 image_info->signature=(~MagickSignature);
1105 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1114 + D i s a s s o c i a t e I m a g e S t r e a m %
1118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1120 % DisassociateImageStream() disassociates the image stream.
1122 % The format of the DisassociateImageStream method is:
1124 % MagickBooleanType DisassociateImageStream(const Image *image)
1126 % A description of each parameter follows:
1128 % o image: the image.
1131 MagickExport void DisassociateImageStream(Image *image)
1133 assert(image != (const Image *) NULL);
1134 assert(image->signature == MagickSignature);
1135 if (image->debug != MagickFalse)
1136 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1137 (void) DetachBlob(image->blob);
1141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1145 % G e t I m a g e A l p h a C h a n n e l %
1149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1151 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1152 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1155 % The format of the GetImageAlphaChannel method is:
1157 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1159 % A description of each parameter follows:
1161 % o image: the image.
1164 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1166 assert(image != (const Image *) NULL);
1167 if (image->debug != MagickFalse)
1168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1169 assert(image->signature == MagickSignature);
1170 return(image->matte);
1174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1178 % G e t I m a g e I n f o %
1182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1184 % GetImageInfo() initializes image_info to default values.
1186 % The format of the GetImageInfo method is:
1188 % void GetImageInfo(ImageInfo *image_info)
1190 % A description of each parameter follows:
1192 % o image_info: the image info.
1195 MagickExport void GetImageInfo(ImageInfo *image_info)
1201 File and image dimension members.
1203 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1204 assert(image_info != (ImageInfo *) NULL);
1205 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1206 image_info->adjoin=MagickTrue;
1207 image_info->interlace=NoInterlace;
1208 image_info->channel=DefaultChannels;
1209 image_info->quality=UndefinedCompressionQuality;
1210 image_info->antialias=MagickTrue;
1211 image_info->dither=MagickTrue;
1212 image_info->synchronize=IsStringTrue(GetEnvironmentValue(
1213 "MAGICK_SYNCHRONIZE"));
1214 exception=AcquireExceptionInfo();
1215 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1216 &image_info->background_color,exception);
1217 (void) QueryColorCompliance(BorderColor,AllCompliance,
1218 &image_info->border_color,exception);
1219 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1221 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1222 &image_info->transparent_color,exception);
1223 exception=DestroyExceptionInfo(exception);
1224 image_info->debug=IsEventLogging();
1225 image_info->signature=MagickSignature;
1229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1233 % G e t I m a g e I n f o F i l e %
1237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1239 % GetImageInfoFile() returns the image info file member.
1241 % The format of the GetImageInfoFile method is:
1243 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1245 % A description of each parameter follows:
1247 % o image_info: the image info.
1250 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1252 return(image_info->file);
1256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1260 % G e t I m a g e M a s k %
1264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1266 % GetImageMask() returns the mask associated with the image.
1268 % The format of the GetImageMask method is:
1270 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1272 % A description of each parameter follows:
1274 % o image: the image.
1277 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1295 assert(image != (Image *) NULL);
1296 if (image->debug != MagickFalse)
1297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1298 assert(image->signature == MagickSignature);
1299 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1300 if (mask_image == (Image *) NULL)
1301 return((Image *) NULL);
1303 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1304 mask_image->mask=MagickFalse;
1305 image_view=AcquireVirtualCacheView(image,exception);
1306 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1307 for (y=0; y < (ssize_t) image->rows; y++)
1309 register const Quantum
1318 if (status == MagickFalse)
1320 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1321 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1323 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1328 for (x=0; x < (ssize_t) image->columns; x++)
1330 SetPixelGray(mask_image,GetPixelMask(image,p),q);
1331 p+=GetPixelChannels(image);
1332 q+=GetPixelChannels(mask_image);
1334 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1337 mask_view=DestroyCacheView(mask_view);
1338 image_view=DestroyCacheView(image_view);
1343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1347 + G e t I m a g e R e f e r e n c e C o u n t %
1351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1353 % GetImageReferenceCount() returns the image reference count.
1355 % The format of the GetReferenceCount method is:
1357 % ssize_t GetImageReferenceCount(Image *image)
1359 % A description of each parameter follows:
1361 % o image: the image.
1364 MagickExport ssize_t GetImageReferenceCount(Image *image)
1369 assert(image != (Image *) NULL);
1370 assert(image->signature == MagickSignature);
1371 if (image->debug != MagickFalse)
1372 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1373 LockSemaphoreInfo(image->semaphore);
1374 reference_count=image->reference_count;
1375 UnlockSemaphoreInfo(image->semaphore);
1376 return(reference_count);
1380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1384 % 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 %
1388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1391 % image. A virtual pixel is any pixel access that is outside the boundaries
1392 % of the image cache.
1394 % The format of the GetImageVirtualPixelMethod() method is:
1396 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1398 % A description of each parameter follows:
1400 % o image: the image.
1403 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1405 assert(image != (Image *) NULL);
1406 assert(image->signature == MagickSignature);
1407 if (image->debug != MagickFalse)
1408 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1409 return(GetPixelCacheVirtualMethod(image));
1413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1417 % I n t e r p r e t I m a g e F i l e n a m e %
1421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1423 % InterpretImageFilename() interprets embedded characters in an image filename.
1424 % The filename length is returned.
1426 % The format of the InterpretImageFilename method is:
1428 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1429 % const char *format,int value,char *filename,ExceptionInfo *exception)
1431 % A description of each parameter follows.
1433 % o image_info: the image info..
1435 % o image: the image.
1437 % o format: A filename describing the format to use to write the numeric
1438 % argument. Only the first numeric format identifier is replaced.
1440 % o value: Numeric value to substitute into format filename.
1442 % o filename: return the formatted filename in this character buffer.
1444 % o exception: return any errors or warnings in this structure.
1447 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1448 Image *image,const char *format,int value,char *filename,
1449 ExceptionInfo *exception)
1466 canonical=MagickFalse;
1468 (void) CopyMagickString(filename,format,MaxTextExtent);
1469 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1482 value=(ssize_t) strtol(q,&q,10);
1494 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1495 (p-format)),p,value);
1497 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1498 canonical=MagickTrue;
1507 pattern[MaxTextExtent];
1524 /* FUTURE: Compare update with code from InterpretImageProperties()
1525 Note that a 'filename:' property should not need depth recursion.
1527 if (strchr(p,']') == (char *) NULL)
1531 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1542 if (LocaleNCompare(pattern,"filename:",9) != 0)
1544 value=(const char *) NULL;
1546 // FUTURE: remove this code. -- Anthony 29 Arpil 2012
1547 // Removed as GetMagickProperty() will will never match a "filename:"
1548 // string as this is not a 'known' image property.
1550 if ((image_info != (const ImageInfo *) NULL) &&
1551 (image != (const Image *) NULL))
1552 value=GetMagickProperty(image_info,image,pattern,exception);
1555 if (image != (Image *) NULL)
1556 value=GetImageProperty(image,pattern,exception);
1557 if ((value == (const char *) NULL) &&
1558 (image != (Image *) NULL))
1559 value=GetImageArtifact(image,pattern);
1560 if ((value == (const char *) NULL) &&
1561 (image_info != (ImageInfo *) NULL))
1562 value=GetImageOption(image_info,pattern);
1563 if (value == (const char *) NULL)
1568 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1569 (MaxTextExtent-(p-format-length)));
1570 length+=strlen(pattern)-1;
1572 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1573 canonical=MagickTrue;
1583 for (q=filename; *q != '\0'; q++)
1584 if ((*q == '%') && (*(q+1) == '%'))
1586 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1587 canonical=MagickTrue;
1589 if (canonical == MagickFalse)
1590 (void) CopyMagickString(filename,format,MaxTextExtent);
1591 return(strlen(filename));
1595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1599 % I s H i g h D y n a m i c R a n g e I m a g e %
1603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1605 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1606 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1609 % The format of the IsHighDynamicRangeImage method is:
1611 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1612 % ExceptionInfo *exception)
1614 % A description of each parameter follows:
1616 % o image: the image.
1618 % o exception: return any errors or warnings in this structure.
1621 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1622 ExceptionInfo *exception)
1624 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1627 return(MagickFalse);
1638 assert(image != (Image *) NULL);
1639 assert(image->signature == MagickSignature);
1640 if (image->debug != MagickFalse)
1641 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1643 image_view=AcquireVirtualCacheView(image,exception);
1644 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1645 #pragma omp parallel for schedule(static,4) shared(status) \
1646 dynamic_number_threads(image,image->columns,image->rows,1)
1648 for (y=0; y < (ssize_t) image->rows; y++)
1650 register const Quantum
1656 if (status == MagickFalse)
1658 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1659 if (p == (const Quantum *) NULL)
1664 for (x=0; x < (ssize_t) image->columns; x++)
1672 if (GetPixelMask(image,p) != 0)
1674 p+=GetPixelChannels(image);
1677 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1682 traits=GetPixelChannelMapTraits(image,i);
1683 if (traits == UndefinedPixelTrait)
1685 pixel=(double) p[i];
1686 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1687 (pixel != (QuantumAny) pixel))
1690 p+=GetPixelChannels(image);
1691 if (i < (ssize_t) GetPixelChannels(image))
1694 if (x < (ssize_t) image->columns)
1697 image_view=DestroyCacheView(image_view);
1698 return(status != MagickFalse ? MagickFalse : MagickTrue);
1703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1707 % I s I m a g e O b j e c t %
1711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1713 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1714 % set of image objects.
1716 % The format of the IsImageObject method is:
1718 % MagickBooleanType IsImageObject(const Image *image)
1720 % A description of each parameter follows:
1722 % o image: the image.
1725 MagickExport MagickBooleanType IsImageObject(const Image *image)
1727 register const Image
1730 assert(image != (Image *) NULL);
1731 if (image->debug != MagickFalse)
1732 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1733 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1734 if (p->signature != MagickSignature)
1735 return(MagickFalse);
1740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1744 % I s T a i n t I m a g e %
1748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1750 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1751 % since it was first constituted.
1753 % The format of the IsTaintImage method is:
1755 % MagickBooleanType IsTaintImage(const Image *image)
1757 % A description of each parameter follows:
1759 % o image: the image.
1762 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1765 magick[MaxTextExtent],
1766 filename[MaxTextExtent];
1768 register const Image
1771 assert(image != (Image *) NULL);
1772 if (image->debug != MagickFalse)
1773 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1774 assert(image->signature == MagickSignature);
1775 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1776 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1777 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1779 if (p->taint != MagickFalse)
1781 if (LocaleCompare(p->magick,magick) != 0)
1783 if (LocaleCompare(p->filename,filename) != 0)
1786 return(MagickFalse);
1790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1794 % M o d i f y I m a g e %
1798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1800 % ModifyImage() ensures that there is only a single reference to the image
1801 % to be modified, updating the provided image pointer to point to a clone of
1802 % the original image if necessary.
1804 % The format of the ModifyImage method is:
1806 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1808 % A description of each parameter follows:
1810 % o image: the image.
1812 % o exception: return any errors or warnings in this structure.
1815 MagickExport MagickBooleanType ModifyImage(Image **image,
1816 ExceptionInfo *exception)
1821 assert(image != (Image **) NULL);
1822 assert(*image != (Image *) NULL);
1823 assert((*image)->signature == MagickSignature);
1824 if ((*image)->debug != MagickFalse)
1825 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1826 if (GetImageReferenceCount(*image) <= 1)
1828 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1829 LockSemaphoreInfo((*image)->semaphore);
1830 (*image)->reference_count--;
1831 UnlockSemaphoreInfo((*image)->semaphore);
1837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1841 % N e w M a g i c k I m a g e %
1845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1847 % NewMagickImage() creates a blank image canvas of the specified size and
1850 % The format of the NewMagickImage method is:
1852 % Image *NewMagickImage(const ImageInfo *image_info,
1853 % const size_t width,const size_t height,const PixelInfo *background,
1854 % ExceptionInfo *exception)
1856 % A description of each parameter follows:
1858 % o image: the image.
1860 % o width: the image width.
1862 % o height: the image height.
1864 % o background: the image color.
1866 % o exception: return any errors or warnings in this structure.
1869 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
1870 const size_t width,const size_t height,const PixelInfo *background,
1871 ExceptionInfo *exception)
1885 assert(image_info != (const ImageInfo *) NULL);
1886 if (image_info->debug != MagickFalse)
1887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1888 assert(image_info->signature == MagickSignature);
1889 assert(background != (const PixelInfo *) NULL);
1890 image=AcquireImage(image_info,exception);
1891 image->columns=width;
1893 image->colorspace=background->colorspace;
1894 image->matte=background->matte;
1895 image->fuzz=background->fuzz;
1896 image->depth=background->depth;
1898 image_view=AcquireAuthenticCacheView(image,exception);
1899 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1900 #pragma omp parallel for schedule(static,4) shared(status) \
1901 dynamic_number_threads(image,image->columns,image->rows,1)
1903 for (y=0; y < (ssize_t) image->rows; y++)
1911 if (status == MagickFalse)
1913 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1914 if (q == (Quantum *) NULL)
1919 for (x=0; x < (ssize_t) image->columns; x++)
1921 SetPixelInfoPixel(image,background,q);
1922 q+=GetPixelChannels(image);
1924 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1927 image_view=DestroyCacheView(image_view);
1928 if (status == MagickFalse)
1929 image=DestroyImage(image);
1934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1938 % R e f e r e n c e I m a g e %
1942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1944 % ReferenceImage() increments the reference count associated with an image
1945 % returning a pointer to the image.
1947 % The format of the ReferenceImage method is:
1949 % Image *ReferenceImage(Image *image)
1951 % A description of each parameter follows:
1953 % o image: the image.
1956 MagickExport Image *ReferenceImage(Image *image)
1958 assert(image != (Image *) NULL);
1959 if (image->debug != MagickFalse)
1960 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1961 assert(image->signature == MagickSignature);
1962 LockSemaphoreInfo(image->semaphore);
1963 image->reference_count++;
1964 UnlockSemaphoreInfo(image->semaphore);
1969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1973 % R e s e t I m a g e P a g e %
1977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1979 % ResetImagePage() resets the image page canvas and position.
1981 % The format of the ResetImagePage method is:
1983 % MagickBooleanType ResetImagePage(Image *image,const char *page)
1985 % A description of each parameter follows:
1987 % o image: the image.
1989 % o page: the relative page specification.
1992 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2000 assert(image != (Image *) NULL);
2001 assert(image->signature == MagickSignature);
2002 if (image->debug != MagickFalse)
2003 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2004 flags=ParseAbsoluteGeometry(page,&geometry);
2005 if ((flags & WidthValue) != 0)
2007 if ((flags & HeightValue) == 0)
2008 geometry.height=geometry.width;
2009 image->page.width=geometry.width;
2010 image->page.height=geometry.height;
2012 if ((flags & AspectValue) != 0)
2014 if ((flags & XValue) != 0)
2015 image->page.x+=geometry.x;
2016 if ((flags & YValue) != 0)
2017 image->page.y+=geometry.y;
2021 if ((flags & XValue) != 0)
2023 image->page.x=geometry.x;
2024 if ((image->page.width == 0) && (geometry.x > 0))
2025 image->page.width=image->columns+geometry.x;
2027 if ((flags & YValue) != 0)
2029 image->page.y=geometry.y;
2030 if ((image->page.height == 0) && (geometry.y > 0))
2031 image->page.height=image->rows+geometry.y;
2038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2042 % S e t I m a g e A l p h a C h a n n e l %
2046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2048 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2051 % The format of the SetImageAlphaChannel method is:
2053 % MagickBooleanType SetImageAlphaChannel(Image *image,
2054 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2056 % A description of each parameter follows:
2058 % o image: the image.
2060 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2061 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2062 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2063 % TransparentAlphaChannel.
2065 % o exception: return any errors or warnings in this structure.
2069 static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
2070 const double alpha,const Quantum *q,const double beta,
2082 Compose pixel p over pixel q with the given alpha.
2084 Sa=QuantumScale*alpha;
2085 Da=QuantumScale*beta,
2086 gamma=Sa*(-Da)+Sa+Da;
2087 gamma=MagickEpsilonReciprocal(gamma);
2088 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2096 channel=GetPixelChannelMapChannel(image,i);
2097 traits=GetPixelChannelMapTraits(image,channel);
2098 if (traits == UndefinedPixelTrait)
2102 case RedPixelChannel:
2104 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],
2105 beta,(double) p->red,alpha));
2108 case GreenPixelChannel:
2110 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],
2111 beta,(double) p->green,alpha));
2114 case BluePixelChannel:
2116 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],
2117 beta,(double) p->blue,alpha));
2120 case BlackPixelChannel:
2122 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],
2123 beta,(double) p->black,alpha));
2126 case AlphaPixelChannel:
2128 composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
2137 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2138 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2143 assert(image != (Image *) NULL);
2144 if (image->debug != MagickFalse)
2145 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2146 assert(image->signature == MagickSignature);
2150 case ActivateAlphaChannel:
2152 image->matte=MagickTrue;
2155 case BackgroundAlphaChannel:
2164 Set transparent pixels to background color.
2166 if (image->matte == MagickFalse)
2168 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2170 image_view=AcquireAuthenticCacheView(image,exception);
2171 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2172 #pragma omp parallel for schedule(static,4) shared(status) \
2173 dynamic_number_threads(image,image->columns,image->rows,1)
2175 for (y=0; y < (ssize_t) image->rows; y++)
2183 if (status == MagickFalse)
2185 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2187 if (q == (Quantum *) NULL)
2192 for (x=0; x < (ssize_t) image->columns; x++)
2194 if (GetPixelAlpha(image,q) == TransparentAlpha)
2195 SetPixelInfoPixel(image,&image->background_color,q);
2196 q+=GetPixelChannels(image);
2198 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2201 image_view=DestroyCacheView(image_view);
2204 case CopyAlphaChannel:
2205 case ShapeAlphaChannel:
2208 Copy pixel intensity to the alpha channel.
2210 status=CompositeImage(image,image,IntensityCompositeOp,MagickTrue,0,0,
2212 if (alpha_type == ShapeAlphaChannel)
2213 (void) LevelImageColors(image,&image->background_color,
2214 &image->background_color,MagickTrue,exception);
2217 case DeactivateAlphaChannel:
2219 image->matte=MagickFalse;
2222 case ExtractAlphaChannel:
2224 status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
2226 image->matte=MagickFalse;
2229 case OpaqueAlphaChannel:
2231 status=SetImageAlpha(image,OpaqueAlpha,exception);
2234 case RemoveAlphaChannel:
2243 Remove transparency.
2245 if (image->matte == MagickFalse)
2247 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2249 image_view=AcquireAuthenticCacheView(image,exception);
2250 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2251 #pragma omp parallel for schedule(static,4) shared(status) \
2252 dynamic_number_threads(image,image->columns,image->rows,1)
2254 for (y=0; y < (ssize_t) image->rows; y++)
2262 if (status == MagickFalse)
2264 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2266 if (q == (Quantum *) NULL)
2271 for (x=0; x < (ssize_t) image->columns; x++)
2273 FlattenPixelInfo(image,&image->background_color,
2274 image->background_color.alpha,q,(double)
2275 GetPixelAlpha(image,q),q);
2276 q+=GetPixelChannels(image);
2278 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2281 image_view=DestroyCacheView(image_view);
2282 image->matte=image->background_color.matte;
2285 case SetAlphaChannel:
2287 if (image->matte == MagickFalse)
2288 status=SetImageAlpha(image,OpaqueAlpha,exception);
2291 case TransparentAlphaChannel:
2293 status=SetImageAlpha(image,TransparentAlpha,exception);
2296 case UndefinedAlphaChannel:
2299 if (status == MagickFalse)
2301 return(SyncImagePixelCache(image,exception));
2305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2309 % S e t I m a g e B a c k g r o u n d C o l o r %
2313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2315 % SetImageBackgroundColor() initializes the image pixels to the image
2316 % background color. The background color is defined by the background_color
2317 % member of the image structure.
2319 % The format of the SetImage method is:
2321 % MagickBooleanType SetImageBackgroundColor(Image *image,
2322 % ExceptionInfo *exception)
2324 % A description of each parameter follows:
2326 % o image: the image.
2328 % o exception: return any errors or warnings in this structure.
2331 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2332 ExceptionInfo *exception)
2343 assert(image != (Image *) NULL);
2344 if (image->debug != MagickFalse)
2345 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2346 assert(image->signature == MagickSignature);
2347 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2348 return(MagickFalse);
2349 if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
2350 (IsGrayColorspace(image->colorspace) != MagickFalse))
2351 (void) TransformImageColorspace(image,RGBColorspace,exception);
2352 if ((image->background_color.matte != MagickFalse) &&
2353 (image->matte == MagickFalse))
2354 (void) SetImageAlpha(image,OpaqueAlpha,exception);
2356 Set image background color.
2359 image_view=AcquireAuthenticCacheView(image,exception);
2360 for (y=0; y < (ssize_t) image->rows; y++)
2368 if (status == MagickFalse)
2370 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2371 if (q == (Quantum *) NULL)
2376 for (x=0; x < (ssize_t) image->columns; x++)
2378 SetPixelInfoPixel(image,&image->background_color,q);
2379 q+=GetPixelChannels(image);
2381 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2384 image_view=DestroyCacheView(image_view);
2389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2393 % S e t I m a g e C o l o r %
2397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2399 % SetImageColor() set the entire image canvas to the specified color.
2401 % The format of the SetImageColor method is:
2403 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2404 % ExeptionInfo *exception)
2406 % A description of each parameter follows:
2408 % o image: the image.
2410 % o background: the image color.
2412 % o exception: return any errors or warnings in this structure.
2415 MagickExport MagickBooleanType SetImageColor(Image *image,
2416 const PixelInfo *color,ExceptionInfo *exception)
2427 assert(image != (Image *) NULL);
2428 if (image->debug != MagickFalse)
2429 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2430 assert(image->signature == MagickSignature);
2431 assert(color != (const PixelInfo *) NULL);
2432 image->colorspace=color->colorspace;
2433 image->matte=color->matte;
2434 image->fuzz=color->fuzz;
2435 image->depth=color->depth;
2437 image_view=AcquireAuthenticCacheView(image,exception);
2438 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2439 #pragma omp parallel for schedule(static,4) shared(status) \
2440 dynamic_number_threads(image,image->columns,image->rows,1)
2442 for (y=0; y < (ssize_t) image->rows; y++)
2450 if (status == MagickFalse)
2452 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2453 if (q == (Quantum *) NULL)
2458 for (x=0; x < (ssize_t) image->columns; x++)
2460 SetPixelInfoPixel(image,color,q);
2461 q+=GetPixelChannels(image);
2463 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2466 image_view=DestroyCacheView(image_view);
2471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2475 % S e t I m a g e S t o r a g e C l a s s %
2479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2481 % SetImageStorageClass() sets the image class: DirectClass for true color
2482 % images or PseudoClass for colormapped images.
2484 % The format of the SetImageStorageClass method is:
2486 % MagickBooleanType SetImageStorageClass(Image *image,
2487 % const ClassType storage_class,ExceptionInfo *exception)
2489 % A description of each parameter follows:
2491 % o image: the image.
2493 % o storage_class: The image class.
2495 % o exception: return any errors or warnings in this structure.
2498 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2499 const ClassType storage_class,ExceptionInfo *exception)
2501 image->storage_class=storage_class;
2502 return(SyncImagePixelCache(image,exception));
2506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2510 % S e t I m a g e E x t e n t %
2514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2516 % SetImageExtent() sets the image size (i.e. columns & rows).
2518 % The format of the SetImageExtent method is:
2520 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2521 % const size_t rows,ExceptionInfo *exception)
2523 % A description of each parameter follows:
2525 % o image: the image.
2527 % o columns: The image width in pixels.
2529 % o rows: The image height in pixels.
2531 % o exception: return any errors or warnings in this structure.
2534 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2535 const size_t rows,ExceptionInfo *exception)
2537 if ((columns == 0) || (rows == 0))
2538 return(MagickFalse);
2539 image->columns=columns;
2541 return(SyncImagePixelCache(image,exception));
2545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2549 + S e t I m a g e I n f o %
2553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2555 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2556 % It is set to a type of image format based on the prefix or suffix of the
2557 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2558 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2559 % precendence over the suffix. Use an optional index enclosed in brackets
2560 % after a file name to specify a desired scene of a multi-resolution image
2561 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2562 % indicates success.
2564 % The format of the SetImageInfo method is:
2566 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2567 % const unsigned int frames,ExceptionInfo *exception)
2569 % A description of each parameter follows:
2571 % o image_info: the image info.
2573 % o frames: the number of images you intend to write.
2575 % o exception: return any errors or warnings in this structure.
2578 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2579 const unsigned int frames,ExceptionInfo *exception)
2582 extension[MaxTextExtent],
2583 filename[MaxTextExtent],
2584 magic[MaxTextExtent],
2586 subimage[MaxTextExtent];
2610 magick[2*MaxTextExtent];
2613 Look for 'image.format' in filename.
2615 assert(image_info != (ImageInfo *) NULL);
2616 assert(image_info->signature == MagickSignature);
2617 if (image_info->debug != MagickFalse)
2618 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2619 image_info->filename);
2623 GetPathComponent(image_info->filename,SubimagePath,subimage);
2624 if (*subimage != '\0')
2627 Look for scene specification (e.g. img0001.pcd[4]).
2629 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2631 if (IsGeometry(subimage) != MagickFalse)
2632 (void) CloneString(&image_info->extract,subimage);
2640 (void) CloneString(&image_info->scenes,subimage);
2641 image_info->scene=StringToUnsignedLong(image_info->scenes);
2642 image_info->number_scenes=image_info->scene;
2643 p=image_info->scenes;
2644 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2646 while ((isspace((int) ((unsigned char) *p)) != 0) ||
2649 first=(size_t) strtol(p,&q,10);
2651 while (isspace((int) ((unsigned char) *q)) != 0)
2654 last=(size_t) strtol(q+1,&q,10);
2657 if (first < image_info->scene)
2658 image_info->scene=first;
2659 if (last > image_info->number_scenes)
2660 image_info->number_scenes=last;
2663 image_info->number_scenes-=image_info->scene-1;
2668 GetPathComponent(image_info->filename,ExtensionPath,extension);
2669 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2670 if (*extension != '\0')
2671 if ((LocaleCompare(extension,"gz") == 0) ||
2672 (LocaleCompare(extension,"Z") == 0) ||
2673 (LocaleCompare(extension,"svgz") == 0) ||
2674 (LocaleCompare(extension,"wmz") == 0))
2677 path[MaxTextExtent];
2679 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2680 path[strlen(path)-strlen(extension)-1]='\0';
2681 GetPathComponent(path,ExtensionPath,extension);
2684 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2685 if (*extension != '\0')
2686 if (LocaleCompare(extension,"bz2") == 0)
2689 path[MaxTextExtent];
2691 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2692 path[strlen(path)-strlen(extension)-1]='\0';
2693 GetPathComponent(path,ExtensionPath,extension);
2696 image_info->affirm=MagickFalse;
2697 sans_exception=AcquireExceptionInfo();
2698 if (*extension != '\0')
2707 *format_type_formats[] =
2730 User specified image format.
2732 (void) CopyMagickString(magic,extension,MaxTextExtent);
2735 Look for explicit image formats.
2737 format_type=UndefinedFormatType;
2739 while ((format_type == UndefinedFormatType) &&
2740 (format_type_formats[i] != (char *) NULL))
2742 if ((*magic == *format_type_formats[i]) &&
2743 (LocaleCompare(magic,format_type_formats[i]) == 0))
2744 format_type=ExplicitFormatType;
2747 magick_info=GetMagickInfo(magic,sans_exception);
2748 if ((magick_info != (const MagickInfo *) NULL) &&
2749 (magick_info->format_type != UndefinedFormatType))
2750 format_type=magick_info->format_type;
2751 if (format_type == UndefinedFormatType)
2752 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2754 if (format_type == ExplicitFormatType)
2756 image_info->affirm=MagickTrue;
2757 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2759 if (LocaleCompare(magic,"RGB") == 0)
2760 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2763 Look for explicit 'format:image' in filename.
2766 GetPathComponent(image_info->filename,MagickPath,magic);
2768 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
2772 User specified image format.
2775 if (IsMagickConflict(magic) == MagickFalse)
2777 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2778 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2779 image_info->affirm=MagickTrue;
2781 image_info->temporary=MagickTrue;
2784 magick_info=GetMagickInfo(magic,sans_exception);
2785 sans_exception=DestroyExceptionInfo(sans_exception);
2786 if ((magick_info == (const MagickInfo *) NULL) ||
2787 (GetMagickEndianSupport(magick_info) == MagickFalse))
2788 image_info->endian=UndefinedEndian;
2789 GetPathComponent(image_info->filename,CanonicalPath,filename);
2790 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2791 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2794 Test for multiple image support (e.g. image%02d.png).
2796 (void) InterpretImageFilename(image_info,(Image *) NULL,
2797 image_info->filename,(int) image_info->scene,filename,exception);
2798 if ((LocaleCompare(filename,image_info->filename) != 0) &&
2799 (strchr(filename,'%') == (char *) NULL))
2800 image_info->adjoin=MagickFalse;
2802 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2805 Some image formats do not support multiple frames per file.
2807 magick_info=GetMagickInfo(magic,exception);
2808 if (magick_info != (const MagickInfo *) NULL)
2809 if (GetMagickAdjoin(magick_info) == MagickFalse)
2810 image_info->adjoin=MagickFalse;
2812 if (image_info->affirm != MagickFalse)
2817 Determine the image format from the first few bytes of the file.
2819 image=AcquireImage(image_info,exception);
2820 (void) CopyMagickString(image->filename,image_info->filename,
2822 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2823 if (status == MagickFalse)
2825 image=DestroyImage(image);
2826 return(MagickFalse);
2828 if ((IsBlobSeekable(image) == MagickFalse) ||
2829 (IsBlobExempt(image) != MagickFalse))
2832 Copy standard input or pipe to temporary file.
2835 status=ImageToFile(image,filename,exception);
2836 (void) CloseBlob(image);
2837 if (status == MagickFalse)
2839 image=DestroyImage(image);
2840 return(MagickFalse);
2842 SetImageInfoFile(image_info,(FILE *) NULL);
2843 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
2844 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2845 if (status == MagickFalse)
2847 image=DestroyImage(image);
2848 return(MagickFalse);
2850 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2851 image_info->temporary=MagickTrue;
2853 (void) ResetMagickMemory(magick,0,sizeof(magick));
2854 count=ReadBlob(image,2*MaxTextExtent,magick);
2855 (void) CloseBlob(image);
2856 image=DestroyImage(image);
2858 Check magic.xml configuration file.
2860 sans_exception=AcquireExceptionInfo();
2861 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2862 if ((magic_info != (const MagicInfo *) NULL) &&
2863 (GetMagicName(magic_info) != (char *) NULL))
2865 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
2867 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2868 if ((magick_info == (const MagickInfo *) NULL) ||
2869 (GetMagickEndianSupport(magick_info) == MagickFalse))
2870 image_info->endian=UndefinedEndian;
2871 sans_exception=DestroyExceptionInfo(sans_exception);
2874 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2875 if ((magick_info == (const MagickInfo *) NULL) ||
2876 (GetMagickEndianSupport(magick_info) == MagickFalse))
2877 image_info->endian=UndefinedEndian;
2878 sans_exception=DestroyExceptionInfo(sans_exception);
2884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2888 % S e t I m a g e I n f o B l o b %
2892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2894 % SetImageInfoBlob() sets the image info blob member.
2896 % The format of the SetImageInfoBlob method is:
2898 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2899 % const size_t length)
2901 % A description of each parameter follows:
2903 % o image_info: the image info.
2907 % o length: the blob length.
2910 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2911 const size_t length)
2913 assert(image_info != (ImageInfo *) NULL);
2914 assert(image_info->signature == MagickSignature);
2915 if (image_info->debug != MagickFalse)
2916 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2917 image_info->filename);
2918 image_info->blob=(void *) blob;
2919 image_info->length=length;
2923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2927 % S e t I m a g e I n f o F i l e %
2931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2933 % SetImageInfoFile() sets the image info file member.
2935 % The format of the SetImageInfoFile method is:
2937 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2939 % A description of each parameter follows:
2941 % o image_info: the image info.
2946 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2948 assert(image_info != (ImageInfo *) NULL);
2949 assert(image_info->signature == MagickSignature);
2950 if (image_info->debug != MagickFalse)
2951 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2952 image_info->filename);
2953 image_info->file=file;
2957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2961 % S e t I m a g e M a s k %
2965 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2967 % SetImageMask() associates a mask with the image. The mask must be the same
2968 % dimensions as the image.
2970 % The format of the SetImageMask method is:
2972 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
2973 % ExceptionInfo *exception)
2975 % A description of each parameter follows:
2977 % o image: the image.
2979 % o mask: the image mask.
2981 % o exception: return any errors or warnings in this structure.
2984 MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
2985 ExceptionInfo *exception)
3000 assert(image != (Image *) NULL);
3001 if (image->debug != MagickFalse)
3002 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3003 assert(image->signature == MagickSignature);
3004 if (mask == (const Image *) NULL)
3006 image->mask=MagickFalse;
3010 image->mask=MagickTrue;
3011 mask_view=AcquireVirtualCacheView(mask,exception);
3012 image_view=AcquireAuthenticCacheView(image,exception);
3013 for (y=0; y < (ssize_t) image->rows; y++)
3015 register const Quantum
3024 if (status == MagickFalse)
3026 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3027 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3028 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3033 for (x=0; x < (ssize_t) image->columns; x++)
3035 SetPixelMask(image,GetPixelGray(mask,p),q);
3036 p+=GetPixelChannels(mask);
3037 q+=GetPixelChannels(image);
3039 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3042 mask_view=DestroyCacheView(mask_view);
3043 image_view=DestroyCacheView(image_view);
3048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3052 % S e t I m a g e A l p h a %
3056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3058 % SetImageAlpha() sets the alpha levels of the image.
3060 % The format of the SetImageAlpha method is:
3062 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3063 % ExceptionInfo *exception)
3065 % A description of each parameter follows:
3067 % o image: the image.
3069 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3070 % fully transparent.
3073 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3074 ExceptionInfo *exception)
3085 assert(image != (Image *) NULL);
3086 if (image->debug != MagickFalse)
3087 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3088 assert(image->signature == MagickSignature);
3089 image->matte=MagickTrue;
3091 image_view=AcquireAuthenticCacheView(image,exception);
3092 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3093 #pragma omp parallel for schedule(static,4) shared(status) \
3094 dynamic_number_threads(image,image->columns,image->rows,1)
3096 for (y=0; y < (ssize_t) image->rows; y++)
3104 if (status == MagickFalse)
3106 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3107 if (q == (Quantum *) NULL)
3112 for (x=0; x < (ssize_t) image->columns; x++)
3114 SetPixelAlpha(image,alpha,q);
3115 q+=GetPixelChannels(image);
3117 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3120 image_view=DestroyCacheView(image_view);
3125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3129 % 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 %
3133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3135 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3136 % image and returns the previous setting. A virtual pixel is any pixel access
3137 % that is outside the boundaries of the image cache.
3139 % The format of the SetImageVirtualPixelMethod() method is:
3141 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3142 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3144 % A description of each parameter follows:
3146 % o image: the image.
3148 % o virtual_pixel_method: choose the type of virtual pixel.
3150 % o exception: return any errors or warnings in this structure.
3153 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3154 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3156 assert(image != (const Image *) NULL);
3157 assert(image->signature == MagickSignature);
3158 if (image->debug != MagickFalse)
3159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3160 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3168 % S m u s h I m a g e s %
3172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3174 % SmushImages() takes all images from the current image pointer to the end
3175 % of the image list and smushes them to each other top-to-bottom if the
3176 % stack parameter is true, otherwise left-to-right.
3178 % The current gravity setting now effects how the image is justified in the
3181 % The format of the SmushImages method is:
3183 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3184 % ExceptionInfo *exception)
3186 % A description of each parameter follows:
3188 % o images: the image sequence.
3190 % o stack: A value other than 0 stacks the images top-to-bottom.
3192 % o offset: minimum distance in pixels between images.
3194 % o exception: return any errors or warnings in this structure.
3198 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3199 const ssize_t offset,ExceptionInfo *exception)
3213 register const Quantum
3226 if (images->previous == (Image *) NULL)
3229 SetGeometry(smush_image,&right_geometry);
3230 GravityAdjustGeometry(right_image->columns,right_image->rows,
3231 right_image->gravity,&right_geometry);
3232 left_image=images->previous;
3233 SetGeometry(smush_image,&left_geometry);
3234 GravityAdjustGeometry(left_image->columns,left_image->rows,
3235 left_image->gravity,&left_geometry);
3236 gap=right_image->columns;
3237 left_view=AcquireVirtualCacheView(left_image,exception);
3238 right_view=AcquireVirtualCacheView(right_image,exception);
3239 for (y=0; y < (ssize_t) smush_image->rows; y++)
3241 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3243 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3244 if ((p == (const Quantum *) NULL) ||
3245 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3246 ((left_image->columns-x-1) >= gap))
3249 i=(ssize_t) left_image->columns-x-1;
3250 for (x=0; x < (ssize_t) right_image->columns; x++)
3252 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3254 if ((p == (const Quantum *) NULL) ||
3255 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3256 ((x+i) >= (ssize_t) gap))
3259 if ((x+i) < (ssize_t) gap)
3262 right_view=DestroyCacheView(right_view);
3263 left_view=DestroyCacheView(left_view);
3264 if (y < (ssize_t) smush_image->rows)
3266 return((ssize_t) gap-offset);
3269 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3270 const ssize_t offset,ExceptionInfo *exception)
3284 register const Quantum
3297 if (images->previous == (Image *) NULL)
3299 bottom_image=images;
3300 SetGeometry(smush_image,&bottom_geometry);
3301 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3302 bottom_image->gravity,&bottom_geometry);
3303 top_image=images->previous;
3304 SetGeometry(smush_image,&top_geometry);
3305 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3307 gap=bottom_image->rows;
3308 top_view=AcquireVirtualCacheView(top_image,exception);
3309 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3310 for (x=0; x < (ssize_t) smush_image->columns; x++)
3312 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3314 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3315 if ((p == (const Quantum *) NULL) ||
3316 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3317 ((top_image->rows-y-1) >= gap))
3320 i=(ssize_t) top_image->rows-y-1;
3321 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3323 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3325 if ((p == (const Quantum *) NULL) ||
3326 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3327 ((y+i) >= (ssize_t) gap))
3330 if ((y+i) < (ssize_t) gap)
3333 bottom_view=DestroyCacheView(bottom_view);
3334 top_view=DestroyCacheView(top_view);
3335 if (x < (ssize_t) smush_image->columns)
3337 return((ssize_t) gap-offset);
3340 MagickExport Image *SmushImages(const Image *images,
3341 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3343 #define SmushImageTag "Smush/Image"
3362 register const Image
3375 Compute maximum area of smushed area.
3377 assert(images != (Image *) NULL);
3378 assert(images->signature == MagickSignature);
3379 if (images->debug != MagickFalse)
3380 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3381 assert(exception != (ExceptionInfo *) NULL);
3382 assert(exception->signature == MagickSignature);
3386 width=image->columns;
3388 next=GetNextImageInList(image);
3389 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3391 if (next->matte != MagickFalse)
3394 if (stack != MagickFalse)
3396 if (next->columns > width)
3397 width=next->columns;
3399 if (next->previous != (Image *) NULL)
3403 width+=next->columns;
3404 if (next->previous != (Image *) NULL)
3406 if (next->rows > height)
3412 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3413 if (smush_image == (Image *) NULL)
3414 return((Image *) NULL);
3415 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3417 smush_image=DestroyImage(smush_image);
3418 return((Image *) NULL);
3420 smush_image->matte=matte;
3421 (void) SetImageBackgroundColor(smush_image,exception);
3425 for (n=0; n < (MagickOffsetType) number_images; n++)
3427 SetGeometry(smush_image,&geometry);
3428 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3429 if (stack != MagickFalse)
3431 x_offset-=geometry.x;
3432 y_offset-=SmushYGap(smush_image,image,offset,exception);
3436 x_offset-=SmushXGap(smush_image,image,offset,exception);
3437 y_offset-=geometry.y;
3439 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3440 y_offset,exception);
3441 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3442 if (proceed == MagickFalse)
3444 if (stack == MagickFalse)
3446 x_offset+=(ssize_t) image->columns;
3452 y_offset+=(ssize_t) image->rows;
3454 image=GetNextImageInList(image);
3456 if (stack == MagickFalse)
3457 smush_image->columns=(size_t) x_offset;
3459 smush_image->rows=(size_t) y_offset;
3460 if (status == MagickFalse)
3461 smush_image=DestroyImage(smush_image);
3462 return(smush_image);
3466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3470 % S t r i p I m a g e %
3474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3476 % StripImage() strips an image of all profiles and comments.
3478 % The format of the StripImage method is:
3480 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3482 % A description of each parameter follows:
3484 % o image: the image.
3486 % o exception: return any errors or warnings in this structure.
3489 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3494 assert(image != (Image *) NULL);
3495 if (image->debug != MagickFalse)
3496 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3498 DestroyImageProfiles(image);
3499 (void) DeleteImageProperty(image,"comment");
3500 (void) DeleteImageProperty(image,"date:create");
3501 (void) DeleteImageProperty(image,"date:modify");
3502 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
3507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3511 + S y n c I m a g e %
3515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3517 % SyncImage() initializes the red, green, and blue intensities of each pixel
3518 % as defined by the colormap index.
3520 % The format of the SyncImage method is:
3522 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3524 % A description of each parameter follows:
3526 % o image: the image.
3528 % o exception: return any errors or warnings in this structure.
3532 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3533 MagickBooleanType *range_exception)
3535 if ((size_t) index < image->colors)
3537 *range_exception=MagickTrue;
3538 return((Quantum) 0);
3541 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3553 assert(image != (Image *) NULL);
3554 if (image->debug != MagickFalse)
3555 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3556 assert(image->signature == MagickSignature);
3557 if (image->storage_class == DirectClass)
3558 return(MagickFalse);
3559 range_exception=MagickFalse;
3561 image_view=AcquireAuthenticCacheView(image,exception);
3562 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3563 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3564 dynamic_number_threads(image,image->columns,image->rows,1)
3566 for (y=0; y < (ssize_t) image->rows; y++)
3577 if (status == MagickFalse)
3579 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3580 if (q == (Quantum *) NULL)
3585 for (x=0; x < (ssize_t) image->columns; x++)
3587 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3588 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
3589 q+=GetPixelChannels(image);
3591 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3594 image_view=DestroyCacheView(image_view);
3595 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3596 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
3597 "InvalidColormapIndex","'%s'",image->filename);
3602 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3606 % S y n c I m a g e S e t t i n g s %
3610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3612 % SyncImageSettings() syncs the image_info options into per-image attributes.
3614 % The format of the SyncImageSettings method is:
3616 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3617 % Image *image,ExceptionInfo *exception)
3618 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3619 % Image *image,ExceptionInfo *exception)
3621 % A description of each parameter follows:
3623 % o image_info: the image info.
3625 % o image: the image.
3627 % o exception: return any errors or warnings in this structure.
3631 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3632 Image *images,ExceptionInfo *exception)
3637 assert(image_info != (const ImageInfo *) NULL);
3638 assert(image_info->signature == MagickSignature);
3639 assert(images != (Image *) NULL);
3640 assert(images->signature == MagickSignature);
3641 if (images->debug != MagickFalse)
3642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3644 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3645 (void) SyncImageSettings(image_info,image,exception);
3646 (void) DeleteImageOption(image_info,"page");
3650 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3651 Image *image,ExceptionInfo *exception)
3654 property[MaxTextExtent];
3672 assert(image_info != (const ImageInfo *) NULL);
3673 assert(image_info->signature == MagickSignature);
3674 assert(image != (Image *) NULL);
3675 assert(image->signature == MagickSignature);
3676 if (image->debug != MagickFalse)
3677 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3678 option=GetImageOption(image_info,"background");
3679 if (option != (const char *) NULL)
3680 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3682 option=GetImageOption(image_info,"black-point-compensation");
3683 if (option != (const char *) NULL)
3684 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3685 MagickBooleanOptions,MagickFalse,option);
3686 option=GetImageOption(image_info,"blue-primary");
3687 if (option != (const char *) NULL)
3689 flags=ParseGeometry(option,&geometry_info);
3690 image->chromaticity.blue_primary.x=geometry_info.rho;
3691 image->chromaticity.blue_primary.y=geometry_info.sigma;
3692 if ((flags & SigmaValue) == 0)
3693 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3695 option=GetImageOption(image_info,"bordercolor");
3696 if (option != (const char *) NULL)
3697 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3699 option=GetImageOption(image_info,"channel");
3700 if (option != (const char *) NULL)
3701 (void) SetPixelChannelMapMask(image,(ChannelType)
3702 ParseChannelOption(option));
3703 /* FUTURE: do not sync compose to per-image compose setting here */
3704 option=GetImageOption(image_info,"compose");
3705 if (option != (const char *) NULL)
3706 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3707 MagickFalse,option);
3709 option=GetImageOption(image_info,"compress");
3710 if (option != (const char *) NULL)
3711 image->compression=(CompressionType) ParseCommandOption(
3712 MagickCompressOptions,MagickFalse,option);
3713 option=GetImageOption(image_info,"debug");
3714 if (option != (const char *) NULL)
3715 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3716 MagickFalse,option);
3717 option=GetImageOption(image_info,"density");
3718 if (option != (const char *) NULL)
3723 flags=ParseGeometry(option,&geometry_info);
3724 image->resolution.x=geometry_info.rho;
3725 image->resolution.y=geometry_info.sigma;
3726 if ((flags & SigmaValue) == 0)
3727 image->resolution.y=image->resolution.x;
3729 option=GetImageOption(image_info,"depth");
3730 if (option != (const char *) NULL)
3731 image->depth=StringToUnsignedLong(option);
3732 option=GetImageOption(image_info,"endian");
3733 if (option != (const char *) NULL)
3734 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3735 MagickFalse,option);
3736 option=GetImageOption(image_info,"filter");
3737 if (option != (const char *) NULL)
3738 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3739 MagickFalse,option);
3740 option=GetImageOption(image_info,"fuzz");
3741 if (option != (const char *) NULL)
3742 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3743 option=GetImageOption(image_info,"gravity");
3744 if (option != (const char *) NULL)
3745 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3746 MagickFalse,option);
3747 option=GetImageOption(image_info,"green-primary");
3748 if (option != (const char *) NULL)
3750 flags=ParseGeometry(option,&geometry_info);
3751 image->chromaticity.green_primary.x=geometry_info.rho;
3752 image->chromaticity.green_primary.y=geometry_info.sigma;
3753 if ((flags & SigmaValue) == 0)
3754 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3756 option=GetImageOption(image_info,"intent");
3757 if (option != (const char *) NULL)
3758 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3759 MagickIntentOptions,MagickFalse,option);
3760 option=GetImageOption(image_info,"interlace");
3761 if (option != (const char *) NULL)
3762 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3763 MagickFalse,option);
3764 option=GetImageOption(image_info,"interpolate");
3765 if (option != (const char *) NULL)
3766 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3767 MagickInterpolateOptions,MagickFalse,option);
3768 option=GetImageOption(image_info,"loop");
3769 if (option != (const char *) NULL)
3770 image->iterations=StringToUnsignedLong(option);
3771 option=GetImageOption(image_info,"mattecolor");
3772 if (option != (const char *) NULL)
3773 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
3775 option=GetImageOption(image_info,"orient");
3776 if (option != (const char *) NULL)
3777 image->orientation=(OrientationType) ParseCommandOption(
3778 MagickOrientationOptions,MagickFalse,option);
3779 option=GetImageOption(image_info,"page");
3780 if (option != (const char *) NULL)
3785 geometry=GetPageGeometry(option);
3786 flags=ParseAbsoluteGeometry(geometry,&image->page);
3787 geometry=DestroyString(geometry);
3789 option=GetImageOption(image_info,"quality");
3790 if (option != (const char *) NULL)
3791 image->quality=StringToUnsignedLong(option);
3792 option=GetImageOption(image_info,"red-primary");
3793 if (option != (const char *) NULL)
3795 flags=ParseGeometry(option,&geometry_info);
3796 image->chromaticity.red_primary.x=geometry_info.rho;
3797 image->chromaticity.red_primary.y=geometry_info.sigma;
3798 if ((flags & SigmaValue) == 0)
3799 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3801 if (image_info->quality != UndefinedCompressionQuality)
3802 image->quality=image_info->quality;
3803 option=GetImageOption(image_info,"scene");
3804 if (option != (const char *) NULL)
3805 image->scene=StringToUnsignedLong(option);
3806 option=GetImageOption(image_info,"taint");
3807 if (option != (const char *) NULL)
3808 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3809 MagickFalse,option);
3810 option=GetImageOption(image_info,"tile-offset");
3811 if (option != (const char *) NULL)
3816 geometry=GetPageGeometry(option);
3817 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3818 geometry=DestroyString(geometry);
3820 option=GetImageOption(image_info,"transparent-color");
3821 if (option != (const char *) NULL)
3822 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3824 option=GetImageOption(image_info,"type");
3825 if (option != (const char *) NULL)
3826 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3828 option=GetImageOption(image_info,"units");
3829 units=image_info->units;
3830 if (option != (const char *) NULL)
3831 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3832 MagickFalse,option);
3833 if (units != UndefinedResolution)
3835 if (image->units != units)
3836 switch (image->units)
3838 case PixelsPerInchResolution:
3840 if (units == PixelsPerCentimeterResolution)
3842 image->resolution.x/=2.54;
3843 image->resolution.y/=2.54;
3847 case PixelsPerCentimeterResolution:
3849 if (units == PixelsPerInchResolution)
3851 image->resolution.x=(double) ((size_t) (100.0*2.54*
3852 image->resolution.x+0.5))/100.0;
3853 image->resolution.y=(double) ((size_t) (100.0*2.54*
3854 image->resolution.y+0.5))/100.0;
3863 option=GetImageOption(image_info,"virtual-pixel");
3864 if (option != (const char *) NULL)
3865 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3866 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3868 option=GetImageOption(image_info,"white-point");
3869 if (option != (const char *) NULL)
3871 flags=ParseGeometry(option,&geometry_info);
3872 image->chromaticity.white_point.x=geometry_info.rho;
3873 image->chromaticity.white_point.y=geometry_info.sigma;
3874 if ((flags & SigmaValue) == 0)
3875 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3877 ResetImageOptionIterator(image_info);
3878 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
3880 value=GetImageOption(image_info,option);
3881 if (value != (const char *) NULL)
3883 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
3884 (void) SetImageArtifact(image,property,value);
3886 option=GetNextImageOption(image_info);