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((
double) scale_x*
912 (
double) image->page.width+0.5));
913 clone_image->page.height=(size_t) CastDoubleToSsizeT(floor((
double) scale_y*
914 (
double) 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((
double) scale_x*
918 (
double) image->page.x-0.5));
919 clone_image->tile_offset.x=CastDoubleToSsizeT(ceil((
double) scale_x*
920 (
double) image->tile_offset.x-0.5));
921 clone_image->page.y=CastDoubleToSsizeT(ceil((
double) scale_y*(
double)
922 (
double) image->page.y-0.5));
923 clone_image->tile_offset.y=CastDoubleToSsizeT(ceil((
double) scale_y*
924 (
double) image->tile_offset.y-0.5));
925 clone_image->cache=ClonePixelCache(image->cache);
926 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
927 clone_image=DestroyImage(clone_image);
955MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
960 clone_info=AcquireImageInfo();
961 if (image_info == (ImageInfo *) NULL)
963 clone_info->compression=image_info->compression;
964 clone_info->temporary=image_info->temporary;
965 clone_info->adjoin=image_info->adjoin;
966 clone_info->antialias=image_info->antialias;
967 clone_info->scene=image_info->scene;
968 clone_info->number_scenes=image_info->number_scenes;
969 clone_info->depth=image_info->depth;
970 if (image_info->size != (
char *) NULL)
971 (void) CloneString(&clone_info->size,image_info->size);
972 if (image_info->extract != (
char *) NULL)
973 (void) CloneString(&clone_info->extract,image_info->extract);
974 if (image_info->scenes != (
char *) NULL)
975 (void) CloneString(&clone_info->scenes,image_info->scenes);
976 if (image_info->page != (
char *) NULL)
977 (void) CloneString(&clone_info->page,image_info->page);
978 clone_info->interlace=image_info->interlace;
979 clone_info->endian=image_info->endian;
980 clone_info->units=image_info->units;
981 clone_info->quality=image_info->quality;
982 if (image_info->sampling_factor != (
char *) NULL)
983 (void) CloneString(&clone_info->sampling_factor,
984 image_info->sampling_factor);
985 if (image_info->server_name != (
char *) NULL)
986 (void) CloneString(&clone_info->server_name,image_info->server_name);
987 if (image_info->font != (
char *) NULL)
988 (void) CloneString(&clone_info->font,image_info->font);
989 if (image_info->texture != (
char *) NULL)
990 (void) CloneString(&clone_info->texture,image_info->texture);
991 if (image_info->density != (
char *) NULL)
992 (void) CloneString(&clone_info->density,image_info->density);
993 clone_info->pointsize=image_info->pointsize;
994 clone_info->fuzz=image_info->fuzz;
995 clone_info->matte_color=image_info->matte_color;
996 clone_info->background_color=image_info->background_color;
997 clone_info->border_color=image_info->border_color;
998 clone_info->transparent_color=image_info->transparent_color;
999 clone_info->dither=image_info->dither;
1000 clone_info->monochrome=image_info->monochrome;
1001 clone_info->colorspace=image_info->colorspace;
1002 clone_info->type=image_info->type;
1003 clone_info->orientation=image_info->orientation;
1004 clone_info->ping=image_info->ping;
1005 clone_info->verbose=image_info->verbose;
1006 clone_info->progress_monitor=image_info->progress_monitor;
1007 clone_info->client_data=image_info->client_data;
1008 clone_info->cache=image_info->cache;
1009 if (image_info->cache != (
void *) NULL)
1010 clone_info->cache=ReferencePixelCache(image_info->cache);
1011 if (image_info->profile != (
void *) NULL)
1012 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1013 image_info->profile);
1014 SetImageInfoFile(clone_info,image_info->file);
1015 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1016 clone_info->stream=image_info->stream;
1017 clone_info->custom_stream=image_info->custom_stream;
1018 (void) CopyMagickString(clone_info->magick,image_info->magick,
1020 (void) CopyMagickString(clone_info->unique,image_info->unique,
1022 (void) CopyMagickString(clone_info->filename,image_info->filename,
1024 clone_info->channel=image_info->channel;
1025 (void) CloneImageOptions(clone_info,image_info);
1026 clone_info->coder_depth=image_info->coder_depth;
1027 clone_info->debug=image_info->debug;
1028 clone_info->signature=image_info->signature;
1065MagickExport MagickBooleanType CopyImagePixels(Image *image,
1066 const Image *source_image,
const RectangleInfo *geometry,
1067 const OffsetInfo *offset,ExceptionInfo *exception)
1069#define CopyImageTag "Copy/Image"
1084 assert(image != (Image *) NULL);
1085 assert(source_image != (Image *) NULL);
1086 assert(geometry != (RectangleInfo *) NULL);
1087 assert(offset != (OffsetInfo *) NULL);
1088 if (IsEventLogging() != MagickFalse)
1089 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1090 if ((offset->x < 0) || (offset->y < 0) ||
1091 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1092 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1093 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1095 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1096 return(MagickFalse);
1102 source_view=AcquireVirtualCacheView(source_image,exception);
1103 image_view=AcquireAuthenticCacheView(image,exception);
1104#if defined(MAGICKCORE_OPENMP_SUPPORT)
1105 #pragma omp parallel for schedule(static) shared(progress,status) \
1106 magick_number_threads(image,source_image,geometry->height,2)
1108 for (y=0; y < (ssize_t) geometry->height; y++)
1122 if (status == MagickFalse)
1124 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1125 geometry->width,1,exception);
1126 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1127 geometry->width,1,exception);
1128 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1133 for (x=0; x < (ssize_t) geometry->width; x++)
1138 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1140 PixelChannel channel = GetPixelChannelChannel(image,i);
1141 PixelTrait traits = GetPixelChannelTraits(image,channel);
1142 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1143 if ((traits == UndefinedPixelTrait) ||
1144 ((traits & UpdatePixelTrait) == 0) ||
1145 (source_traits == UndefinedPixelTrait))
1147 SetPixelChannel(image,channel,p[i],q);
1149 p+=(ptrdiff_t) GetPixelChannels(source_image);
1150 q+=(ptrdiff_t) GetPixelChannels(image);
1152 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1153 if (sync == MagickFalse)
1155 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1160#if defined(MAGICKCORE_OPENMP_SUPPORT)
1164 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1165 if (proceed == MagickFalse)
1169 source_view=DestroyCacheView(source_view);
1170 image_view=DestroyCacheView(image_view);
1197MagickExport Image *DestroyImage(Image *image)
1205 assert(image != (Image *) NULL);
1206 assert(image->signature == MagickCoreSignature);
1207 if (IsEventLogging() != MagickFalse)
1208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1209 destroy=MagickFalse;
1210 LockSemaphoreInfo(image->semaphore);
1211 image->reference_count--;
1212 if (image->reference_count == 0)
1214 UnlockSemaphoreInfo(image->semaphore);
1215 if (destroy == MagickFalse)
1216 return((Image *) NULL);
1220 DestroyImagePixels(image);
1221 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1222 if (image->montage != (
char *) NULL)
1223 image->montage=DestroyString(image->montage);
1224 if (image->directory != (
char *) NULL)
1225 image->directory=DestroyString(image->directory);
1226 if (image->colormap != (PixelInfo *) NULL)
1227 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1228 if (image->geometry != (
char *) NULL)
1229 image->geometry=DestroyString(image->geometry);
1230 DestroyImageProfiles(image);
1231 DestroyImageProperties(image);
1232 DestroyImageArtifacts(image);
1233 if (image->ascii85 != (Ascii85Info *) NULL)
1234 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1235 if (image->image_info != (ImageInfo *) NULL)
1236 image->image_info=DestroyImageInfo(image->image_info);
1239 RelinquishSemaphoreInfo(&image->semaphore);
1240 image->signature=(~MagickCoreSignature);
1241 image=(Image *) RelinquishMagickMemory(image);
1268MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1270 assert(image_info != (ImageInfo *) NULL);
1271 assert(image_info->signature == MagickCoreSignature);
1272 if (IsEventLogging() != MagickFalse)
1273 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1274 image_info->filename);
1275 if (image_info->size != (
char *) NULL)
1276 image_info->size=DestroyString(image_info->size);
1277 if (image_info->extract != (
char *) NULL)
1278 image_info->extract=DestroyString(image_info->extract);
1279 if (image_info->scenes != (
char *) NULL)
1280 image_info->scenes=DestroyString(image_info->scenes);
1281 if (image_info->page != (
char *) NULL)
1282 image_info->page=DestroyString(image_info->page);
1283 if (image_info->sampling_factor != (
char *) NULL)
1284 image_info->sampling_factor=DestroyString(
1285 image_info->sampling_factor);
1286 if (image_info->server_name != (
char *) NULL)
1287 image_info->server_name=DestroyString(
1288 image_info->server_name);
1289 if (image_info->font != (
char *) NULL)
1290 image_info->font=DestroyString(image_info->font);
1291 if (image_info->texture != (
char *) NULL)
1292 image_info->texture=DestroyString(image_info->texture);
1293 if (image_info->density != (
char *) NULL)
1294 image_info->density=DestroyString(image_info->density);
1295 if (image_info->cache != (
void *) NULL)
1296 image_info->cache=DestroyPixelCache(image_info->cache);
1297 if (image_info->profile != (StringInfo *) NULL)
1298 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1299 image_info->profile);
1300 DestroyImageOptions(image_info);
1301 image_info->signature=(~MagickCoreSignature);
1302 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1330MagickExport
void DisassociateImageStream(Image *image)
1332 assert(image != (Image *) NULL);
1333 assert(image->signature == MagickCoreSignature);
1334 if (IsEventLogging() != MagickFalse)
1335 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1336 DisassociateBlob(image);
1361MagickExport
void GetImageInfo(ImageInfo *image_info)
1369 assert(image_info != (ImageInfo *) NULL);
1370 if (IsEventLogging() != MagickFalse)
1371 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1372 (void) memset(image_info,0,
sizeof(*image_info));
1373 image_info->adjoin=MagickTrue;
1374 image_info->interlace=NoInterlace;
1375 image_info->channel=AllChannels;
1376 image_info->quality=UndefinedCompressionQuality;
1377 image_info->antialias=MagickTrue;
1378 image_info->dither=MagickTrue;
1379 image_info->depth=0;
1380 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1381 if (synchronize != (
const char *) NULL)
1383 image_info->synchronize=IsStringTrue(synchronize);
1384 synchronize=DestroyString(synchronize);
1386 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1387 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1388 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1389 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1390 image_info->coder_depth=0;
1391 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1393 image_info->signature=MagickCoreSignature;
1418MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1420 return(image_info->file);
1448MagickExport Image *GetImageMask(
const Image *image,
const PixelMask type,
1449 ExceptionInfo *exception)
1467 assert(image != (Image *) NULL);
1468 assert(image->signature == MagickCoreSignature);
1469 if (IsEventLogging() != MagickFalse)
1470 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1475 if ((image->channels & ReadMaskChannel) == 0)
1476 return((Image *) NULL);
1479 case WritePixelMask:
1481 if ((image->channels & WriteMaskChannel) == 0)
1482 return((Image *) NULL);
1487 if ((image->channels & CompositeMaskChannel) == 0)
1488 return((Image *) NULL);
1492 mask_image=AcquireImage((ImageInfo *) NULL,exception);
1493 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1494 if (status == MagickFalse)
1495 return(DestroyImage(mask_image));
1497 mask_image->alpha_trait=UndefinedPixelTrait;
1498 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1499 image_view=AcquireVirtualCacheView(image,exception);
1500 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1501#if defined(MAGICKCORE_OPENMP_SUPPORT)
1502 #pragma omp parallel for schedule(static) shared(status) \
1503 magick_number_threads(image,image,image->rows,2)
1505 for (y=0; y < (ssize_t) image->rows; y++)
1516 if (status == MagickFalse)
1518 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1519 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1521 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1526 for (x=0; x < (ssize_t) image->columns; x++)
1532 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1535 case WritePixelMask:
1537 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1542 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1546 p+=(ptrdiff_t) GetPixelChannels(image);
1547 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1549 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1552 mask_view=DestroyCacheView(mask_view);
1553 image_view=DestroyCacheView(image_view);
1554 if (status == MagickFalse)
1555 mask_image=DestroyImage(mask_image);
1581MagickExport ssize_t GetImageReferenceCount(Image *image)
1586 assert(image != (Image *) NULL);
1587 assert(image->signature == MagickCoreSignature);
1588 if (IsEventLogging() != MagickFalse)
1589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1590 LockSemaphoreInfo(image->semaphore);
1591 reference_count=image->reference_count;
1592 UnlockSemaphoreInfo(image->semaphore);
1593 return(reference_count);
1620MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1622 assert(image != (Image *) NULL);
1623 assert(image->signature == MagickCoreSignature);
1624 if (IsEventLogging() != MagickFalse)
1625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1626 return(GetPixelCacheVirtualMethod(image));
1665static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1669 specifier = end[-1];
1672 length = (size_t) (end-start);
1677 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1678 return(MagickFalse);
1679 if ((length == 1) && (*start == specifier))
1688 if ((length >= 3) && (start[1] ==
'0'))
1689 return(MagickFalse);
1692 for ( ; i < (length-1); i++)
1693 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1694 return(MagickFalse);
1697 return(MagickFalse);
1700MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1701 Image *image,
const char *format,
int value,
char *filename,
1702 ExceptionInfo *exception)
1707 pattern[MagickPathExtent];
1712 assert(format != (
const char *) NULL);
1713 assert(filename != (
char *) NULL);
1714 literal=(
char *) GetImageRegistry(StringRegistryType,
"filename:literal",
1716 if (IsStringTrue(literal) != MagickFalse)
1718 if (literal != (
char *) NULL)
1719 literal=DestroyString(literal);
1720 (void) CopyMagickString(filename,format,MagickPathExtent);
1721 return(strlen(filename));
1723 if (literal != (
char *) NULL)
1724 literal=DestroyString(literal);
1725 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1743 specifier_start=cursor;
1744 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1746 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1749 *specifier_end = cursor+1;
1751 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1754 format_specifier[MagickPathExtent];
1757 length = (size_t) (cursor-specifier_start),
1763 (void) snprintf(format_specifier,
sizeof(format_specifier),
1764 "%%%.*s%c",(
int) length,specifier_start,*cursor);
1765 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1767 pattern_length=strlen(pattern);
1768 if ((count <= 0) || ((
size_t) count != pattern_length))
1770 if ((p-filename+(ssize_t) pattern_length) >= MagickPathExtent)
1772 (void) CopyMagickString(p,pattern,(
size_t) (MagickPathExtent-
1791 *end = strchr(cursor,
']'),
1792 *option = (
const char *) NULL;
1798 if (end == (
const char *) NULL)
1800 extent=(size_t) (end-cursor-1);
1801 if (extent >=
sizeof(pattern))
1803 (void) CopyMagickString(pattern,cursor+1,extent+1);
1804 pattern[extent]=
'\0';
1807 option=GetImageProperty(image,pattern,exception);
1808 if (option == (
const char *) NULL)
1809 option=GetImageArtifact(image,pattern);
1811 if ((option == (
const char *) NULL) &&
1812 (image_info != (ImageInfo *) NULL))
1813 option=GetImageOption(image_info,pattern);
1814 if (option == (
const char *) NULL)
1816 option_length=strlen(option);
1817 if ((p-filename+(ssize_t) option_length) >= MagickPathExtent)
1819 (void) CopyMagickString(p,option,(
size_t) (MagickPathExtent-
1829 if ((p-filename+1) >= MagickPathExtent)
1834 return(strlen(filename));
1864MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1865 ExceptionInfo *exception)
1867#if !defined(MAGICKCORE_HDRI_SUPPORT)
1870 return(MagickFalse);
1881 assert(image != (Image *) NULL);
1882 assert(image->signature == MagickCoreSignature);
1883 if (IsEventLogging() != MagickFalse)
1884 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1885 image_view=AcquireVirtualCacheView(image,exception);
1886#if defined(MAGICKCORE_OPENMP_SUPPORT)
1887 #pragma omp parallel for schedule(static) shared(hdri) \
1888 magick_number_threads(image,image,image->rows,2)
1890 for (y=0; y < (ssize_t) image->rows; y++)
1898 if (hdri != MagickFalse)
1900 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1901 if (p == (
const Quantum *) NULL)
1903 for (x=0; x < (ssize_t) image->columns; x++)
1908 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1916 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1917 if (traits == UndefinedPixelTrait)
1919 pixel=(double) p[i];
1920 if ((pixel < 0.0) || (pixel > (
double) QuantumRange) ||
1921 (pixel != (
double) ((QuantumAny) pixel)))
1927 if (hdri != MagickFalse)
1929 p+=(ptrdiff_t) GetPixelChannels(image);
1932 image_view=DestroyCacheView(image_view);
1960MagickExport MagickBooleanType IsImageObject(
const Image *image)
1965 assert(image != (Image *) NULL);
1966 if (IsEventLogging() != MagickFalse)
1967 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1968 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1969 if (p->signature != MagickCoreSignature)
1970 return(MagickFalse);
1997MagickExport MagickBooleanType IsTaintImage(
const Image *image)
2000 magick[MagickPathExtent],
2001 filename[MagickPathExtent];
2006 assert(image != (Image *) NULL);
2007 assert(image->signature == MagickCoreSignature);
2008 if (IsEventLogging() != MagickFalse)
2009 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2010 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
2011 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
2012 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2014 if (p->taint != MagickFalse)
2016 if (LocaleCompare(p->magick,magick) != 0)
2018 if (LocaleCompare(p->filename,filename) != 0)
2021 return(MagickFalse);
2050MagickExport MagickBooleanType ModifyImage(Image **image,
2051 ExceptionInfo *exception)
2056 assert(image != (Image **) NULL);
2057 assert(*image != (Image *) NULL);
2058 assert((*image)->signature == MagickCoreSignature);
2059 if (IsEventLogging() != MagickFalse)
2060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2061 if (GetImageReferenceCount(*image) <= 1)
2063 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2064 LockSemaphoreInfo((*image)->semaphore);
2065 (*image)->reference_count--;
2066 UnlockSemaphoreInfo((*image)->semaphore);
2104MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2105 const size_t width,
const size_t height,
const PixelInfo *background,
2106 ExceptionInfo *exception)
2120 assert(image_info != (
const ImageInfo *) NULL);
2121 assert(image_info->signature == MagickCoreSignature);
2122 assert(background != (
const PixelInfo *) NULL);
2123 if (IsEventLogging() != MagickFalse)
2124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2125 image=AcquireImage(image_info,exception);
2126 image->columns=width;
2128 image->colorspace=background->colorspace;
2129 image->alpha_trait=background->alpha_trait;
2130 image->fuzz=background->fuzz;
2131 image->depth=background->depth;
2133 image_view=AcquireAuthenticCacheView(image,exception);
2134#if defined(MAGICKCORE_OPENMP_SUPPORT)
2135 #pragma omp parallel for schedule(static) shared(status) \
2136 magick_number_threads(image,image,image->rows,2)
2138 for (y=0; y < (ssize_t) image->rows; y++)
2146 if (status == MagickFalse)
2148 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2149 if (q == (Quantum *) NULL)
2154 for (x=0; x < (ssize_t) image->columns; x++)
2156 SetPixelViaPixelInfo(image,background,q);
2157 q+=(ptrdiff_t) GetPixelChannels(image);
2159 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2162 image_view=DestroyCacheView(image_view);
2163 if (status == MagickFalse)
2164 image=DestroyImage(image);
2191MagickExport Image *ReferenceImage(Image *image)
2193 assert(image != (Image *) NULL);
2194 assert(image->signature == MagickCoreSignature);
2195 if (IsEventLogging() != MagickFalse)
2196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2197 LockSemaphoreInfo(image->semaphore);
2198 image->reference_count++;
2199 UnlockSemaphoreInfo(image->semaphore);
2227MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2235 assert(image != (Image *) NULL);
2236 assert(image->signature == MagickCoreSignature);
2237 if (IsEventLogging() != MagickFalse)
2238 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2239 flags=ParseAbsoluteGeometry(page,&geometry);
2240 if ((flags & WidthValue) != 0)
2242 if ((flags & HeightValue) == 0)
2243 geometry.height=geometry.width;
2244 image->page.width=geometry.width;
2245 image->page.height=geometry.height;
2247 if ((flags & AspectValue) != 0)
2249 if ((flags & XValue) != 0)
2250 image->page.x+=geometry.x;
2251 if ((flags & YValue) != 0)
2252 image->page.y+=geometry.y;
2256 if ((flags & XValue) != 0)
2258 image->page.x=geometry.x;
2259 if ((image->page.width == 0) && (geometry.x > 0))
2260 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2262 if ((flags & YValue) != 0)
2264 image->page.y=geometry.y;
2265 if ((image->page.height == 0) && (geometry.y > 0))
2266 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2298MagickExport MagickBooleanType ResetImagePixels(Image *image,
2299 ExceptionInfo *exception)
2316 assert(image != (Image *) NULL);
2317 assert(image->signature == MagickCoreSignature);
2318 if (IsEventLogging() != MagickFalse)
2319 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2320 pixels=AcquirePixelCachePixels(image,&length,exception);
2321 if (pixels != (
void *) NULL)
2326 (void) memset(pixels,0,length);
2333 image_view=AcquireAuthenticCacheView(image,exception);
2334#if defined(MAGICKCORE_OPENMP_SUPPORT)
2335 #pragma omp parallel for schedule(static) shared(status) \
2336 magick_number_threads(image,image,image->rows,2)
2338 for (y=0; y < (ssize_t) image->rows; y++)
2346 if (status == MagickFalse)
2348 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2349 if (q == (Quantum *) NULL)
2354 for (x=0; x < (ssize_t) image->columns; x++)
2356 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2357 q+=(ptrdiff_t) GetPixelChannels(image);
2359 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2362 image_view=DestroyCacheView(image_view);
2394MagickExport MagickBooleanType SetImageAlpha(Image *image,
const Quantum alpha,
2395 ExceptionInfo *exception)
2409 assert(image != (Image *) NULL);
2410 assert(image->signature == MagickCoreSignature);
2411 if (IsEventLogging() != MagickFalse)
2412 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2413 image->alpha_trait=BlendPixelTrait;
2415 original_mask=image->mask_trait;
2416 image->mask_trait=UndefinedPixelTrait;
2418 image_view=AcquireAuthenticCacheView(image,exception);
2419#if defined(MAGICKCORE_OPENMP_SUPPORT)
2420 #pragma omp parallel for schedule(static) shared(status) \
2421 magick_number_threads(image,image,image->rows,2)
2423 for (y=0; y < (ssize_t) image->rows; y++)
2431 if (status == MagickFalse)
2433 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2434 if (q == (Quantum *) NULL)
2439 for (x=0; x < (ssize_t) image->columns; x++)
2441 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2442 SetPixelAlpha(image,alpha,q);
2443 q+=(ptrdiff_t) GetPixelChannels(image);
2445 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2448 image_view=DestroyCacheView(image_view);
2449 image->mask_trait=original_mask;
2480MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2481 ExceptionInfo *exception)
2495 assert(image != (Image *) NULL);
2496 assert(image->signature == MagickCoreSignature);
2497 if (IsEventLogging() != MagickFalse)
2498 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2499 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2500 return(MagickFalse);
2501 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2502 ((image->alpha_trait & BlendPixelTrait) == 0))
2503 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2504 ConformPixelInfo(image,&image->background_color,&background,exception);
2509 image_view=AcquireAuthenticCacheView(image,exception);
2510#if defined(MAGICKCORE_OPENMP_SUPPORT)
2511 #pragma omp parallel for schedule(static) shared(status) \
2512 magick_number_threads(image,image,image->rows,2)
2514 for (y=0; y < (ssize_t) image->rows; y++)
2522 if (status == MagickFalse)
2524 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2525 if (q == (Quantum *) NULL)
2530 for (x=0; x < (ssize_t) image->columns; x++)
2532 SetPixelViaPixelInfo(image,&background,q);
2533 q+=(ptrdiff_t) GetPixelChannels(image);
2535 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2538 image_view=DestroyCacheView(image_view);
2568MagickExport ChannelType SetImageChannelMask(Image *image,
2569 const ChannelType channel_mask)
2571 return(SetPixelChannelMask(image,channel_mask));
2601MagickExport MagickBooleanType SetImageColor(Image *image,
2602 const PixelInfo *color,ExceptionInfo *exception)
2613 assert(image != (Image *) NULL);
2614 assert(image->signature == MagickCoreSignature);
2615 assert(color != (
const PixelInfo *) NULL);
2616 if (IsEventLogging() != MagickFalse)
2617 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2618 image->colorspace=color->colorspace;
2619 image->alpha_trait=color->alpha_trait;
2620 image->fuzz=color->fuzz;
2621 image->depth=color->depth;
2623 image_view=AcquireAuthenticCacheView(image,exception);
2624#if defined(MAGICKCORE_OPENMP_SUPPORT)
2625 #pragma omp parallel for schedule(static) shared(status) \
2626 magick_number_threads(image,image,image->rows,2)
2628 for (y=0; y < (ssize_t) image->rows; y++)
2636 if (status == MagickFalse)
2638 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2639 if (q == (Quantum *) NULL)
2644 for (x=0; x < (ssize_t) image->columns; x++)
2646 SetPixelViaPixelInfo(image,color,q);
2647 q+=(ptrdiff_t) GetPixelChannels(image);
2649 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2652 image_view=DestroyCacheView(image_view);
2684MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2685 const ClassType storage_class,ExceptionInfo *exception)
2687 assert(image != (Image *) NULL);
2688 assert(image->signature == MagickCoreSignature);
2689 assert(exception != (ExceptionInfo *) NULL);
2690 assert(exception->signature == MagickCoreSignature);
2691 if (IsEventLogging() != MagickFalse)
2692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2693 image->storage_class=storage_class;
2694 return(SyncImagePixelCache(image,exception));
2726MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2727 const size_t rows,ExceptionInfo *exception)
2729 if ((columns == 0) || (rows == 0))
2730 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2731 if ((columns > (
size_t) MAGICK_SSIZE_MAX) ||
2732 (rows > (
size_t) MAGICK_SSIZE_MAX))
2733 ThrowBinaryException(ImageError,
"ImageSizeLimitExceeded",image->filename);
2734 image->columns=columns;
2736 if (image->depth == 0)
2739 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2740 "ImageDepthNotSupported",
"`%s'",image->filename);
2742 if (image->depth > (8*
sizeof(MagickSizeType)))
2744 image->depth=8*
sizeof(MagickSizeType);
2745 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2746 "ImageDepthNotSupported",
"`%s'",image->filename);
2748 return(SyncImagePixelCache(image,exception));
2786static const MagickInfo *SetImageInfoFromExtension(ImageInfo *image_info,
2787 const char *component,
char *magic,ExceptionInfo *exception)
2799 *format_type_formats[] =
2823 (void) CopyMagickString(magic,component,MagickPathExtent);
2828 format_type=UndefinedFormatType;
2829 magick_info=GetMagickInfo(magic,exception);
2830 if ((magick_info != (
const MagickInfo *) NULL) &&
2831 (magick_info->format_type != UndefinedFormatType))
2832 format_type=magick_info->format_type;
2834 while ((format_type == UndefinedFormatType) &&
2835 (format_type_formats[i] != (
char *) NULL))
2837 if ((*magic == *format_type_formats[i]) &&
2838 (LocaleCompare(magic,format_type_formats[i]) == 0))
2839 format_type=ExplicitFormatType;
2842 if (format_type == UndefinedFormatType)
2843 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2845 if (format_type == ExplicitFormatType)
2847 image_info->affirm=MagickTrue;
2848 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2850 if (LocaleCompare(magic,
"RGB") == 0)
2851 image_info->affirm=MagickFalse;
2852 return(magick_info);
2855MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2856 const unsigned int frames,ExceptionInfo *exception)
2859 component[MagickPathExtent],
2860 magic[MagickPathExtent],
2861 path[MagickPathExtent],
2888 assert(image_info != (ImageInfo *) NULL);
2889 assert(image_info->signature == MagickCoreSignature);
2890 if (IsEventLogging() != MagickFalse)
2891 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2892 image_info->filename);
2894 GetPathComponent(image_info->filename,SubimagePath,component);
2895 if (*component ==
'\0')
2897 const char *image_frames = GetImageOption(image_info,
"image:frames");
2898 if (image_frames != (
const char *) NULL)
2899 (void) CopyMagickString(component,image_frames,MagickPathExtent);
2901 if (*component !=
'\0')
2906 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2908 if (IsGeometry(component) != MagickFalse)
2909 (void) CloneString(&image_info->extract,component);
2917 (void) CloneString(&image_info->scenes,component);
2918 image_info->scene=StringToUnsignedLong(image_info->scenes);
2919 image_info->number_scenes=image_info->scene;
2920 p=image_info->scenes;
2921 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2923 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2925 first=(size_t) strtol(p,&q,10);
2927 while (isspace((
int) ((
unsigned char) *q)) != 0)
2930 last=(size_t) strtol(q+1,&q,10);
2933 if (first < image_info->scene)
2934 image_info->scene=first;
2935 if (last > image_info->number_scenes)
2936 image_info->number_scenes=last;
2939 image_info->number_scenes-=image_info->scene-1;
2943 if (*image_info->magick ==
'\0')
2944 GetPathComponent(image_info->filename,ExtensionPath,component);
2945 if (*component !=
'\0')
2950 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2951 GetPathComponent(path,ExtensionPath,component);
2953 image_info->affirm=MagickFalse;
2954 sans_exception=AcquireExceptionInfo();
2955 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2956 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2962 GetPathComponent(image_info->filename,MagickPath,magic);
2965 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2966 magick_info=GetMagickInfo(magic,sans_exception);
2967 if ((magick_info != (
const MagickInfo *) NULL) &&
2968 (magick_info->format_type == ExplicitFormatType))
2969 image_info->affirm=MagickTrue;
2971 GetPathComponent(image_info->filename,CanonicalPath,component);
2973 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2974 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2985 magick_info=GetMagickInfo(magic,sans_exception);
2986 delegate_info=(
const DelegateInfo *) NULL;
2987 if (magick_info == (
const MagickInfo *) NULL)
2989 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2990 if (delegate_info == (
const DelegateInfo *) NULL)
2991 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2992 if ((delegate_info == (
const DelegateInfo *) NULL) &&
2993 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2998 magick_info=SetImageInfoFromExtension(image_info,component,magic,
3002 if (((magick_info != (
const MagickInfo *) NULL) ||
3003 (delegate_info != (
const DelegateInfo *) NULL)) &&
3004 (IsMagickConflict(magic) == MagickFalse))
3006 char *literal = (
char *) GetImageRegistry(StringRegistryType,
3007 "filename:literal",exception);
3008 image_info->affirm=MagickTrue;
3009 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
3010 GetPathComponent(image_info->filename,CanonicalPath,component);
3011 if (IsStringTrue(literal) != MagickFalse)
3012 GetPathComponent(image_info->filename,SubcanonicalPath,component);
3013 (void) CopyMagickString(image_info->filename,component,
3015 if (literal != (
char *) NULL)
3016 literal=DestroyString(literal);
3019 sans_exception=DestroyExceptionInfo(sans_exception);
3020 if ((magick_info == (
const MagickInfo *) NULL) ||
3021 (GetMagickEndianSupport(magick_info) == MagickFalse))
3022 image_info->endian=UndefinedEndian;
3023 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3028 (void) InterpretImageFilename(image_info,(Image *) NULL,
3029 image_info->filename,(
int) image_info->scene,component,exception);
3030 if ((LocaleCompare(component,image_info->filename) != 0) &&
3031 (strchr(component,
'%') == (
char *) NULL))
3032 image_info->adjoin=MagickFalse;
3034 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3039 magick_info=GetMagickInfo(magic,exception);
3040 if (magick_info != (
const MagickInfo *) NULL)
3041 if (GetMagickAdjoin(magick_info) == MagickFalse)
3042 image_info->adjoin=MagickFalse;
3044 if (image_info->affirm != MagickFalse)
3057 magick_size=GetMagicPatternExtent(exception);
3058 if (magick_size == 0)
3059 return(MagickFalse);
3060 image=AcquireImage(image_info,exception);
3061 (void) CopyMagickString(image->filename,image_info->filename,
3063 sans_exception=AcquireExceptionInfo();
3064 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3065 sans_exception=DestroyExceptionInfo(sans_exception);
3066 if (status == MagickFalse)
3068 image=DestroyImage(image);
3069 return(MagickFalse);
3071 if ((IsBlobSeekable(image) == MagickFalse) ||
3072 (IsBlobExempt(image) != MagickFalse))
3078 status=ImageToFile(image,component,exception);
3079 if (CloseBlob(image) == MagickFalse)
3081 if (status == MagickFalse)
3083 (void) RelinquishUniqueFileResource(component);
3084 image=DestroyImage(image);
3085 return(MagickFalse);
3087 SetImageInfoFile(image_info,(FILE *) NULL);
3088 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3089 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3090 if (status == MagickFalse)
3092 (void) RelinquishUniqueFileResource(component);
3093 image=DestroyImage(image);
3094 return(MagickFalse);
3096 (void) CopyMagickString(image_info->filename,component,
3098 image_info->temporary=MagickTrue;
3100 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3101 if (magick == (
unsigned char *) NULL)
3103 (void) CloseBlob(image);
3104 image=DestroyImage(image);
3105 return(MagickFalse);
3107 (void) memset(magick,0,magick_size);
3108 count=ReadBlob(image,magick_size,magick);
3109 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3110 (void) CloseBlob(image);
3111 image=DestroyImage(image);
3115 sans_exception=AcquireExceptionInfo();
3116 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3117 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3118 if ((magic_info != (
const MagicInfo *) NULL) &&
3119 (GetMagicName(magic_info) != (
char *) NULL))
3124 if ((magick_info != (
const MagickInfo *) NULL) &&
3125 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3126 (LocaleCompare(magick_info->magick_module,GetMagicName(
3128 (void) CopyMagickString(image_info->magick,magick_info->name,
3132 (void) CopyMagickString(image_info->magick,GetMagicName(
3133 magic_info),MagickPathExtent);
3134 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3136 if ((magick_info == (
const MagickInfo *) NULL) ||
3137 (GetMagickEndianSupport(magick_info) == MagickFalse))
3138 image_info->endian=UndefinedEndian;
3139 sans_exception=DestroyExceptionInfo(sans_exception);
3142 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3143 if ((magick_info == (
const MagickInfo *) NULL) ||
3144 (GetMagickEndianSupport(magick_info) == MagickFalse))
3145 image_info->endian=UndefinedEndian;
3146 sans_exception=DestroyExceptionInfo(sans_exception);
3178MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3179 const size_t length)
3181 assert(image_info != (ImageInfo *) NULL);
3182 assert(image_info->signature == MagickCoreSignature);
3183 if (IsEventLogging() != MagickFalse)
3184 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3185 image_info->filename);
3186 image_info->blob=(
void *) blob;
3187 image_info->length=length;
3215MagickExport
void SetImageInfoCustomStream(ImageInfo *image_info,
3216 CustomStreamInfo *custom_stream)
3218 assert(image_info != (ImageInfo *) NULL);
3219 assert(image_info->signature == MagickCoreSignature);
3220 if (IsEventLogging() != MagickFalse)
3221 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3222 image_info->filename);
3223 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3250MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3252 assert(image_info != (ImageInfo *) NULL);
3253 assert(image_info->signature == MagickCoreSignature);
3254 if (IsEventLogging() != MagickFalse)
3255 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3256 image_info->filename);
3257 image_info->file=file;
3290MagickExport MagickBooleanType SetImageMask(Image *image,
const PixelMask type,
3291 const Image *mask,ExceptionInfo *exception)
3306 assert(image != (Image *) NULL);
3307 if (IsEventLogging() != MagickFalse)
3308 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3309 assert(image->signature == MagickCoreSignature);
3310 image->mask_trait=UndefinedPixelTrait;
3311 if (mask == (
const Image *) NULL)
3317 image->channels=(ChannelType) ((
unsigned int) image->channels &
3318 (
unsigned int) ~ReadMaskChannel);
3321 case WritePixelMask:
3323 image->channels=(ChannelType) ((
unsigned int) image->channels &
3324 (
unsigned int) ~WriteMaskChannel);
3329 image->channels=(ChannelType) ((
unsigned int) image->channels &
3330 (
unsigned int) ~CompositeMaskChannel);
3334 return(SyncImagePixelCache(image,exception));
3340 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3343 case WritePixelMask:
3345 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3350 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3354 if (SyncImagePixelCache(image,exception) == MagickFalse)
3355 return(MagickFalse);
3357 mask_view=AcquireVirtualCacheView(mask,exception);
3358 image_view=AcquireAuthenticCacheView(image,exception);
3359#if defined(MAGICKCORE_OPENMP_SUPPORT)
3360 #pragma omp parallel for schedule(static) shared(status) \
3361 magick_number_threads(mask,image,image->rows,2)
3363 for (y=0; y < (ssize_t) image->rows; y++)
3374 if (status == MagickFalse)
3376 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3377 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3378 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3383 for (x=0; x < (ssize_t) image->columns; x++)
3389 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3390 intensity=GetPixelIntensity(mask,p);
3395 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3398 case WritePixelMask:
3400 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3405 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3409 p+=(ptrdiff_t) GetPixelChannels(mask);
3410 q+=(ptrdiff_t) GetPixelChannels(image);
3412 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3415 mask_view=DestroyCacheView(mask_view);
3416 image_view=DestroyCacheView(image_view);
3417 image->mask_trait=UpdatePixelTrait;
3451MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3452 const PixelMask type,
const RectangleInfo *region,ExceptionInfo *exception)
3466 assert(image != (Image *) NULL);
3467 assert(image->signature == MagickCoreSignature);
3468 if (IsEventLogging() != MagickFalse)
3469 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3470 image->mask_trait=UndefinedPixelTrait;
3471 if (region == (
const RectangleInfo *) NULL)
3477 image->channels=(ChannelType) ((
unsigned int) image->channels &
3478 (
unsigned int) ~ReadMaskChannel);
3481 case WritePixelMask:
3483 image->channels=(ChannelType) ((
unsigned int) image->channels &
3484 (
unsigned int) ~WriteMaskChannel);
3489 image->channels=(ChannelType) ((
unsigned int) image->channels &
3490 (
unsigned int) ~CompositeMaskChannel);
3494 return(SyncImagePixelCache(image,exception));
3500 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3503 case WritePixelMask:
3505 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3510 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3514 if (SyncImagePixelCache(image,exception) == MagickFalse)
3515 return(MagickFalse);
3517 image_view=AcquireAuthenticCacheView(image,exception);
3518#if defined(MAGICKCORE_OPENMP_SUPPORT)
3519 #pragma omp parallel for schedule(static) shared(status) \
3520 magick_number_threads(image,image,image->rows,2)
3522 for (y=0; y < (ssize_t) image->rows; y++)
3530 if (status == MagickFalse)
3532 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3533 if (q == (Quantum *) NULL)
3538 for (x=0; x < (ssize_t) image->columns; x++)
3544 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3545 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3551 SetPixelReadMask(image,pixel,q);
3554 case WritePixelMask:
3556 SetPixelWriteMask(image,pixel,q);
3561 SetPixelCompositeMask(image,pixel,q);
3565 q+=(ptrdiff_t) GetPixelChannels(image);
3567 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3570 image->mask_trait=UpdatePixelTrait;
3571 image_view=DestroyCacheView(image_view);
3604MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3605 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3607 assert(image != (
const Image *) NULL);
3608 assert(image->signature == MagickCoreSignature);
3609 if (IsEventLogging() != MagickFalse)
3610 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3611 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3649static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3650 const ssize_t offset,ExceptionInfo *exception)
3677 if (images->previous == (Image *) NULL)
3680 SetGeometry(smush_image,&right_geometry);
3681 GravityAdjustGeometry(right_image->columns,right_image->rows,
3682 right_image->gravity,&right_geometry);
3683 left_image=images->previous;
3684 SetGeometry(smush_image,&left_geometry);
3685 GravityAdjustGeometry(left_image->columns,left_image->rows,
3686 left_image->gravity,&left_geometry);
3687 gap=right_image->columns;
3688 left_view=AcquireVirtualCacheView(left_image,exception);
3689 right_view=AcquireVirtualCacheView(right_image,exception);
3690 for (y=0; y < (ssize_t) smush_image->rows; y++)
3692 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3694 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3695 if ((p == (
const Quantum *) NULL) ||
3696 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3697 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3700 i=(ssize_t) left_image->columns-x-1;
3701 for (x=0; x < (ssize_t) right_image->columns; x++)
3703 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3705 if ((p == (
const Quantum *) NULL) ||
3706 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3707 ((x+i) >= (ssize_t) gap))
3710 if ((x+i) < (ssize_t) gap)
3713 right_view=DestroyCacheView(right_view);
3714 left_view=DestroyCacheView(left_view);
3715 if (y < (ssize_t) smush_image->rows)
3717 return((ssize_t) gap-offset);
3720static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3721 const ssize_t offset,ExceptionInfo *exception)
3748 if (images->previous == (Image *) NULL)
3750 bottom_image=images;
3751 SetGeometry(smush_image,&bottom_geometry);
3752 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3753 bottom_image->gravity,&bottom_geometry);
3754 top_image=images->previous;
3755 SetGeometry(smush_image,&top_geometry);
3756 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3758 gap=bottom_image->rows;
3759 top_view=AcquireVirtualCacheView(top_image,exception);
3760 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3761 for (x=0; x < (ssize_t) smush_image->columns; x++)
3763 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3765 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3766 if ((p == (
const Quantum *) NULL) ||
3767 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3768 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3771 i=(ssize_t) top_image->rows-y-1;
3772 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3774 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3776 if ((p == (
const Quantum *) NULL) ||
3777 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3778 ((y+i) >= (ssize_t) gap))
3781 if ((y+i) < (ssize_t) gap)
3784 bottom_view=DestroyCacheView(bottom_view);
3785 top_view=DestroyCacheView(top_view);
3786 if (x < (ssize_t) smush_image->columns)
3788 return((ssize_t) gap-offset);
3791MagickExport Image *SmushImages(
const Image *images,
3792 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3794#define SmushImageTag "Smush/Image"
3830 assert(images != (Image *) NULL);
3831 assert(images->signature == MagickCoreSignature);
3832 assert(exception != (ExceptionInfo *) NULL);
3833 assert(exception->signature == MagickCoreSignature);
3834 if (IsEventLogging() != MagickFalse)
3835 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3837 alpha_trait=image->alpha_trait;
3839 width=image->columns;
3841 next=GetNextImageInList(image);
3842 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3844 if (next->alpha_trait != UndefinedPixelTrait)
3845 alpha_trait=BlendPixelTrait;
3847 if (stack != MagickFalse)
3849 if (next->columns > width)
3850 width=next->columns;
3852 if (next->previous != (Image *) NULL)
3853 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3856 width+=next->columns;
3857 if (next->previous != (Image *) NULL)
3858 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3859 if (next->rows > height)
3865 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3866 if (smush_image == (Image *) NULL)
3867 return((Image *) NULL);
3868 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3870 smush_image=DestroyImage(smush_image);
3871 return((Image *) NULL);
3873 smush_image->alpha_trait=alpha_trait;
3874 (void) SetImageBackgroundColor(smush_image,exception);
3878 for (n=0; n < (MagickOffsetType) number_images; n++)
3880 SetGeometry(smush_image,&geometry);
3881 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3882 if (stack != MagickFalse)
3884 x_offset-=geometry.x;
3885 y_offset-=SmushYGap(smush_image,image,offset,exception);
3889 x_offset-=SmushXGap(smush_image,image,offset,exception);
3890 y_offset-=geometry.y;
3892 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3893 y_offset,exception);
3894 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3895 if (proceed == MagickFalse)
3897 if (stack == MagickFalse)
3899 x_offset+=(ssize_t) image->columns;
3905 y_offset+=(ssize_t) image->rows;
3907 image=GetNextImageInList(image);
3909 if (stack == MagickFalse)
3910 smush_image->columns=(size_t) x_offset;
3912 smush_image->rows=(size_t) y_offset;
3913 if (status == MagickFalse)
3914 smush_image=DestroyImage(smush_image);
3915 return(smush_image);
3942MagickExport MagickBooleanType StripImage(Image *image,
3943 ExceptionInfo *magick_unused(exception))
3948 magick_unreferenced(exception);
3949 assert(image != (Image *) NULL);
3950 if (IsEventLogging() != MagickFalse)
3951 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3952 DestroyImageProfiles(image);
3953 (void) DeleteImageProperty(image,
"comment");
3954 (void) DeleteImageProperty(image,
"date:create");
3955 (void) DeleteImageProperty(image,
"date:modify");
3956 (void) DeleteImageProperty(image,
"date:timestamp");
3957 status=SetImageArtifact(image,
"png:exclude-chunk",
3958 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3988static inline Quantum PushColormapIndex(Image *image,
const Quantum index,
3989 MagickBooleanType *range_exception)
3991 if ((
size_t) index < image->colors)
3993 *range_exception=MagickTrue;
3994 return((Quantum) 0);
3997MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
4010 assert(image != (Image *) NULL);
4011 assert(image->signature == MagickCoreSignature);
4012 if (IsEventLogging() != MagickFalse)
4013 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
4014 if (image->ping != MagickFalse)
4016 if (image->storage_class != PseudoClass)
4017 return(MagickFalse);
4018 assert(image->colormap != (PixelInfo *) NULL);
4019 range_exception=MagickFalse;
4022 image_view=AcquireAuthenticCacheView(image,exception);
4023#if defined(MAGICKCORE_OPENMP_SUPPORT)
4024 #pragma omp parallel for schedule(static) shared(range_exception,status) \
4025 magick_number_threads(image,image,image->rows,2)
4027 for (y=0; y < (ssize_t) image->rows; y++)
4038 if (status == MagickFalse)
4040 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4041 if (q == (Quantum *) NULL)
4046 for (x=0; x < (ssize_t) image->columns; x++)
4048 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4049 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4050 q+=(ptrdiff_t) GetPixelChannels(image);
4052 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4055 image_view=DestroyCacheView(image_view);
4057 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4058 (void) ThrowMagickException(exception,GetMagickModule(),
4059 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4100MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4101 Image *images,ExceptionInfo *exception)
4106 assert(image_info != (
const ImageInfo *) NULL);
4107 assert(image_info->signature == MagickCoreSignature);
4108 assert(images != (Image *) NULL);
4109 assert(images->signature == MagickCoreSignature);
4110 if (IsEventLogging() != MagickFalse)
4111 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4113 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4114 (
void) SyncImageSettings(image_info,image,exception);
4115 (void) DeleteImageOption(image_info,
"page");
4119MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4120 Image *image,ExceptionInfo *exception)
4137 assert(image_info != (
const ImageInfo *) NULL);
4138 assert(image_info->signature == MagickCoreSignature);
4139 assert(image != (Image *) NULL);
4140 assert(image->signature == MagickCoreSignature);
4141 if (IsEventLogging() != MagickFalse)
4142 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4143 option=GetImageOption(image_info,
"background");
4144 if (option != (
const char *) NULL)
4145 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4147 option=GetImageOption(image_info,
"black-point-compensation");
4148 if (option != (
const char *) NULL)
4149 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4150 MagickBooleanOptions,MagickFalse,option);
4151 option=GetImageOption(image_info,
"blue-primary");
4152 if (option != (
const char *) NULL)
4154 flags=ParseGeometry(option,&geometry_info);
4155 if ((flags & RhoValue) != 0)
4156 image->chromaticity.blue_primary.x=geometry_info.rho;
4157 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4158 if ((flags & SigmaValue) != 0)
4159 image->chromaticity.blue_primary.y=geometry_info.sigma;
4161 option=GetImageOption(image_info,
"bordercolor");
4162 if (option != (
const char *) NULL)
4163 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4166 option=GetImageOption(image_info,
"compose");
4167 if (option != (
const char *) NULL)
4168 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4169 MagickFalse,option);
4171 option=GetImageOption(image_info,
"compress");
4172 if (option != (
const char *) NULL)
4173 image->compression=(CompressionType) ParseCommandOption(
4174 MagickCompressOptions,MagickFalse,option);
4175 option=GetImageOption(image_info,
"debug");
4176 if (option != (
const char *) NULL)
4177 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4178 MagickFalse,option);
4179 option=GetImageOption(image_info,
"density");
4180 if (option != (
const char *) NULL)
4182 flags=ParseGeometry(option,&geometry_info);
4183 if ((flags & RhoValue) != 0)
4184 image->resolution.x=geometry_info.rho;
4185 image->resolution.y=image->resolution.x;
4186 if ((flags & SigmaValue) != 0)
4187 image->resolution.y=geometry_info.sigma;
4189 option=GetImageOption(image_info,
"depth");
4190 if (option != (
const char *) NULL)
4191 image->depth=StringToUnsignedLong(option);
4192 option=GetImageOption(image_info,
"endian");
4193 if (option != (
const char *) NULL)
4194 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4195 MagickFalse,option);
4196 option=GetImageOption(image_info,
"filter");
4197 if (option != (
const char *) NULL)
4198 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4199 MagickFalse,option);
4200 option=GetImageOption(image_info,
"fuzz");
4201 if (option != (
const char *) NULL)
4202 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4203 option=GetImageOption(image_info,
"gravity");
4204 if (option != (
const char *) NULL)
4205 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4206 MagickFalse,option);
4207 option=GetImageOption(image_info,
"green-primary");
4208 if (option != (
const char *) NULL)
4210 flags=ParseGeometry(option,&geometry_info);
4211 if ((flags & RhoValue) != 0)
4212 image->chromaticity.green_primary.x=geometry_info.rho;
4213 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4214 if ((flags & SigmaValue) != 0)
4215 image->chromaticity.green_primary.y=geometry_info.sigma;
4217 option=GetImageOption(image_info,
"intent");
4218 if (option != (
const char *) NULL)
4219 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4220 MagickIntentOptions,MagickFalse,option);
4221 option=GetImageOption(image_info,
"intensity");
4222 if (option != (
const char *) NULL)
4223 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4224 MagickPixelIntensityOptions,MagickFalse,option);
4225 option=GetImageOption(image_info,
"interlace");
4226 if (option != (
const char *) NULL)
4227 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4228 MagickFalse,option);
4229 option=GetImageOption(image_info,
"interpolate");
4230 if (option != (
const char *) NULL)
4231 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4232 MagickInterpolateOptions,MagickFalse,option);
4233 option=GetImageOption(image_info,
"loop");
4234 if (option != (
const char *) NULL)
4235 image->iterations=StringToUnsignedLong(option);
4236 option=GetImageOption(image_info,
"mattecolor");
4237 if (option != (
const char *) NULL)
4238 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4240 option=GetImageOption(image_info,
"orient");
4241 if (option != (
const char *) NULL)
4242 image->orientation=(OrientationType) ParseCommandOption(
4243 MagickOrientationOptions,MagickFalse,option);
4244 option=GetImageOption(image_info,
"page");
4245 if (option != (
const char *) NULL)
4250 geometry=GetPageGeometry(option);
4251 flags=ParseAbsoluteGeometry(geometry,&image->page);
4252 geometry=DestroyString(geometry);
4254 option=GetImageOption(image_info,
"quality");
4255 if (option != (
const char *) NULL)
4256 image->quality=StringToUnsignedLong(option);
4257 option=GetImageOption(image_info,
"red-primary");
4258 if (option != (
const char *) NULL)
4260 flags=ParseGeometry(option,&geometry_info);
4261 if ((flags & RhoValue) != 0)
4262 image->chromaticity.red_primary.x=geometry_info.rho;
4263 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4264 if ((flags & SigmaValue) != 0)
4265 image->chromaticity.red_primary.y=geometry_info.sigma;
4267 if (image_info->quality != UndefinedCompressionQuality)
4268 image->quality=image_info->quality;
4269 option=GetImageOption(image_info,
"scene");
4270 if (option != (
const char *) NULL)
4271 image->scene=StringToUnsignedLong(option);
4272 option=GetImageOption(image_info,
"taint");
4273 if (option != (
const char *) NULL)
4274 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4275 MagickFalse,option);
4276 option=GetImageOption(image_info,
"tile-offset");
4277 if (option != (
const char *) NULL)
4282 geometry=GetPageGeometry(option);
4283 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4284 geometry=DestroyString(geometry);
4286 option=GetImageOption(image_info,
"transparent-color");
4287 if (option != (
const char *) NULL)
4288 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4290 option=GetImageOption(image_info,
"type");
4291 if (option != (
const char *) NULL)
4292 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4294 option=GetImageOption(image_info,
"units");
4295 units=image_info->units;
4296 if (option != (
const char *) NULL)
4297 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4298 MagickFalse,option);
4299 if (units != UndefinedResolution)
4301 if (image->units != units)
4302 switch (image->units)
4304 case PixelsPerInchResolution:
4306 if (units == PixelsPerCentimeterResolution)
4308 image->resolution.x/=2.54;
4309 image->resolution.y/=2.54;
4313 case PixelsPerCentimeterResolution:
4315 if (units == PixelsPerInchResolution)
4317 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4318 image->resolution.x+0.5))/100.0;
4319 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4320 image->resolution.y+0.5))/100.0;
4328 option=GetImageOption(image_info,
"density");
4329 if (option != (
const char *) NULL)
4331 flags=ParseGeometry(option,&geometry_info);
4332 if ((flags & RhoValue) != 0)
4333 image->resolution.x=geometry_info.rho;
4334 image->resolution.y=image->resolution.x;
4335 if ((flags & SigmaValue) != 0)
4336 image->resolution.y=geometry_info.sigma;
4339 option=GetImageOption(image_info,
"virtual-pixel");
4340 if (option != (
const char *) NULL)
4341 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4342 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4344 option=GetImageOption(image_info,
"white-point");
4345 if (option != (
const char *) NULL)
4347 flags=ParseGeometry(option,&geometry_info);
4348 if ((flags & RhoValue) != 0)
4349 image->chromaticity.white_point.x=geometry_info.rho;
4350 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4351 if ((flags & SigmaValue) != 0)
4352 image->chromaticity.white_point.y=geometry_info.sigma;
4360 if (image->image_info != (ImageInfo *) NULL)
4361 image->image_info=DestroyImageInfo(image->image_info);
4362 image->image_info=CloneImageInfo(image_info);