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/channel.h"
53#include "MagickCore/client.h"
54#include "MagickCore/color.h"
55#include "MagickCore/color-private.h"
56#include "MagickCore/colormap.h"
57#include "MagickCore/colorspace.h"
58#include "MagickCore/colorspace-private.h"
59#include "MagickCore/composite.h"
60#include "MagickCore/composite-private.h"
61#include "MagickCore/compress.h"
62#include "MagickCore/constitute.h"
63#include "MagickCore/delegate.h"
64#include "MagickCore/display.h"
65#include "MagickCore/draw.h"
66#include "MagickCore/enhance.h"
67#include "MagickCore/exception.h"
68#include "MagickCore/exception-private.h"
69#include "MagickCore/gem.h"
70#include "MagickCore/geometry.h"
71#include "MagickCore/histogram.h"
72#include "MagickCore/image-private.h"
73#include "MagickCore/list.h"
74#include "MagickCore/magic.h"
75#include "MagickCore/magick.h"
76#include "MagickCore/magick-private.h"
77#include "MagickCore/memory_.h"
78#include "MagickCore/memory-private.h"
79#include "MagickCore/module.h"
80#include "MagickCore/monitor.h"
81#include "MagickCore/monitor-private.h"
82#include "MagickCore/option.h"
83#include "MagickCore/paint.h"
84#include "MagickCore/pixel-accessor.h"
85#include "MagickCore/profile.h"
86#include "MagickCore/property.h"
87#include "MagickCore/quantize.h"
88#include "MagickCore/random_.h"
89#include "MagickCore/registry.h"
90#include "MagickCore/resource_.h"
91#include "MagickCore/segment.h"
92#include "MagickCore/semaphore.h"
93#include "MagickCore/signature-private.h"
94#include "MagickCore/statistic.h"
95#include "MagickCore/string_.h"
96#include "MagickCore/string-private.h"
97#include "MagickCore/thread-private.h"
98#include "MagickCore/threshold.h"
99#include "MagickCore/timer.h"
100#include "MagickCore/timer-private.h"
101#include "MagickCore/token.h"
102#include "MagickCore/token-private.h"
103#include "MagickCore/utility.h"
104#include "MagickCore/utility-private.h"
105#include "MagickCore/version.h"
106#include "MagickCore/xwindow-private.h"
135MagickExport Image *AcquireImage(
const ImageInfo *image_info,
136 ExceptionInfo *exception)
153 if (IsEventLogging() != MagickFalse)
154 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
155 image=(Image *) AcquireCriticalMemory(
sizeof(*image));
156 (void) memset(image,0,
sizeof(*image));
160 (void) CopyMagickString(image->magick,
"MIFF",MagickPathExtent);
161 image->storage_class=DirectClass;
162 image->depth=MAGICKCORE_QUANTUM_DEPTH;
163 image->colorspace=sRGBColorspace;
164 image->rendering_intent=PerceptualIntent;
165 image->gamma=1.000/2.200;
166 image->chromaticity.red_primary.x=0.6400;
167 image->chromaticity.red_primary.y=0.3300;
168 image->chromaticity.red_primary.z=0.0300;
169 image->chromaticity.green_primary.x=0.3000;
170 image->chromaticity.green_primary.y=0.6000;
171 image->chromaticity.green_primary.z=0.1000;
172 image->chromaticity.blue_primary.x=0.1500;
173 image->chromaticity.blue_primary.y=0.0600;
174 image->chromaticity.blue_primary.z=0.7900;
175 image->chromaticity.white_point.x=0.3127;
176 image->chromaticity.white_point.y=0.3290;
177 image->chromaticity.white_point.z=0.3583;
178 image->interlace=NoInterlace;
179 image->ticks_per_second=UndefinedTicksPerSecond;
180 image->compose=OverCompositeOp;
181 GetPixelInfoRGBA(BackgroundColorRGBA,&image->background_color);
182 GetPixelInfoRGBA(BorderColorRGBA,&image->border_color);
183 GetPixelInfoRGBA(MatteColorRGBA,&image->matte_color);
184 GetPixelInfoRGBA(TransparentColorRGBA,&image->transparent_color);
185 GetTimerInfo(&image->timer);
186 image->cache=AcquirePixelCache(0);
187 image->channel_mask=AllChannels;
188 image->channel_map=AcquirePixelChannelMap();
189 image->blob=CloneBlobInfo((BlobInfo *) NULL);
190#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
193 image->timestamp=time((time_t *) NULL);
195 time_limit=GetMagickResourceLimit(TimeResource);
196 if (time_limit != MagickResourceInfinity)
197 image->ttl=image->timestamp+(time_t) time_limit;
198 image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
199 != 0 ? MagickTrue : MagickFalse;
200 image->reference_count=1;
201 image->semaphore=AcquireSemaphoreInfo();
202 image->signature=MagickCoreSignature;
203 if (image_info == (ImageInfo *) NULL)
208 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
210 (void) CopyMagickString(image->filename,image_info->filename,
212 (void) CopyMagickString(image->magick_filename,image_info->filename,
214 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
215 if (image_info->size != (
char *) NULL)
217 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
218 image->columns=image->extract_info.width;
219 image->rows=image->extract_info.height;
220 image->offset=image->extract_info.x;
221 image->extract_info.x=0;
222 image->extract_info.y=0;
224 if (image_info->extract != (
char *) NULL)
229 (void) memset(&geometry,0,
sizeof(geometry));
230 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
231 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
233 image->extract_info=geometry;
234 Swap(image->columns,image->extract_info.width);
235 Swap(image->rows,image->extract_info.height);
238 image->compression=image_info->compression;
239 image->quality=image_info->quality;
240 image->endian=image_info->endian;
241 image->interlace=image_info->interlace;
242 image->units=image_info->units;
243 if (image_info->density != (
char *) NULL)
248 flags=ParseGeometry(image_info->density,&geometry_info);
249 if ((flags & RhoValue) != 0)
250 image->resolution.x=geometry_info.rho;
251 image->resolution.y=image->resolution.x;
252 if ((flags & SigmaValue) != 0)
253 image->resolution.y=geometry_info.sigma;
255 if (image_info->page != (
char *) NULL)
260 image->page=image->extract_info;
261 geometry=GetPageGeometry(image_info->page);
262 (void) ParseAbsoluteGeometry(geometry,&image->page);
263 geometry=DestroyString(geometry);
265 if (image_info->depth != 0)
266 image->depth=image_info->depth;
267 image->dither=image_info->dither;
268 image->matte_color=image_info->matte_color;
269 image->background_color=image_info->background_color;
270 image->border_color=image_info->border_color;
271 image->transparent_color=image_info->transparent_color;
272 image->ping=image_info->ping;
273 image->progress_monitor=image_info->progress_monitor;
274 image->client_data=image_info->client_data;
275 if (image_info->cache != (
void *) NULL)
276 ClonePixelCacheMethods(image->cache,image_info->cache);
280 (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 ((
double) image->delay > floor(geometry_info.rho+0.5))
294 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+
298 if ((flags & LessValue) != 0)
300 if ((
double) image->delay < floor(geometry_info.rho+0.5))
301 image->ticks_per_second=CastDoubleToSsizeT(floor(
302 geometry_info.sigma+0.5));
305 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+
307 if ((flags & SigmaValue) != 0)
308 image->ticks_per_second=CastDoubleToSsizeT(floor(geometry_info.sigma+
311 option=GetImageOption(image_info,
"dispose");
312 if (option != (
const char *) NULL)
313 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
336MagickExport ImageInfo *AcquireImageInfo(
void)
341 image_info=(ImageInfo *) AcquireCriticalMemory(
sizeof(*image_info));
342 GetImageInfo(image_info);
377MagickExport
void AcquireNextImage(
const ImageInfo *image_info,Image *image,
378 ExceptionInfo *exception)
383 assert(image != (Image *) NULL);
384 assert(image->signature == MagickCoreSignature);
385 if (IsEventLogging() != MagickFalse)
386 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
387 image->next=AcquireImage(image_info,exception);
388 if (GetNextImageInList(image) == (Image *) NULL)
390 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
392 if (image_info != (ImageInfo *) NULL)
393 (void) CopyMagickString(GetNextImageInList(image)->filename,
394 image_info->filename,MagickPathExtent);
395 DestroyBlob(GetNextImageInList(image));
396 image->next->blob=ReferenceBlob(image->blob);
397 image->next->endian=image->endian;
398 image->next->scene=image->scene+1;
399 image->next->previous=image;
434MagickExport Image *AppendImages(
const Image *images,
435 const MagickBooleanType stack,ExceptionInfo *exception)
437#define AppendImageTag "Append/Image"
449 homogeneous_colorspace,
478 assert(images != (Image *) NULL);
479 assert(images->signature == MagickCoreSignature);
480 assert(exception != (ExceptionInfo *) NULL);
481 assert(exception->signature == MagickCoreSignature);
482 if (IsEventLogging() != MagickFalse)
483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
484 alpha_trait=images->alpha_trait;
486 width=images->columns;
489 image_type=images->type;
490 homogeneous_colorspace=MagickTrue;
491 next=GetNextImageInList(images);
492 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
494 if (next->depth > depth)
496 if (next->type != images->type)
497 image_type=UndefinedType;
498 if (next->colorspace != images->colorspace)
499 homogeneous_colorspace=MagickFalse;
500 if (next->alpha_trait != UndefinedPixelTrait)
501 alpha_trait=BlendPixelTrait;
503 if (stack != MagickFalse)
505 if (next->columns > width)
510 width+=next->columns;
511 if (next->rows > height)
517 append_image=CloneImage(images,width,height,MagickTrue,exception);
518 if (append_image == (Image *) NULL)
519 return((Image *) NULL);
520 if (image_type != BilevelType)
522 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
524 append_image=DestroyImage(append_image);
525 return((Image *) NULL);
527 if (homogeneous_colorspace == MagickFalse)
528 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
530 append_image->depth=depth;
531 append_image->alpha_trait=alpha_trait;
532 append_image->page=images->page;
533 (void) SetImageBackgroundColor(append_image,exception);
538 append_view=AcquireAuthenticCacheView(append_image,exception);
539 for (n=0; n < (MagickOffsetType) number_images; n++)
547 SetGeometry(append_image,&geometry);
548 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
549 if (stack != MagickFalse)
550 x_offset-=geometry.x;
552 y_offset-=geometry.y;
553 image_view=AcquireVirtualCacheView(next,exception);
554#if defined(MAGICKCORE_OPENMP_SUPPORT)
555 #pragma omp parallel for schedule(static) shared(status) \
556 magick_number_threads(next,next,next->rows,2)
558 for (y=0; y < (ssize_t) next->rows; y++)
575 if (status == MagickFalse)
577 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
578 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
579 next->columns,1,exception);
580 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
585 GetPixelInfo(next,&pixel);
586 for (x=0; x < (ssize_t) next->columns; x++)
588 GetPixelInfoPixel(next,p,&pixel);
589 SetPixelViaPixelInfo(append_image,&pixel,q);
590 p+=(ptrdiff_t) GetPixelChannels(next);
591 q+=(ptrdiff_t) GetPixelChannels(append_image);
593 sync=SyncCacheViewAuthenticPixels(append_view,exception);
594 if (sync == MagickFalse)
597 image_view=DestroyCacheView(image_view);
598 if (stack == MagickFalse)
600 x_offset+=(ssize_t) next->columns;
606 y_offset+=(ssize_t) next->rows;
608 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
609 if (proceed == MagickFalse)
611 next=GetNextImageInList(next);
613 append_view=DestroyCacheView(append_view);
614 if (status == MagickFalse)
615 append_image=DestroyImage(append_image);
616 return(append_image);
643MagickExport ExceptionType CatchImageException(Image *image)
651 assert(image != (
const Image *) NULL);
652 assert(image->signature == MagickCoreSignature);
653 if (IsEventLogging() != MagickFalse)
654 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
655 exception=AcquireExceptionInfo();
656 CatchException(exception);
657 severity=exception->severity;
658 exception=DestroyExceptionInfo(exception);
695MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
697 return(ClipImagePath(image,
"#1",MagickTrue,exception));
700MagickExport MagickBooleanType ClipImagePath(Image *image,
const char *pathname,
701 const MagickBooleanType inside,ExceptionInfo *exception)
703#define ClipImagePathTag "ClipPath/Image"
718 assert(image != (
const Image *) NULL);
719 assert(image->signature == MagickCoreSignature);
720 assert(pathname != NULL);
721 if (IsEventLogging() != MagickFalse)
722 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
723 property=AcquireString(pathname);
724 (void) FormatLocaleString(property,MagickPathExtent,
"8BIM:1999,2998:%s",
726 value=GetImageProperty(image,property,exception);
727 property=DestroyString(property);
728 if (value == (
const char *) NULL)
730 ThrowFileException(exception,OptionError,
"NoClipPathDefined",
734 image_info=AcquireImageInfo();
735 (void) CopyMagickString(image_info->filename,image->filename,
737 (void) ConcatenateMagickString(image_info->filename,
"_",MagickPathExtent);
738 sanitized_pathname=SanitizeString(pathname);
739 (void) ConcatenateMagickString(image_info->filename,sanitized_pathname,
741 sanitized_pathname=DestroyString(sanitized_pathname);
742 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
743 image_info=DestroyImageInfo(image_info);
744 if (clip_mask == (Image *) NULL)
746 if (clip_mask->storage_class == PseudoClass)
748 (void) SyncImage(clip_mask,exception);
749 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
752 if (inside != MagickFalse)
753 (void) NegateImage(clip_mask,MagickFalse,exception);
754 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
755 "8BIM:1999,2998:%s\nPS",pathname);
756 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
757 clip_mask=DestroyImage(clip_mask);
800MagickExport Image *CloneImage(
const Image *image,
const size_t columns,
801 const size_t rows,
const MagickBooleanType detach,ExceptionInfo *exception)
816 assert(image != (
const Image *) NULL);
817 assert(image->signature == MagickCoreSignature);
818 assert(exception != (ExceptionInfo *) NULL);
819 assert(exception->signature == MagickCoreSignature);
820 if (IsEventLogging() != MagickFalse)
821 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
822 if ((image->columns == 0) || (image->rows == 0))
824 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
825 "NegativeOrZeroImageSize",
"`%s'",image->filename);
826 return((Image *) NULL);
828 clone_image=(Image *) AcquireCriticalMemory(
sizeof(*clone_image));
829 (void) memset(clone_image,0,
sizeof(*clone_image));
830 clone_image->signature=MagickCoreSignature;
831 clone_image->storage_class=image->storage_class;
832 clone_image->number_channels=image->number_channels;
833 clone_image->number_meta_channels=image->number_meta_channels;
834 clone_image->metacontent_extent=image->metacontent_extent;
835 clone_image->colorspace=image->colorspace;
836 clone_image->alpha_trait=image->alpha_trait;
837 clone_image->channels=image->channels;
838 clone_image->mask_trait=image->mask_trait;
839 clone_image->columns=image->columns;
840 clone_image->rows=image->rows;
841 clone_image->dither=image->dither;
842 clone_image->image_info=CloneImageInfo(image->image_info);
843 (void) CloneImageProfiles(clone_image,image);
844 (void) CloneImageProperties(clone_image,image);
845 (void) CloneImageArtifacts(clone_image,image);
846 GetTimerInfo(&clone_image->timer);
847 if (image->ascii85 != (
void *) NULL)
848 Ascii85Initialize(clone_image);
849 clone_image->extent=image->extent;
850 clone_image->magick_columns=image->magick_columns;
851 clone_image->magick_rows=image->magick_rows;
852 clone_image->type=image->type;
853 clone_image->channel_mask=image->channel_mask;
854 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
855 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
857 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
858 (void) CopyMagickString(clone_image->filename,image->filename,
860 clone_image->progress_monitor=image->progress_monitor;
861 clone_image->client_data=image->client_data;
862 clone_image->reference_count=1;
863 clone_image->next=image->next;
864 clone_image->previous=image->previous;
865 clone_image->list=NewImageList();
866 if (detach == MagickFalse)
867 clone_image->blob=ReferenceBlob(image->blob);
870 clone_image->next=NewImageList();
871 clone_image->previous=NewImageList();
872 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
874 clone_image->ping=image->ping;
875 clone_image->timestamp=image->timestamp;
876 clone_image->ttl=image->ttl;
877 clone_image->debug=image->debug;
878 clone_image->semaphore=AcquireSemaphoreInfo();
879 if (image->colormap != (PixelInfo *) NULL)
884 clone_image->colors=image->colors;
885 length=(size_t) image->colors;
886 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length+1,
887 sizeof(*clone_image->colormap));
888 if (clone_image->colormap == (PixelInfo *) NULL)
890 clone_image=DestroyImage(clone_image);
891 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
893 (void) memcpy(clone_image->colormap,image->colormap,length*
894 sizeof(*clone_image->colormap));
896 if ((columns == 0) || (rows == 0))
898 if (image->montage != (
char *) NULL)
899 (void) CloneString(&clone_image->montage,image->montage);
900 if (image->directory != (
char *) NULL)
901 (void) CloneString(&clone_image->directory,image->directory);
902 clone_image->cache=ReferencePixelCache(image->cache);
907 if (image->columns != 0)
908 scale_x=(double) columns/(
double) image->columns;
909 if (image->rows != 0)
910 scale_y=(double) rows/(
double) image->rows;
911 clone_image->page.width=(size_t) CastDoubleToSsizeT(floor(scale_x*
912 image->page.width+0.5));
913 clone_image->page.height=(size_t) CastDoubleToSsizeT(floor(scale_y*
914 image->page.height+0.5));
915 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
916 scale_x=scale_y=MagickMin(scale_x,scale_y);
917 clone_image->page.x=CastDoubleToSsizeT(ceil(scale_x*image->page.x-0.5));
918 clone_image->tile_offset.x=CastDoubleToSsizeT(ceil(scale_x*
919 image->tile_offset.x-0.5));
920 clone_image->page.y=CastDoubleToSsizeT(ceil(scale_y*image->page.y-0.5));
921 clone_image->tile_offset.y=CastDoubleToSsizeT(ceil(scale_y*
922 image->tile_offset.y-0.5));
923 clone_image->cache=ClonePixelCache(image->cache);
924 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
925 clone_image=DestroyImage(clone_image);
953MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
958 clone_info=AcquireImageInfo();
959 if (image_info == (ImageInfo *) NULL)
961 clone_info->compression=image_info->compression;
962 clone_info->temporary=image_info->temporary;
963 clone_info->adjoin=image_info->adjoin;
964 clone_info->antialias=image_info->antialias;
965 clone_info->scene=image_info->scene;
966 clone_info->number_scenes=image_info->number_scenes;
967 clone_info->depth=image_info->depth;
968 if (image_info->size != (
char *) NULL)
969 (void) CloneString(&clone_info->size,image_info->size);
970 if (image_info->extract != (
char *) NULL)
971 (void) CloneString(&clone_info->extract,image_info->extract);
972 if (image_info->scenes != (
char *) NULL)
973 (void) CloneString(&clone_info->scenes,image_info->scenes);
974 if (image_info->page != (
char *) NULL)
975 (void) CloneString(&clone_info->page,image_info->page);
976 clone_info->interlace=image_info->interlace;
977 clone_info->endian=image_info->endian;
978 clone_info->units=image_info->units;
979 clone_info->quality=image_info->quality;
980 if (image_info->sampling_factor != (
char *) NULL)
981 (void) CloneString(&clone_info->sampling_factor,
982 image_info->sampling_factor);
983 if (image_info->server_name != (
char *) NULL)
984 (void) CloneString(&clone_info->server_name,image_info->server_name);
985 if (image_info->font != (
char *) NULL)
986 (void) CloneString(&clone_info->font,image_info->font);
987 if (image_info->texture != (
char *) NULL)
988 (void) CloneString(&clone_info->texture,image_info->texture);
989 if (image_info->density != (
char *) NULL)
990 (void) CloneString(&clone_info->density,image_info->density);
991 clone_info->pointsize=image_info->pointsize;
992 clone_info->fuzz=image_info->fuzz;
993 clone_info->matte_color=image_info->matte_color;
994 clone_info->background_color=image_info->background_color;
995 clone_info->border_color=image_info->border_color;
996 clone_info->transparent_color=image_info->transparent_color;
997 clone_info->dither=image_info->dither;
998 clone_info->monochrome=image_info->monochrome;
999 clone_info->colorspace=image_info->colorspace;
1000 clone_info->type=image_info->type;
1001 clone_info->orientation=image_info->orientation;
1002 clone_info->ping=image_info->ping;
1003 clone_info->verbose=image_info->verbose;
1004 clone_info->progress_monitor=image_info->progress_monitor;
1005 clone_info->client_data=image_info->client_data;
1006 clone_info->cache=image_info->cache;
1007 if (image_info->cache != (
void *) NULL)
1008 clone_info->cache=ReferencePixelCache(image_info->cache);
1009 if (image_info->profile != (
void *) NULL)
1010 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1011 image_info->profile);
1012 SetImageInfoFile(clone_info,image_info->file);
1013 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1014 clone_info->stream=image_info->stream;
1015 clone_info->custom_stream=image_info->custom_stream;
1016 (void) CopyMagickString(clone_info->magick,image_info->magick,
1018 (void) CopyMagickString(clone_info->unique,image_info->unique,
1020 (void) CopyMagickString(clone_info->filename,image_info->filename,
1022 clone_info->channel=image_info->channel;
1023 (void) CloneImageOptions(clone_info,image_info);
1024 clone_info->debug=image_info->debug;
1025 clone_info->signature=image_info->signature;
1062MagickExport MagickBooleanType CopyImagePixels(Image *image,
1063 const Image *source_image,
const RectangleInfo *geometry,
1064 const OffsetInfo *offset,ExceptionInfo *exception)
1066#define CopyImageTag "Copy/Image"
1081 assert(image != (Image *) NULL);
1082 assert(source_image != (Image *) NULL);
1083 assert(geometry != (RectangleInfo *) NULL);
1084 assert(offset != (OffsetInfo *) NULL);
1085 if (IsEventLogging() != MagickFalse)
1086 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1087 if ((offset->x < 0) || (offset->y < 0) ||
1088 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1089 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1090 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1092 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1093 return(MagickFalse);
1099 source_view=AcquireVirtualCacheView(source_image,exception);
1100 image_view=AcquireAuthenticCacheView(image,exception);
1101#if defined(MAGICKCORE_OPENMP_SUPPORT)
1102 #pragma omp parallel for schedule(static) shared(progress,status) \
1103 magick_number_threads(image,source_image,geometry->height,2)
1105 for (y=0; y < (ssize_t) geometry->height; y++)
1119 if (status == MagickFalse)
1121 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1122 geometry->width,1,exception);
1123 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1124 geometry->width,1,exception);
1125 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1130 for (x=0; x < (ssize_t) geometry->width; x++)
1135 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1137 PixelChannel channel = GetPixelChannelChannel(image,i);
1138 PixelTrait traits = GetPixelChannelTraits(image,channel);
1139 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1140 if ((traits == UndefinedPixelTrait) ||
1141 ((traits & UpdatePixelTrait) == 0) ||
1142 (source_traits == UndefinedPixelTrait))
1144 SetPixelChannel(image,channel,p[i],q);
1146 p+=(ptrdiff_t) GetPixelChannels(source_image);
1147 q+=(ptrdiff_t) GetPixelChannels(image);
1149 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1150 if (sync == MagickFalse)
1152 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1157#if defined(MAGICKCORE_OPENMP_SUPPORT)
1161 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1162 if (proceed == MagickFalse)
1166 source_view=DestroyCacheView(source_view);
1167 image_view=DestroyCacheView(image_view);
1194MagickExport Image *DestroyImage(Image *image)
1202 assert(image != (Image *) NULL);
1203 assert(image->signature == MagickCoreSignature);
1204 if (IsEventLogging() != MagickFalse)
1205 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1206 destroy=MagickFalse;
1207 LockSemaphoreInfo(image->semaphore);
1208 image->reference_count--;
1209 if (image->reference_count == 0)
1211 UnlockSemaphoreInfo(image->semaphore);
1212 if (destroy == MagickFalse)
1213 return((Image *) NULL);
1217 DestroyImagePixels(image);
1218 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1219 if (image->montage != (
char *) NULL)
1220 image->montage=DestroyString(image->montage);
1221 if (image->directory != (
char *) NULL)
1222 image->directory=DestroyString(image->directory);
1223 if (image->colormap != (PixelInfo *) NULL)
1224 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1225 if (image->geometry != (
char *) NULL)
1226 image->geometry=DestroyString(image->geometry);
1227 DestroyImageProfiles(image);
1228 DestroyImageProperties(image);
1229 DestroyImageArtifacts(image);
1230 if (image->ascii85 != (Ascii85Info *) NULL)
1231 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1232 if (image->image_info != (ImageInfo *) NULL)
1233 image->image_info=DestroyImageInfo(image->image_info);
1236 RelinquishSemaphoreInfo(&image->semaphore);
1237 image->signature=(~MagickCoreSignature);
1238 image=(Image *) RelinquishMagickMemory(image);
1265MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1267 assert(image_info != (ImageInfo *) NULL);
1268 assert(image_info->signature == MagickCoreSignature);
1269 if (IsEventLogging() != MagickFalse)
1270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1271 image_info->filename);
1272 if (image_info->size != (
char *) NULL)
1273 image_info->size=DestroyString(image_info->size);
1274 if (image_info->extract != (
char *) NULL)
1275 image_info->extract=DestroyString(image_info->extract);
1276 if (image_info->scenes != (
char *) NULL)
1277 image_info->scenes=DestroyString(image_info->scenes);
1278 if (image_info->page != (
char *) NULL)
1279 image_info->page=DestroyString(image_info->page);
1280 if (image_info->sampling_factor != (
char *) NULL)
1281 image_info->sampling_factor=DestroyString(
1282 image_info->sampling_factor);
1283 if (image_info->server_name != (
char *) NULL)
1284 image_info->server_name=DestroyString(
1285 image_info->server_name);
1286 if (image_info->font != (
char *) NULL)
1287 image_info->font=DestroyString(image_info->font);
1288 if (image_info->texture != (
char *) NULL)
1289 image_info->texture=DestroyString(image_info->texture);
1290 if (image_info->density != (
char *) NULL)
1291 image_info->density=DestroyString(image_info->density);
1292 if (image_info->cache != (
void *) NULL)
1293 image_info->cache=DestroyPixelCache(image_info->cache);
1294 if (image_info->profile != (StringInfo *) NULL)
1295 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1296 image_info->profile);
1297 DestroyImageOptions(image_info);
1298 image_info->signature=(~MagickCoreSignature);
1299 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1327MagickExport
void DisassociateImageStream(Image *image)
1329 assert(image != (Image *) NULL);
1330 assert(image->signature == MagickCoreSignature);
1331 if (IsEventLogging() != MagickFalse)
1332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1333 DisassociateBlob(image);
1358MagickExport
void GetImageInfo(ImageInfo *image_info)
1366 assert(image_info != (ImageInfo *) NULL);
1367 if (IsEventLogging() != MagickFalse)
1368 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1369 (void) memset(image_info,0,
sizeof(*image_info));
1370 image_info->adjoin=MagickTrue;
1371 image_info->interlace=NoInterlace;
1372 image_info->channel=AllChannels;
1373 image_info->quality=UndefinedCompressionQuality;
1374 image_info->antialias=MagickTrue;
1375 image_info->dither=MagickTrue;
1376 image_info->depth=0;
1377 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1378 if (synchronize != (
const char *) NULL)
1380 image_info->synchronize=IsStringTrue(synchronize);
1381 synchronize=DestroyString(synchronize);
1383 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1384 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1385 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1386 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1387 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1389 image_info->signature=MagickCoreSignature;
1414MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1416 return(image_info->file);
1444MagickExport Image *GetImageMask(
const Image *image,
const PixelMask type,
1445 ExceptionInfo *exception)
1463 assert(image != (Image *) NULL);
1464 assert(image->signature == MagickCoreSignature);
1465 if (IsEventLogging() != MagickFalse)
1466 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1471 if ((image->channels & ReadMaskChannel) == 0)
1472 return((Image *) NULL);
1475 case WritePixelMask:
1477 if ((image->channels & WriteMaskChannel) == 0)
1478 return((Image *) NULL);
1483 if ((image->channels & CompositeMaskChannel) == 0)
1484 return((Image *) NULL);
1488 mask_image=AcquireImage((ImageInfo *) NULL,exception);
1489 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1490 if (status == MagickFalse)
1491 return(DestroyImage(mask_image));
1493 mask_image->alpha_trait=UndefinedPixelTrait;
1494 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1495 image_view=AcquireVirtualCacheView(image,exception);
1496 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1497#if defined(MAGICKCORE_OPENMP_SUPPORT)
1498 #pragma omp parallel for schedule(static) shared(status) \
1499 magick_number_threads(image,image,image->rows,2)
1501 for (y=0; y < (ssize_t) image->rows; y++)
1512 if (status == MagickFalse)
1514 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1515 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1517 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1522 for (x=0; x < (ssize_t) image->columns; x++)
1528 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1531 case WritePixelMask:
1533 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1538 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1542 p+=(ptrdiff_t) GetPixelChannels(image);
1543 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1545 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1548 mask_view=DestroyCacheView(mask_view);
1549 image_view=DestroyCacheView(image_view);
1550 if (status == MagickFalse)
1551 mask_image=DestroyImage(mask_image);
1577MagickExport ssize_t GetImageReferenceCount(Image *image)
1582 assert(image != (Image *) NULL);
1583 assert(image->signature == MagickCoreSignature);
1584 if (IsEventLogging() != MagickFalse)
1585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1586 LockSemaphoreInfo(image->semaphore);
1587 reference_count=image->reference_count;
1588 UnlockSemaphoreInfo(image->semaphore);
1589 return(reference_count);
1616MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1618 assert(image != (Image *) NULL);
1619 assert(image->signature == MagickCoreSignature);
1620 if (IsEventLogging() != MagickFalse)
1621 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1622 return(GetPixelCacheVirtualMethod(image));
1661static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1665 specifier = end[-1];
1668 length = (size_t) (end-start);
1673 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1674 return(MagickFalse);
1675 if ((length == 1) && (*start == specifier))
1684 if ((length >= 3) && (start[1] ==
'0'))
1685 return(MagickFalse);
1688 for ( ; i < (length-1); i++)
1689 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1690 return(MagickFalse);
1693 return(MagickFalse);
1696MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1697 Image *image,
const char *format,
int value,
char *filename,
1698 ExceptionInfo *exception)
1703 pattern[MagickPathExtent];
1708 assert(format != (
const char *) NULL);
1709 assert(filename != (
char *) NULL);
1710 literal=(
char *) GetImageRegistry(StringRegistryType,
"filename:literal",
1712 if (IsStringTrue(literal) != MagickFalse)
1714 if (literal != (
char *) NULL)
1715 literal=DestroyString(literal);
1716 (void) CopyMagickString(filename,format,MagickPathExtent);
1717 return(strlen(filename));
1719 if (literal != (
char *) NULL)
1720 literal=DestroyString(literal);
1721 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1739 specifier_start=cursor;
1740 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1742 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1745 *specifier_end = cursor+1;
1747 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1750 format_specifier[MagickPathExtent];
1753 length = (size_t) (cursor-specifier_start),
1759 (void) snprintf(format_specifier,
sizeof(format_specifier),
1760 "%%%.*s%c",(
int) length,specifier_start,*cursor);
1761 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1763 pattern_length=strlen(pattern);
1764 if ((count <= 0) || ((
size_t) count != pattern_length))
1766 if ((p-filename+pattern_length) >= MagickPathExtent)
1768 (void) CopyMagickString(p,pattern,(
size_t) (MagickPathExtent-
1787 *end = strchr(cursor,
']'),
1788 *option = (
const char *) NULL;
1794 if (end == (
const char *) NULL)
1796 extent=(size_t) (end-cursor-1);
1797 if (extent >=
sizeof(pattern))
1799 (void) CopyMagickString(pattern,cursor+1,extent+1);
1800 pattern[extent]=
'\0';
1803 option=GetImageProperty(image,pattern,exception);
1804 if (option == (
const char *) NULL)
1805 option=GetImageArtifact(image,pattern);
1807 if ((option == (
const char *) NULL) &&
1808 (image_info != (ImageInfo *) NULL))
1809 option=GetImageOption(image_info,pattern);
1810 if (option == (
const char *) NULL)
1812 option_length=strlen(option);
1813 if ((p-filename+option_length) >= MagickPathExtent)
1815 (void) CopyMagickString(p,option,(
size_t) (MagickPathExtent-
1825 if ((p-filename+1) >= MagickPathExtent)
1830 return(strlen(filename));
1860MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1861 ExceptionInfo *exception)
1863#if !defined(MAGICKCORE_HDRI_SUPPORT)
1866 return(MagickFalse);
1877 assert(image != (Image *) NULL);
1878 assert(image->signature == MagickCoreSignature);
1879 if (IsEventLogging() != MagickFalse)
1880 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1881 image_view=AcquireVirtualCacheView(image,exception);
1882#if defined(MAGICKCORE_OPENMP_SUPPORT)
1883 #pragma omp parallel for schedule(static) shared(hdri) \
1884 magick_number_threads(image,image,image->rows,2)
1886 for (y=0; y < (ssize_t) image->rows; y++)
1894 if (hdri != MagickFalse)
1896 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1897 if (p == (
const Quantum *) NULL)
1899 for (x=0; x < (ssize_t) image->columns; x++)
1904 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1912 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1913 if (traits == UndefinedPixelTrait)
1915 pixel=(double) p[i];
1916 if ((pixel < 0.0) || (pixel > (
double) QuantumRange) ||
1917 (pixel != (
double) ((QuantumAny) pixel)))
1923 if (hdri != MagickFalse)
1925 p+=(ptrdiff_t) GetPixelChannels(image);
1928 image_view=DestroyCacheView(image_view);
1956MagickExport MagickBooleanType IsImageObject(
const Image *image)
1961 assert(image != (Image *) NULL);
1962 if (IsEventLogging() != MagickFalse)
1963 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1964 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1965 if (p->signature != MagickCoreSignature)
1966 return(MagickFalse);
1993MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1996 magick[MagickPathExtent],
1997 filename[MagickPathExtent];
2002 assert(image != (Image *) NULL);
2003 assert(image->signature == MagickCoreSignature);
2004 if (IsEventLogging() != MagickFalse)
2005 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2006 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
2007 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
2008 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2010 if (p->taint != MagickFalse)
2012 if (LocaleCompare(p->magick,magick) != 0)
2014 if (LocaleCompare(p->filename,filename) != 0)
2017 return(MagickFalse);
2046MagickExport MagickBooleanType ModifyImage(Image **image,
2047 ExceptionInfo *exception)
2052 assert(image != (Image **) NULL);
2053 assert(*image != (Image *) NULL);
2054 assert((*image)->signature == MagickCoreSignature);
2055 if (IsEventLogging() != MagickFalse)
2056 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2057 if (GetImageReferenceCount(*image) <= 1)
2059 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2060 LockSemaphoreInfo((*image)->semaphore);
2061 (*image)->reference_count--;
2062 UnlockSemaphoreInfo((*image)->semaphore);
2100MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2101 const size_t width,
const size_t height,
const PixelInfo *background,
2102 ExceptionInfo *exception)
2116 assert(image_info != (
const ImageInfo *) NULL);
2117 assert(image_info->signature == MagickCoreSignature);
2118 assert(background != (
const PixelInfo *) NULL);
2119 if (IsEventLogging() != MagickFalse)
2120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2121 image=AcquireImage(image_info,exception);
2122 image->columns=width;
2124 image->colorspace=background->colorspace;
2125 image->alpha_trait=background->alpha_trait;
2126 image->fuzz=background->fuzz;
2127 image->depth=background->depth;
2129 image_view=AcquireAuthenticCacheView(image,exception);
2130#if defined(MAGICKCORE_OPENMP_SUPPORT)
2131 #pragma omp parallel for schedule(static) shared(status) \
2132 magick_number_threads(image,image,image->rows,2)
2134 for (y=0; y < (ssize_t) image->rows; y++)
2142 if (status == MagickFalse)
2144 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2145 if (q == (Quantum *) NULL)
2150 for (x=0; x < (ssize_t) image->columns; x++)
2152 SetPixelViaPixelInfo(image,background,q);
2153 q+=(ptrdiff_t) GetPixelChannels(image);
2155 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2158 image_view=DestroyCacheView(image_view);
2159 if (status == MagickFalse)
2160 image=DestroyImage(image);
2187MagickExport Image *ReferenceImage(Image *image)
2189 assert(image != (Image *) NULL);
2190 assert(image->signature == MagickCoreSignature);
2191 if (IsEventLogging() != MagickFalse)
2192 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2193 LockSemaphoreInfo(image->semaphore);
2194 image->reference_count++;
2195 UnlockSemaphoreInfo(image->semaphore);
2223MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2231 assert(image != (Image *) NULL);
2232 assert(image->signature == MagickCoreSignature);
2233 if (IsEventLogging() != MagickFalse)
2234 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2235 flags=ParseAbsoluteGeometry(page,&geometry);
2236 if ((flags & WidthValue) != 0)
2238 if ((flags & HeightValue) == 0)
2239 geometry.height=geometry.width;
2240 image->page.width=geometry.width;
2241 image->page.height=geometry.height;
2243 if ((flags & AspectValue) != 0)
2245 if ((flags & XValue) != 0)
2246 image->page.x+=geometry.x;
2247 if ((flags & YValue) != 0)
2248 image->page.y+=geometry.y;
2252 if ((flags & XValue) != 0)
2254 image->page.x=geometry.x;
2255 if ((image->page.width == 0) && (geometry.x > 0))
2256 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2258 if ((flags & YValue) != 0)
2260 image->page.y=geometry.y;
2261 if ((image->page.height == 0) && (geometry.y > 0))
2262 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2294MagickExport MagickBooleanType ResetImagePixels(Image *image,
2295 ExceptionInfo *exception)
2312 assert(image != (Image *) NULL);
2313 assert(image->signature == MagickCoreSignature);
2314 if (IsEventLogging() != MagickFalse)
2315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2316 pixels=AcquirePixelCachePixels(image,&length,exception);
2317 if (pixels != (
void *) NULL)
2322 (void) memset(pixels,0,length);
2329 image_view=AcquireAuthenticCacheView(image,exception);
2330#if defined(MAGICKCORE_OPENMP_SUPPORT)
2331 #pragma omp parallel for schedule(static) shared(status) \
2332 magick_number_threads(image,image,image->rows,2)
2334 for (y=0; y < (ssize_t) image->rows; y++)
2342 if (status == MagickFalse)
2344 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2345 if (q == (Quantum *) NULL)
2350 for (x=0; x < (ssize_t) image->columns; x++)
2352 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2353 q+=(ptrdiff_t) GetPixelChannels(image);
2355 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2358 image_view=DestroyCacheView(image_view);
2390MagickExport MagickBooleanType SetImageAlpha(Image *image,
const Quantum alpha,
2391 ExceptionInfo *exception)
2405 assert(image != (Image *) NULL);
2406 assert(image->signature == MagickCoreSignature);
2407 if (IsEventLogging() != MagickFalse)
2408 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2409 image->alpha_trait=BlendPixelTrait;
2411 original_mask=image->mask_trait;
2412 image->mask_trait=UndefinedPixelTrait;
2414 image_view=AcquireAuthenticCacheView(image,exception);
2415#if defined(MAGICKCORE_OPENMP_SUPPORT)
2416 #pragma omp parallel for schedule(static) shared(status) \
2417 magick_number_threads(image,image,image->rows,2)
2419 for (y=0; y < (ssize_t) image->rows; y++)
2427 if (status == MagickFalse)
2429 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2430 if (q == (Quantum *) NULL)
2435 for (x=0; x < (ssize_t) image->columns; x++)
2437 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2438 SetPixelAlpha(image,alpha,q);
2439 q+=(ptrdiff_t) GetPixelChannels(image);
2441 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2444 image_view=DestroyCacheView(image_view);
2445 image->mask_trait=original_mask;
2476MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2477 ExceptionInfo *exception)
2491 assert(image != (Image *) NULL);
2492 assert(image->signature == MagickCoreSignature);
2493 if (IsEventLogging() != MagickFalse)
2494 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2495 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2496 return(MagickFalse);
2497 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2498 ((image->alpha_trait & BlendPixelTrait) == 0))
2499 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2500 ConformPixelInfo(image,&image->background_color,&background,exception);
2505 image_view=AcquireAuthenticCacheView(image,exception);
2506#if defined(MAGICKCORE_OPENMP_SUPPORT)
2507 #pragma omp parallel for schedule(static) shared(status) \
2508 magick_number_threads(image,image,image->rows,2)
2510 for (y=0; y < (ssize_t) image->rows; y++)
2518 if (status == MagickFalse)
2520 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2521 if (q == (Quantum *) NULL)
2526 for (x=0; x < (ssize_t) image->columns; x++)
2528 SetPixelViaPixelInfo(image,&background,q);
2529 q+=(ptrdiff_t) GetPixelChannels(image);
2531 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2534 image_view=DestroyCacheView(image_view);
2564MagickExport ChannelType SetImageChannelMask(Image *image,
2565 const ChannelType channel_mask)
2567 return(SetPixelChannelMask(image,channel_mask));
2597MagickExport MagickBooleanType SetImageColor(Image *image,
2598 const PixelInfo *color,ExceptionInfo *exception)
2609 assert(image != (Image *) NULL);
2610 assert(image->signature == MagickCoreSignature);
2611 assert(color != (
const PixelInfo *) NULL);
2612 if (IsEventLogging() != MagickFalse)
2613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2614 image->colorspace=color->colorspace;
2615 image->alpha_trait=color->alpha_trait;
2616 image->fuzz=color->fuzz;
2617 image->depth=color->depth;
2619 image_view=AcquireAuthenticCacheView(image,exception);
2620#if defined(MAGICKCORE_OPENMP_SUPPORT)
2621 #pragma omp parallel for schedule(static) shared(status) \
2622 magick_number_threads(image,image,image->rows,2)
2624 for (y=0; y < (ssize_t) image->rows; y++)
2632 if (status == MagickFalse)
2634 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2635 if (q == (Quantum *) NULL)
2640 for (x=0; x < (ssize_t) image->columns; x++)
2642 SetPixelViaPixelInfo(image,color,q);
2643 q+=(ptrdiff_t) GetPixelChannels(image);
2645 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2648 image_view=DestroyCacheView(image_view);
2680MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2681 const ClassType storage_class,ExceptionInfo *exception)
2683 assert(image != (Image *) NULL);
2684 assert(image->signature == MagickCoreSignature);
2685 assert(exception != (ExceptionInfo *) NULL);
2686 assert(exception->signature == MagickCoreSignature);
2687 if (IsEventLogging() != MagickFalse)
2688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2689 image->storage_class=storage_class;
2690 return(SyncImagePixelCache(image,exception));
2722MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2723 const size_t rows,ExceptionInfo *exception)
2725 if ((columns == 0) || (rows == 0))
2726 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2727 if ((columns > (
size_t) MAGICK_SSIZE_MAX) ||
2728 (rows > (
size_t) MAGICK_SSIZE_MAX))
2729 ThrowBinaryException(ImageError,
"ImageSizeLimitExceeded",image->filename);
2730 image->columns=columns;
2732 if (image->depth == 0)
2735 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2736 "ImageDepthNotSupported",
"`%s'",image->filename);
2738 if (image->depth > (8*
sizeof(MagickSizeType)))
2740 image->depth=8*
sizeof(MagickSizeType);
2741 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2742 "ImageDepthNotSupported",
"`%s'",image->filename);
2744 return(SyncImagePixelCache(image,exception));
2782static const MagickInfo *SetImageInfoFromExtension(ImageInfo *image_info,
2783 const char *component,
char *magic,ExceptionInfo *exception)
2795 *format_type_formats[] =
2819 (void) CopyMagickString(magic,component,MagickPathExtent);
2824 format_type=UndefinedFormatType;
2825 magick_info=GetMagickInfo(magic,exception);
2826 if ((magick_info != (
const MagickInfo *) NULL) &&
2827 (magick_info->format_type != UndefinedFormatType))
2828 format_type=magick_info->format_type;
2830 while ((format_type == UndefinedFormatType) &&
2831 (format_type_formats[i] != (
char *) NULL))
2833 if ((*magic == *format_type_formats[i]) &&
2834 (LocaleCompare(magic,format_type_formats[i]) == 0))
2835 format_type=ExplicitFormatType;
2838 if (format_type == UndefinedFormatType)
2839 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2841 if (format_type == ExplicitFormatType)
2843 image_info->affirm=MagickTrue;
2844 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2846 if (LocaleCompare(magic,
"RGB") == 0)
2847 image_info->affirm=MagickFalse;
2848 return(magick_info);
2851MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2852 const unsigned int frames,ExceptionInfo *exception)
2855 component[MagickPathExtent],
2856 magic[MagickPathExtent],
2857 path[MagickPathExtent],
2884 assert(image_info != (ImageInfo *) NULL);
2885 assert(image_info->signature == MagickCoreSignature);
2886 if (IsEventLogging() != MagickFalse)
2887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2888 image_info->filename);
2890 GetPathComponent(image_info->filename,SubimagePath,component);
2891 if (*component !=
'\0')
2896 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2898 if (IsGeometry(component) != MagickFalse)
2899 (void) CloneString(&image_info->extract,component);
2907 (void) CloneString(&image_info->scenes,component);
2908 image_info->scene=StringToUnsignedLong(image_info->scenes);
2909 image_info->number_scenes=image_info->scene;
2910 p=image_info->scenes;
2911 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2913 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2915 first=(size_t) strtol(p,&q,10);
2917 while (isspace((
int) ((
unsigned char) *q)) != 0)
2920 last=(size_t) strtol(q+1,&q,10);
2923 if (first < image_info->scene)
2924 image_info->scene=first;
2925 if (last > image_info->number_scenes)
2926 image_info->number_scenes=last;
2929 image_info->number_scenes-=image_info->scene-1;
2933 if (*image_info->magick ==
'\0')
2934 GetPathComponent(image_info->filename,ExtensionPath,component);
2935 if (*component !=
'\0')
2940 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2941 GetPathComponent(path,ExtensionPath,component);
2943 image_info->affirm=MagickFalse;
2944 sans_exception=AcquireExceptionInfo();
2945 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2946 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2952 GetPathComponent(image_info->filename,MagickPath,magic);
2955 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2956 magick_info=GetMagickInfo(magic,sans_exception);
2957 if ((magick_info != (
const MagickInfo *) NULL) &&
2958 (magick_info->format_type == ExplicitFormatType))
2959 image_info->affirm=MagickTrue;
2961 GetPathComponent(image_info->filename,CanonicalPath,component);
2963 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2964 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2975 magick_info=GetMagickInfo(magic,sans_exception);
2976 delegate_info=(
const DelegateInfo *) NULL;
2977 if (magick_info == (
const MagickInfo *) NULL)
2979 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2980 if (delegate_info == (
const DelegateInfo *) NULL)
2981 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2982 if ((delegate_info == (
const DelegateInfo *) NULL) &&
2983 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2988 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2992 if (((magick_info != (
const MagickInfo *) NULL) ||
2993 (delegate_info != (
const DelegateInfo *) NULL)) &&
2994 (IsMagickConflict(magic) == MagickFalse))
2996 char *literal = (
char *) GetImageRegistry(StringRegistryType,
2997 "filename:literal",exception);
2998 image_info->affirm=MagickTrue;
2999 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
3000 GetPathComponent(image_info->filename,CanonicalPath,component);
3001 if (IsStringTrue(literal) != MagickFalse)
3002 GetPathComponent(image_info->filename,SubcanonicalPath,component);
3003 (void) CopyMagickString(image_info->filename,component,
3005 if (literal != (
char *) NULL)
3006 literal=DestroyString(literal);
3009 sans_exception=DestroyExceptionInfo(sans_exception);
3010 if ((magick_info == (
const MagickInfo *) NULL) ||
3011 (GetMagickEndianSupport(magick_info) == MagickFalse))
3012 image_info->endian=UndefinedEndian;
3013 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3018 (void) InterpretImageFilename(image_info,(Image *) NULL,
3019 image_info->filename,(
int) image_info->scene,component,exception);
3020 if ((LocaleCompare(component,image_info->filename) != 0) &&
3021 (strchr(component,
'%') == (
char *) NULL))
3022 image_info->adjoin=MagickFalse;
3024 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3029 magick_info=GetMagickInfo(magic,exception);
3030 if (magick_info != (
const MagickInfo *) NULL)
3031 if (GetMagickAdjoin(magick_info) == MagickFalse)
3032 image_info->adjoin=MagickFalse;
3034 if (image_info->affirm != MagickFalse)
3047 magick_size=GetMagicPatternExtent(exception);
3048 if (magick_size == 0)
3049 return(MagickFalse);
3050 image=AcquireImage(image_info,exception);
3051 (void) CopyMagickString(image->filename,image_info->filename,
3053 sans_exception=AcquireExceptionInfo();
3054 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3055 sans_exception=DestroyExceptionInfo(sans_exception);
3056 if (status == MagickFalse)
3058 image=DestroyImage(image);
3059 return(MagickFalse);
3061 if ((IsBlobSeekable(image) == MagickFalse) ||
3062 (IsBlobExempt(image) != MagickFalse))
3068 status=ImageToFile(image,component,exception);
3069 if (CloseBlob(image) == MagickFalse)
3071 if (status == MagickFalse)
3073 (void) RelinquishUniqueFileResource(component);
3074 image=DestroyImage(image);
3075 return(MagickFalse);
3077 SetImageInfoFile(image_info,(FILE *) NULL);
3078 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3079 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3080 if (status == MagickFalse)
3082 (void) RelinquishUniqueFileResource(component);
3083 image=DestroyImage(image);
3084 return(MagickFalse);
3086 (void) CopyMagickString(image_info->filename,component,
3088 image_info->temporary=MagickTrue;
3090 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3091 if (magick == (
unsigned char *) NULL)
3093 (void) CloseBlob(image);
3094 image=DestroyImage(image);
3095 return(MagickFalse);
3097 (void) memset(magick,0,magick_size);
3098 count=ReadBlob(image,magick_size,magick);
3099 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3100 (void) CloseBlob(image);
3101 image=DestroyImage(image);
3105 sans_exception=AcquireExceptionInfo();
3106 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3107 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3108 if ((magic_info != (
const MagicInfo *) NULL) &&
3109 (GetMagicName(magic_info) != (
char *) NULL))
3114 if ((magick_info != (
const MagickInfo *) NULL) &&
3115 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3116 (LocaleCompare(magick_info->magick_module,GetMagicName(
3118 (void) CopyMagickString(image_info->magick,magick_info->name,
3122 (void) CopyMagickString(image_info->magick,GetMagicName(
3123 magic_info),MagickPathExtent);
3124 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3126 if ((magick_info == (
const MagickInfo *) NULL) ||
3127 (GetMagickEndianSupport(magick_info) == MagickFalse))
3128 image_info->endian=UndefinedEndian;
3129 sans_exception=DestroyExceptionInfo(sans_exception);
3132 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3133 if ((magick_info == (
const MagickInfo *) NULL) ||
3134 (GetMagickEndianSupport(magick_info) == MagickFalse))
3135 image_info->endian=UndefinedEndian;
3136 sans_exception=DestroyExceptionInfo(sans_exception);
3168MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3169 const size_t length)
3171 assert(image_info != (ImageInfo *) NULL);
3172 assert(image_info->signature == MagickCoreSignature);
3173 if (IsEventLogging() != MagickFalse)
3174 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3175 image_info->filename);
3176 image_info->blob=(
void *) blob;
3177 image_info->length=length;
3205MagickExport
void SetImageInfoCustomStream(ImageInfo *image_info,
3206 CustomStreamInfo *custom_stream)
3208 assert(image_info != (ImageInfo *) NULL);
3209 assert(image_info->signature == MagickCoreSignature);
3210 if (IsEventLogging() != MagickFalse)
3211 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3212 image_info->filename);
3213 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3240MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3242 assert(image_info != (ImageInfo *) NULL);
3243 assert(image_info->signature == MagickCoreSignature);
3244 if (IsEventLogging() != MagickFalse)
3245 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3246 image_info->filename);
3247 image_info->file=file;
3280MagickExport MagickBooleanType SetImageMask(Image *image,
const PixelMask type,
3281 const Image *mask,ExceptionInfo *exception)
3296 assert(image != (Image *) NULL);
3297 if (IsEventLogging() != MagickFalse)
3298 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3299 assert(image->signature == MagickCoreSignature);
3300 image->mask_trait=UndefinedPixelTrait;
3301 if (mask == (
const Image *) NULL)
3307 image->channels=(ChannelType) ((
unsigned int) image->channels &
3308 (
unsigned int) ~ReadMaskChannel);
3311 case WritePixelMask:
3313 image->channels=(ChannelType) ((
unsigned int) image->channels &
3314 (
unsigned int) ~WriteMaskChannel);
3319 image->channels=(ChannelType) ((
unsigned int) image->channels &
3320 (
unsigned int) ~CompositeMaskChannel);
3324 return(SyncImagePixelCache(image,exception));
3330 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3333 case WritePixelMask:
3335 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3340 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3344 if (SyncImagePixelCache(image,exception) == MagickFalse)
3345 return(MagickFalse);
3347 mask_view=AcquireVirtualCacheView(mask,exception);
3348 image_view=AcquireAuthenticCacheView(image,exception);
3349#if defined(MAGICKCORE_OPENMP_SUPPORT)
3350 #pragma omp parallel for schedule(static) shared(status) \
3351 magick_number_threads(mask,image,image->rows,2)
3353 for (y=0; y < (ssize_t) image->rows; y++)
3364 if (status == MagickFalse)
3366 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3367 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3368 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3373 for (x=0; x < (ssize_t) image->columns; x++)
3379 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3380 intensity=GetPixelIntensity(mask,p);
3385 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3388 case WritePixelMask:
3390 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3395 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3399 p+=(ptrdiff_t) GetPixelChannels(mask);
3400 q+=(ptrdiff_t) GetPixelChannels(image);
3402 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3405 mask_view=DestroyCacheView(mask_view);
3406 image_view=DestroyCacheView(image_view);
3407 image->mask_trait=UpdatePixelTrait;
3441MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3442 const PixelMask type,
const RectangleInfo *region,ExceptionInfo *exception)
3456 assert(image != (Image *) NULL);
3457 assert(image->signature == MagickCoreSignature);
3458 if (IsEventLogging() != MagickFalse)
3459 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3460 image->mask_trait=UndefinedPixelTrait;
3461 if (region == (
const RectangleInfo *) NULL)
3467 image->channels=(ChannelType) ((
unsigned int) image->channels &
3468 (
unsigned int) ~ReadMaskChannel);
3471 case WritePixelMask:
3473 image->channels=(ChannelType) ((
unsigned int) image->channels &
3474 (
unsigned int) ~WriteMaskChannel);
3479 image->channels=(ChannelType) ((
unsigned int) image->channels &
3480 (
unsigned int) ~CompositeMaskChannel);
3484 return(SyncImagePixelCache(image,exception));
3490 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3493 case WritePixelMask:
3495 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3500 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3504 if (SyncImagePixelCache(image,exception) == MagickFalse)
3505 return(MagickFalse);
3507 image_view=AcquireAuthenticCacheView(image,exception);
3508#if defined(MAGICKCORE_OPENMP_SUPPORT)
3509 #pragma omp parallel for schedule(static) shared(status) \
3510 magick_number_threads(image,image,image->rows,2)
3512 for (y=0; y < (ssize_t) image->rows; y++)
3520 if (status == MagickFalse)
3522 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3523 if (q == (Quantum *) NULL)
3528 for (x=0; x < (ssize_t) image->columns; x++)
3534 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3535 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3541 SetPixelReadMask(image,pixel,q);
3544 case WritePixelMask:
3546 SetPixelWriteMask(image,pixel,q);
3551 SetPixelCompositeMask(image,pixel,q);
3555 q+=(ptrdiff_t) GetPixelChannels(image);
3557 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3560 image->mask_trait=UpdatePixelTrait;
3561 image_view=DestroyCacheView(image_view);
3594MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3595 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3597 assert(image != (
const Image *) NULL);
3598 assert(image->signature == MagickCoreSignature);
3599 if (IsEventLogging() != MagickFalse)
3600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3601 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3639static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3640 const ssize_t offset,ExceptionInfo *exception)
3667 if (images->previous == (Image *) NULL)
3670 SetGeometry(smush_image,&right_geometry);
3671 GravityAdjustGeometry(right_image->columns,right_image->rows,
3672 right_image->gravity,&right_geometry);
3673 left_image=images->previous;
3674 SetGeometry(smush_image,&left_geometry);
3675 GravityAdjustGeometry(left_image->columns,left_image->rows,
3676 left_image->gravity,&left_geometry);
3677 gap=right_image->columns;
3678 left_view=AcquireVirtualCacheView(left_image,exception);
3679 right_view=AcquireVirtualCacheView(right_image,exception);
3680 for (y=0; y < (ssize_t) smush_image->rows; y++)
3682 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3684 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3685 if ((p == (
const Quantum *) NULL) ||
3686 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3687 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3690 i=(ssize_t) left_image->columns-x-1;
3691 for (x=0; x < (ssize_t) right_image->columns; x++)
3693 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3695 if ((p == (
const Quantum *) NULL) ||
3696 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3697 ((x+i) >= (ssize_t) gap))
3700 if ((x+i) < (ssize_t) gap)
3703 right_view=DestroyCacheView(right_view);
3704 left_view=DestroyCacheView(left_view);
3705 if (y < (ssize_t) smush_image->rows)
3707 return((ssize_t) gap-offset);
3710static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3711 const ssize_t offset,ExceptionInfo *exception)
3738 if (images->previous == (Image *) NULL)
3740 bottom_image=images;
3741 SetGeometry(smush_image,&bottom_geometry);
3742 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3743 bottom_image->gravity,&bottom_geometry);
3744 top_image=images->previous;
3745 SetGeometry(smush_image,&top_geometry);
3746 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3748 gap=bottom_image->rows;
3749 top_view=AcquireVirtualCacheView(top_image,exception);
3750 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3751 for (x=0; x < (ssize_t) smush_image->columns; x++)
3753 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3755 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3756 if ((p == (
const Quantum *) NULL) ||
3757 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3758 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3761 i=(ssize_t) top_image->rows-y-1;
3762 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3764 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3766 if ((p == (
const Quantum *) NULL) ||
3767 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3768 ((y+i) >= (ssize_t) gap))
3771 if ((y+i) < (ssize_t) gap)
3774 bottom_view=DestroyCacheView(bottom_view);
3775 top_view=DestroyCacheView(top_view);
3776 if (x < (ssize_t) smush_image->columns)
3778 return((ssize_t) gap-offset);
3781MagickExport Image *SmushImages(
const Image *images,
3782 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3784#define SmushImageTag "Smush/Image"
3820 assert(images != (Image *) NULL);
3821 assert(images->signature == MagickCoreSignature);
3822 assert(exception != (ExceptionInfo *) NULL);
3823 assert(exception->signature == MagickCoreSignature);
3824 if (IsEventLogging() != MagickFalse)
3825 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3827 alpha_trait=image->alpha_trait;
3829 width=image->columns;
3831 next=GetNextImageInList(image);
3832 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3834 if (next->alpha_trait != UndefinedPixelTrait)
3835 alpha_trait=BlendPixelTrait;
3837 if (stack != MagickFalse)
3839 if (next->columns > width)
3840 width=next->columns;
3842 if (next->previous != (Image *) NULL)
3843 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3846 width+=next->columns;
3847 if (next->previous != (Image *) NULL)
3848 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3849 if (next->rows > height)
3855 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3856 if (smush_image == (Image *) NULL)
3857 return((Image *) NULL);
3858 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3860 smush_image=DestroyImage(smush_image);
3861 return((Image *) NULL);
3863 smush_image->alpha_trait=alpha_trait;
3864 (void) SetImageBackgroundColor(smush_image,exception);
3868 for (n=0; n < (MagickOffsetType) number_images; n++)
3870 SetGeometry(smush_image,&geometry);
3871 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3872 if (stack != MagickFalse)
3874 x_offset-=geometry.x;
3875 y_offset-=SmushYGap(smush_image,image,offset,exception);
3879 x_offset-=SmushXGap(smush_image,image,offset,exception);
3880 y_offset-=geometry.y;
3882 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3883 y_offset,exception);
3884 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3885 if (proceed == MagickFalse)
3887 if (stack == MagickFalse)
3889 x_offset+=(ssize_t) image->columns;
3895 y_offset+=(ssize_t) image->rows;
3897 image=GetNextImageInList(image);
3899 if (stack == MagickFalse)
3900 smush_image->columns=(size_t) x_offset;
3902 smush_image->rows=(size_t) y_offset;
3903 if (status == MagickFalse)
3904 smush_image=DestroyImage(smush_image);
3905 return(smush_image);
3932MagickExport MagickBooleanType StripImage(Image *image,
3933 ExceptionInfo *magick_unused(exception))
3938 magick_unreferenced(exception);
3939 assert(image != (Image *) NULL);
3940 if (IsEventLogging() != MagickFalse)
3941 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3942 DestroyImageProfiles(image);
3943 (void) DeleteImageProperty(image,
"comment");
3944 (void) DeleteImageProperty(image,
"date:create");
3945 (void) DeleteImageProperty(image,
"date:modify");
3946 (void) DeleteImageProperty(image,
"date:timestamp");
3947 status=SetImageArtifact(image,
"png:exclude-chunk",
3948 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3978static inline Quantum PushColormapIndex(Image *image,
const Quantum index,
3979 MagickBooleanType *range_exception)
3981 if ((
size_t) index < image->colors)
3983 *range_exception=MagickTrue;
3984 return((Quantum) 0);
3987MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4000 assert(image != (Image *) NULL);
4001 assert(image->signature == MagickCoreSignature);
4002 if (IsEventLogging() != MagickFalse)
4003 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4004 if (image->ping != MagickFalse)
4006 if (image->storage_class != PseudoClass)
4007 return(MagickFalse);
4008 assert(image->colormap != (PixelInfo *) NULL);
4009 range_exception=MagickFalse;
4012 image_view=AcquireAuthenticCacheView(image,exception);
4013#if defined(MAGICKCORE_OPENMP_SUPPORT)
4014 #pragma omp parallel for schedule(static) shared(range_exception,status) \
4015 magick_number_threads(image,image,image->rows,2)
4017 for (y=0; y < (ssize_t) image->rows; y++)
4028 if (status == MagickFalse)
4030 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4031 if (q == (Quantum *) NULL)
4036 for (x=0; x < (ssize_t) image->columns; x++)
4038 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4039 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4040 q+=(ptrdiff_t) GetPixelChannels(image);
4042 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4045 image_view=DestroyCacheView(image_view);
4047 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4048 (void) ThrowMagickException(exception,GetMagickModule(),
4049 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4090MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4091 Image *images,ExceptionInfo *exception)
4096 assert(image_info != (
const ImageInfo *) NULL);
4097 assert(image_info->signature == MagickCoreSignature);
4098 assert(images != (Image *) NULL);
4099 assert(images->signature == MagickCoreSignature);
4100 if (IsEventLogging() != MagickFalse)
4101 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4103 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4104 (
void) SyncImageSettings(image_info,image,exception);
4105 (void) DeleteImageOption(image_info,
"page");
4109MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4110 Image *image,ExceptionInfo *exception)
4127 assert(image_info != (
const ImageInfo *) NULL);
4128 assert(image_info->signature == MagickCoreSignature);
4129 assert(image != (Image *) NULL);
4130 assert(image->signature == MagickCoreSignature);
4131 if (IsEventLogging() != MagickFalse)
4132 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4133 option=GetImageOption(image_info,
"background");
4134 if (option != (
const char *) NULL)
4135 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4137 option=GetImageOption(image_info,
"black-point-compensation");
4138 if (option != (
const char *) NULL)
4139 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4140 MagickBooleanOptions,MagickFalse,option);
4141 option=GetImageOption(image_info,
"blue-primary");
4142 if (option != (
const char *) NULL)
4144 flags=ParseGeometry(option,&geometry_info);
4145 if ((flags & RhoValue) != 0)
4146 image->chromaticity.blue_primary.x=geometry_info.rho;
4147 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4148 if ((flags & SigmaValue) != 0)
4149 image->chromaticity.blue_primary.y=geometry_info.sigma;
4151 option=GetImageOption(image_info,
"bordercolor");
4152 if (option != (
const char *) NULL)
4153 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4156 option=GetImageOption(image_info,
"compose");
4157 if (option != (
const char *) NULL)
4158 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4159 MagickFalse,option);
4161 option=GetImageOption(image_info,
"compress");
4162 if (option != (
const char *) NULL)
4163 image->compression=(CompressionType) ParseCommandOption(
4164 MagickCompressOptions,MagickFalse,option);
4165 option=GetImageOption(image_info,
"debug");
4166 if (option != (
const char *) NULL)
4167 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4168 MagickFalse,option);
4169 option=GetImageOption(image_info,
"density");
4170 if (option != (
const char *) NULL)
4172 flags=ParseGeometry(option,&geometry_info);
4173 if ((flags & RhoValue) != 0)
4174 image->resolution.x=geometry_info.rho;
4175 image->resolution.y=image->resolution.x;
4176 if ((flags & SigmaValue) != 0)
4177 image->resolution.y=geometry_info.sigma;
4179 option=GetImageOption(image_info,
"depth");
4180 if (option != (
const char *) NULL)
4181 image->depth=StringToUnsignedLong(option);
4182 option=GetImageOption(image_info,
"endian");
4183 if (option != (
const char *) NULL)
4184 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4185 MagickFalse,option);
4186 option=GetImageOption(image_info,
"filter");
4187 if (option != (
const char *) NULL)
4188 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4189 MagickFalse,option);
4190 option=GetImageOption(image_info,
"fuzz");
4191 if (option != (
const char *) NULL)
4192 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4193 option=GetImageOption(image_info,
"gravity");
4194 if (option != (
const char *) NULL)
4195 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4196 MagickFalse,option);
4197 option=GetImageOption(image_info,
"green-primary");
4198 if (option != (
const char *) NULL)
4200 flags=ParseGeometry(option,&geometry_info);
4201 if ((flags & RhoValue) != 0)
4202 image->chromaticity.green_primary.x=geometry_info.rho;
4203 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4204 if ((flags & SigmaValue) != 0)
4205 image->chromaticity.green_primary.y=geometry_info.sigma;
4207 option=GetImageOption(image_info,
"intent");
4208 if (option != (
const char *) NULL)
4209 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4210 MagickIntentOptions,MagickFalse,option);
4211 option=GetImageOption(image_info,
"intensity");
4212 if (option != (
const char *) NULL)
4213 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4214 MagickPixelIntensityOptions,MagickFalse,option);
4215 option=GetImageOption(image_info,
"interlace");
4216 if (option != (
const char *) NULL)
4217 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4218 MagickFalse,option);
4219 option=GetImageOption(image_info,
"interpolate");
4220 if (option != (
const char *) NULL)
4221 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4222 MagickInterpolateOptions,MagickFalse,option);
4223 option=GetImageOption(image_info,
"loop");
4224 if (option != (
const char *) NULL)
4225 image->iterations=StringToUnsignedLong(option);
4226 option=GetImageOption(image_info,
"mattecolor");
4227 if (option != (
const char *) NULL)
4228 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4230 option=GetImageOption(image_info,
"orient");
4231 if (option != (
const char *) NULL)
4232 image->orientation=(OrientationType) ParseCommandOption(
4233 MagickOrientationOptions,MagickFalse,option);
4234 option=GetImageOption(image_info,
"page");
4235 if (option != (
const char *) NULL)
4240 geometry=GetPageGeometry(option);
4241 flags=ParseAbsoluteGeometry(geometry,&image->page);
4242 geometry=DestroyString(geometry);
4244 option=GetImageOption(image_info,
"quality");
4245 if (option != (
const char *) NULL)
4246 image->quality=StringToUnsignedLong(option);
4247 option=GetImageOption(image_info,
"red-primary");
4248 if (option != (
const char *) NULL)
4250 flags=ParseGeometry(option,&geometry_info);
4251 if ((flags & RhoValue) != 0)
4252 image->chromaticity.red_primary.x=geometry_info.rho;
4253 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4254 if ((flags & SigmaValue) != 0)
4255 image->chromaticity.red_primary.y=geometry_info.sigma;
4257 if (image_info->quality != UndefinedCompressionQuality)
4258 image->quality=image_info->quality;
4259 option=GetImageOption(image_info,
"scene");
4260 if (option != (
const char *) NULL)
4261 image->scene=StringToUnsignedLong(option);
4262 option=GetImageOption(image_info,
"taint");
4263 if (option != (
const char *) NULL)
4264 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4265 MagickFalse,option);
4266 option=GetImageOption(image_info,
"tile-offset");
4267 if (option != (
const char *) NULL)
4272 geometry=GetPageGeometry(option);
4273 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4274 geometry=DestroyString(geometry);
4276 option=GetImageOption(image_info,
"transparent-color");
4277 if (option != (
const char *) NULL)
4278 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4280 option=GetImageOption(image_info,
"type");
4281 if (option != (
const char *) NULL)
4282 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4284 option=GetImageOption(image_info,
"units");
4285 units=image_info->units;
4286 if (option != (
const char *) NULL)
4287 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4288 MagickFalse,option);
4289 if (units != UndefinedResolution)
4291 if (image->units != units)
4292 switch (image->units)
4294 case PixelsPerInchResolution:
4296 if (units == PixelsPerCentimeterResolution)
4298 image->resolution.x/=2.54;
4299 image->resolution.y/=2.54;
4303 case PixelsPerCentimeterResolution:
4305 if (units == PixelsPerInchResolution)
4307 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4308 image->resolution.x+0.5))/100.0;
4309 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4310 image->resolution.y+0.5))/100.0;
4318 option=GetImageOption(image_info,
"density");
4319 if (option != (
const char *) NULL)
4321 flags=ParseGeometry(option,&geometry_info);
4322 if ((flags & RhoValue) != 0)
4323 image->resolution.x=geometry_info.rho;
4324 image->resolution.y=image->resolution.x;
4325 if ((flags & SigmaValue) != 0)
4326 image->resolution.y=geometry_info.sigma;
4329 option=GetImageOption(image_info,
"virtual-pixel");
4330 if (option != (
const char *) NULL)
4331 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4332 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4334 option=GetImageOption(image_info,
"white-point");
4335 if (option != (
const char *) NULL)
4337 flags=ParseGeometry(option,&geometry_info);
4338 if ((flags & RhoValue) != 0)
4339 image->chromaticity.white_point.x=geometry_info.rho;
4340 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4341 if ((flags & SigmaValue) != 0)
4342 image->chromaticity.white_point.y=geometry_info.sigma;
4350 if (image->image_info != (ImageInfo *) NULL)
4351 image->image_info=DestroyImageInfo(image->image_info);
4352 image->image_info=CloneImageInfo(image_info);