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/resource_.h"
90#include "MagickCore/segment.h"
91#include "MagickCore/semaphore.h"
92#include "MagickCore/signature-private.h"
93#include "MagickCore/statistic.h"
94#include "MagickCore/string_.h"
95#include "MagickCore/string-private.h"
96#include "MagickCore/thread-private.h"
97#include "MagickCore/threshold.h"
98#include "MagickCore/timer.h"
99#include "MagickCore/timer-private.h"
100#include "MagickCore/token.h"
101#include "MagickCore/token-private.h"
102#include "MagickCore/utility.h"
103#include "MagickCore/utility-private.h"
104#include "MagickCore/version.h"
105#include "MagickCore/xwindow-private.h"
134MagickExport Image *AcquireImage(
const ImageInfo *image_info,
135 ExceptionInfo *exception)
152 if (IsEventLogging() != MagickFalse)
153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
154 image=(Image *) AcquireCriticalMemory(
sizeof(*image));
155 (void) memset(image,0,
sizeof(*image));
159 (void) CopyMagickString(image->magick,
"MIFF",MagickPathExtent);
160 image->storage_class=DirectClass;
161 image->depth=MAGICKCORE_QUANTUM_DEPTH;
162 image->colorspace=sRGBColorspace;
163 image->rendering_intent=PerceptualIntent;
164 image->gamma=1.000/2.200;
165 image->chromaticity.red_primary.x=0.6400;
166 image->chromaticity.red_primary.y=0.3300;
167 image->chromaticity.red_primary.z=0.0300;
168 image->chromaticity.green_primary.x=0.3000;
169 image->chromaticity.green_primary.y=0.6000;
170 image->chromaticity.green_primary.z=0.1000;
171 image->chromaticity.blue_primary.x=0.1500;
172 image->chromaticity.blue_primary.y=0.0600;
173 image->chromaticity.blue_primary.z=0.7900;
174 image->chromaticity.white_point.x=0.3127;
175 image->chromaticity.white_point.y=0.3290;
176 image->chromaticity.white_point.z=0.3583;
177 image->interlace=NoInterlace;
178 image->ticks_per_second=UndefinedTicksPerSecond;
179 image->compose=OverCompositeOp;
180 GetPixelInfoRGBA(BackgroundColorRGBA,&image->background_color);
181 GetPixelInfoRGBA(BorderColorRGBA,&image->border_color);
182 GetPixelInfoRGBA(MatteColorRGBA,&image->matte_color);
183 GetPixelInfoRGBA(TransparentColorRGBA,&image->transparent_color);
184 GetTimerInfo(&image->timer);
185 image->cache=AcquirePixelCache(0);
186 image->channel_mask=AllChannels;
187 image->channel_map=AcquirePixelChannelMap();
188 image->blob=CloneBlobInfo((BlobInfo *) NULL);
189#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
192 image->timestamp=time((time_t *) NULL);
194 time_limit=GetMagickResourceLimit(TimeResource);
195 if (time_limit != MagickResourceInfinity)
196 image->ttl=image->timestamp+(time_t) time_limit;
197 image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
198 != 0 ? MagickTrue : MagickFalse;
199 image->reference_count=1;
200 image->semaphore=AcquireSemaphoreInfo();
201 image->signature=MagickCoreSignature;
202 if (image_info == (ImageInfo *) NULL)
207 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
209 (void) CopyMagickString(image->filename,image_info->filename,
211 (void) CopyMagickString(image->magick_filename,image_info->filename,
213 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
214 if (image_info->size != (
char *) NULL)
216 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
217 image->columns=image->extract_info.width;
218 image->rows=image->extract_info.height;
219 image->offset=image->extract_info.x;
220 image->extract_info.x=0;
221 image->extract_info.y=0;
223 if (image_info->extract != (
char *) NULL)
228 (void) memset(&geometry,0,
sizeof(geometry));
229 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
230 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
232 image->extract_info=geometry;
233 Swap(image->columns,image->extract_info.width);
234 Swap(image->rows,image->extract_info.height);
237 image->compression=image_info->compression;
238 image->quality=image_info->quality;
239 image->endian=image_info->endian;
240 image->interlace=image_info->interlace;
241 image->units=image_info->units;
242 if (image_info->density != (
char *) NULL)
247 flags=ParseGeometry(image_info->density,&geometry_info);
248 if ((flags & RhoValue) != 0)
249 image->resolution.x=geometry_info.rho;
250 image->resolution.y=image->resolution.x;
251 if ((flags & SigmaValue) != 0)
252 image->resolution.y=geometry_info.sigma;
254 if (image_info->page != (
char *) NULL)
259 image->page=image->extract_info;
260 geometry=GetPageGeometry(image_info->page);
261 (void) ParseAbsoluteGeometry(geometry,&image->page);
262 geometry=DestroyString(geometry);
264 if (image_info->depth != 0)
265 image->depth=image_info->depth;
266 image->dither=image_info->dither;
267 image->matte_color=image_info->matte_color;
268 image->background_color=image_info->background_color;
269 image->border_color=image_info->border_color;
270 image->transparent_color=image_info->transparent_color;
271 image->ping=image_info->ping;
272 image->progress_monitor=image_info->progress_monitor;
273 image->client_data=image_info->client_data;
274 if (image_info->cache != (
void *) NULL)
275 ClonePixelCacheMethods(image->cache,image_info->cache);
279 (void) SyncImageSettings(image_info,image,exception);
283 option=GetImageOption(image_info,
"delay");
284 if (option != (
const char *) NULL)
289 flags=ParseGeometry(option,&geometry_info);
290 if ((flags & GreaterValue) != 0)
292 if ((
double) image->delay > floor(geometry_info.rho+0.5))
293 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+
297 if ((flags & LessValue) != 0)
299 if ((
double) image->delay < floor(geometry_info.rho+0.5))
300 image->ticks_per_second=CastDoubleToSsizeT(floor(
301 geometry_info.sigma+0.5));
304 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+
306 if ((flags & SigmaValue) != 0)
307 image->ticks_per_second=CastDoubleToSsizeT(floor(geometry_info.sigma+
310 option=GetImageOption(image_info,
"dispose");
311 if (option != (
const char *) NULL)
312 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
335MagickExport ImageInfo *AcquireImageInfo(
void)
340 image_info=(ImageInfo *) AcquireCriticalMemory(
sizeof(*image_info));
341 GetImageInfo(image_info);
376MagickExport
void AcquireNextImage(
const ImageInfo *image_info,Image *image,
377 ExceptionInfo *exception)
382 assert(image != (Image *) NULL);
383 assert(image->signature == MagickCoreSignature);
384 if (IsEventLogging() != MagickFalse)
385 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
386 image->next=AcquireImage(image_info,exception);
387 if (GetNextImageInList(image) == (Image *) NULL)
389 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
391 if (image_info != (ImageInfo *) NULL)
392 (void) CopyMagickString(GetNextImageInList(image)->filename,
393 image_info->filename,MagickPathExtent);
394 DestroyBlob(GetNextImageInList(image));
395 image->next->blob=ReferenceBlob(image->blob);
396 image->next->endian=image->endian;
397 image->next->scene=image->scene+1;
398 image->next->previous=image;
433MagickExport Image *AppendImages(
const Image *images,
434 const MagickBooleanType stack,ExceptionInfo *exception)
436#define AppendImageTag "Append/Image"
448 homogeneous_colorspace,
477 assert(images != (Image *) NULL);
478 assert(images->signature == MagickCoreSignature);
479 assert(exception != (ExceptionInfo *) NULL);
480 assert(exception->signature == MagickCoreSignature);
481 if (IsEventLogging() != MagickFalse)
482 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
483 alpha_trait=images->alpha_trait;
485 width=images->columns;
488 image_type=images->type;
489 homogeneous_colorspace=MagickTrue;
490 next=GetNextImageInList(images);
491 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
493 if (next->depth > depth)
495 if (next->type != images->type)
496 image_type=UndefinedType;
497 if (next->colorspace != images->colorspace)
498 homogeneous_colorspace=MagickFalse;
499 if (next->alpha_trait != UndefinedPixelTrait)
500 alpha_trait=BlendPixelTrait;
502 if (stack != MagickFalse)
504 if (next->columns > width)
509 width+=next->columns;
510 if (next->rows > height)
516 append_image=CloneImage(images,width,height,MagickTrue,exception);
517 if (append_image == (Image *) NULL)
518 return((Image *) NULL);
519 if (image_type != BilevelType)
521 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
523 append_image=DestroyImage(append_image);
524 return((Image *) NULL);
526 if (homogeneous_colorspace == MagickFalse)
527 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
529 append_image->depth=depth;
530 append_image->alpha_trait=alpha_trait;
531 append_image->page=images->page;
532 (void) SetImageBackgroundColor(append_image,exception);
537 append_view=AcquireAuthenticCacheView(append_image,exception);
538 for (n=0; n < (MagickOffsetType) number_images; n++)
546 SetGeometry(append_image,&geometry);
547 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
548 if (stack != MagickFalse)
549 x_offset-=geometry.x;
551 y_offset-=geometry.y;
552 image_view=AcquireVirtualCacheView(next,exception);
553#if defined(MAGICKCORE_OPENMP_SUPPORT)
554 #pragma omp parallel for schedule(static) shared(status) \
555 magick_number_threads(next,next,next->rows,2)
557 for (y=0; y < (ssize_t) next->rows; y++)
574 if (status == MagickFalse)
576 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
577 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
578 next->columns,1,exception);
579 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
584 GetPixelInfo(next,&pixel);
585 for (x=0; x < (ssize_t) next->columns; x++)
587 GetPixelInfoPixel(next,p,&pixel);
588 SetPixelViaPixelInfo(append_image,&pixel,q);
589 p+=(ptrdiff_t) GetPixelChannels(next);
590 q+=(ptrdiff_t) GetPixelChannels(append_image);
592 sync=SyncCacheViewAuthenticPixels(append_view,exception);
593 if (sync == MagickFalse)
596 image_view=DestroyCacheView(image_view);
597 if (stack == MagickFalse)
599 x_offset+=(ssize_t) next->columns;
605 y_offset+=(ssize_t) next->rows;
607 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
608 if (proceed == MagickFalse)
610 next=GetNextImageInList(next);
612 append_view=DestroyCacheView(append_view);
613 if (status == MagickFalse)
614 append_image=DestroyImage(append_image);
615 return(append_image);
642MagickExport ExceptionType CatchImageException(Image *image)
650 assert(image != (
const Image *) NULL);
651 assert(image->signature == MagickCoreSignature);
652 if (IsEventLogging() != MagickFalse)
653 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
654 exception=AcquireExceptionInfo();
655 CatchException(exception);
656 severity=exception->severity;
657 exception=DestroyExceptionInfo(exception);
694MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
696 return(ClipImagePath(image,
"#1",MagickTrue,exception));
699MagickExport MagickBooleanType ClipImagePath(Image *image,
const char *pathname,
700 const MagickBooleanType inside,ExceptionInfo *exception)
702#define ClipImagePathTag "ClipPath/Image"
717 assert(image != (
const Image *) NULL);
718 assert(image->signature == MagickCoreSignature);
719 assert(pathname != NULL);
720 if (IsEventLogging() != MagickFalse)
721 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
722 property=AcquireString(pathname);
723 (void) FormatLocaleString(property,MagickPathExtent,
"8BIM:1999,2998:%s",
725 value=GetImageProperty(image,property,exception);
726 property=DestroyString(property);
727 if (value == (
const char *) NULL)
729 ThrowFileException(exception,OptionError,
"NoClipPathDefined",
733 image_info=AcquireImageInfo();
734 (void) CopyMagickString(image_info->filename,image->filename,
736 (void) ConcatenateMagickString(image_info->filename,
"_",MagickPathExtent);
737 sanitized_pathname=SanitizeString(pathname);
738 (void) ConcatenateMagickString(image_info->filename,sanitized_pathname,
740 sanitized_pathname=DestroyString(sanitized_pathname);
741 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
742 image_info=DestroyImageInfo(image_info);
743 if (clip_mask == (Image *) NULL)
745 if (clip_mask->storage_class == PseudoClass)
747 (void) SyncImage(clip_mask,exception);
748 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
751 if (inside != MagickFalse)
752 (void) NegateImage(clip_mask,MagickFalse,exception);
753 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
754 "8BIM:1999,2998:%s\nPS",pathname);
755 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
756 clip_mask=DestroyImage(clip_mask);
799MagickExport Image *CloneImage(
const Image *image,
const size_t columns,
800 const size_t rows,
const MagickBooleanType detach,ExceptionInfo *exception)
815 assert(image != (
const Image *) NULL);
816 assert(image->signature == MagickCoreSignature);
817 assert(exception != (ExceptionInfo *) NULL);
818 assert(exception->signature == MagickCoreSignature);
819 if (IsEventLogging() != MagickFalse)
820 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
821 if ((image->columns == 0) || (image->rows == 0))
823 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
824 "NegativeOrZeroImageSize",
"`%s'",image->filename);
825 return((Image *) NULL);
827 clone_image=(Image *) AcquireCriticalMemory(
sizeof(*clone_image));
828 (void) memset(clone_image,0,
sizeof(*clone_image));
829 clone_image->signature=MagickCoreSignature;
830 clone_image->storage_class=image->storage_class;
831 clone_image->number_channels=image->number_channels;
832 clone_image->number_meta_channels=image->number_meta_channels;
833 clone_image->metacontent_extent=image->metacontent_extent;
834 clone_image->colorspace=image->colorspace;
835 clone_image->alpha_trait=image->alpha_trait;
836 clone_image->channels=image->channels;
837 clone_image->mask_trait=image->mask_trait;
838 clone_image->columns=image->columns;
839 clone_image->rows=image->rows;
840 clone_image->dither=image->dither;
841 clone_image->image_info=CloneImageInfo(image->image_info);
842 (void) CloneImageProfiles(clone_image,image);
843 (void) CloneImageProperties(clone_image,image);
844 (void) CloneImageArtifacts(clone_image,image);
845 GetTimerInfo(&clone_image->timer);
846 if (image->ascii85 != (
void *) NULL)
847 Ascii85Initialize(clone_image);
848 clone_image->extent=image->extent;
849 clone_image->magick_columns=image->magick_columns;
850 clone_image->magick_rows=image->magick_rows;
851 clone_image->type=image->type;
852 clone_image->channel_mask=image->channel_mask;
853 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
854 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
856 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
857 (void) CopyMagickString(clone_image->filename,image->filename,
859 clone_image->progress_monitor=image->progress_monitor;
860 clone_image->client_data=image->client_data;
861 clone_image->reference_count=1;
862 clone_image->next=image->next;
863 clone_image->previous=image->previous;
864 clone_image->list=NewImageList();
865 if (detach == MagickFalse)
866 clone_image->blob=ReferenceBlob(image->blob);
869 clone_image->next=NewImageList();
870 clone_image->previous=NewImageList();
871 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
873 clone_image->ping=image->ping;
874 clone_image->timestamp=image->timestamp;
875 clone_image->ttl=image->ttl;
876 clone_image->debug=image->debug;
877 clone_image->semaphore=AcquireSemaphoreInfo();
878 if (image->colormap != (PixelInfo *) NULL)
883 clone_image->colors=image->colors;
884 length=(size_t) image->colors;
885 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length+1,
886 sizeof(*clone_image->colormap));
887 if (clone_image->colormap == (PixelInfo *) NULL)
889 clone_image=DestroyImage(clone_image);
890 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
892 (void) memcpy(clone_image->colormap,image->colormap,length*
893 sizeof(*clone_image->colormap));
895 if ((columns == 0) || (rows == 0))
897 if (image->montage != (
char *) NULL)
898 (void) CloneString(&clone_image->montage,image->montage);
899 if (image->directory != (
char *) NULL)
900 (void) CloneString(&clone_image->directory,image->directory);
901 clone_image->cache=ReferencePixelCache(image->cache);
906 if (image->columns != 0)
907 scale_x=(double) columns/(
double) image->columns;
908 if (image->rows != 0)
909 scale_y=(double) rows/(
double) image->rows;
910 clone_image->page.width=(size_t) CastDoubleToSsizeT(floor(scale_x*
911 image->page.width+0.5));
912 clone_image->page.height=(size_t) CastDoubleToSsizeT(floor(scale_y*
913 image->page.height+0.5));
914 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
915 scale_x=scale_y=MagickMin(scale_x,scale_y);
916 clone_image->page.x=CastDoubleToSsizeT(ceil(scale_x*image->page.x-0.5));
917 clone_image->tile_offset.x=CastDoubleToSsizeT(ceil(scale_x*
918 image->tile_offset.x-0.5));
919 clone_image->page.y=CastDoubleToSsizeT(ceil(scale_y*image->page.y-0.5));
920 clone_image->tile_offset.y=CastDoubleToSsizeT(ceil(scale_y*
921 image->tile_offset.y-0.5));
922 clone_image->cache=ClonePixelCache(image->cache);
923 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
924 clone_image=DestroyImage(clone_image);
952MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
957 clone_info=AcquireImageInfo();
958 if (image_info == (ImageInfo *) NULL)
960 clone_info->compression=image_info->compression;
961 clone_info->temporary=image_info->temporary;
962 clone_info->adjoin=image_info->adjoin;
963 clone_info->antialias=image_info->antialias;
964 clone_info->scene=image_info->scene;
965 clone_info->number_scenes=image_info->number_scenes;
966 clone_info->depth=image_info->depth;
967 if (image_info->size != (
char *) NULL)
968 (void) CloneString(&clone_info->size,image_info->size);
969 if (image_info->extract != (
char *) NULL)
970 (void) CloneString(&clone_info->extract,image_info->extract);
971 if (image_info->scenes != (
char *) NULL)
972 (void) CloneString(&clone_info->scenes,image_info->scenes);
973 if (image_info->page != (
char *) NULL)
974 (void) CloneString(&clone_info->page,image_info->page);
975 clone_info->interlace=image_info->interlace;
976 clone_info->endian=image_info->endian;
977 clone_info->units=image_info->units;
978 clone_info->quality=image_info->quality;
979 if (image_info->sampling_factor != (
char *) NULL)
980 (void) CloneString(&clone_info->sampling_factor,
981 image_info->sampling_factor);
982 if (image_info->server_name != (
char *) NULL)
983 (void) CloneString(&clone_info->server_name,image_info->server_name);
984 if (image_info->font != (
char *) NULL)
985 (void) CloneString(&clone_info->font,image_info->font);
986 if (image_info->texture != (
char *) NULL)
987 (void) CloneString(&clone_info->texture,image_info->texture);
988 if (image_info->density != (
char *) NULL)
989 (void) CloneString(&clone_info->density,image_info->density);
990 clone_info->pointsize=image_info->pointsize;
991 clone_info->fuzz=image_info->fuzz;
992 clone_info->matte_color=image_info->matte_color;
993 clone_info->background_color=image_info->background_color;
994 clone_info->border_color=image_info->border_color;
995 clone_info->transparent_color=image_info->transparent_color;
996 clone_info->dither=image_info->dither;
997 clone_info->monochrome=image_info->monochrome;
998 clone_info->colorspace=image_info->colorspace;
999 clone_info->type=image_info->type;
1000 clone_info->orientation=image_info->orientation;
1001 clone_info->ping=image_info->ping;
1002 clone_info->verbose=image_info->verbose;
1003 clone_info->progress_monitor=image_info->progress_monitor;
1004 clone_info->client_data=image_info->client_data;
1005 clone_info->cache=image_info->cache;
1006 if (image_info->cache != (
void *) NULL)
1007 clone_info->cache=ReferencePixelCache(image_info->cache);
1008 if (image_info->profile != (
void *) NULL)
1009 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1010 image_info->profile);
1011 SetImageInfoFile(clone_info,image_info->file);
1012 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1013 clone_info->stream=image_info->stream;
1014 clone_info->custom_stream=image_info->custom_stream;
1015 (void) CopyMagickString(clone_info->magick,image_info->magick,
1017 (void) CopyMagickString(clone_info->unique,image_info->unique,
1019 (void) CopyMagickString(clone_info->filename,image_info->filename,
1021 clone_info->channel=image_info->channel;
1022 (void) CloneImageOptions(clone_info,image_info);
1023 clone_info->debug=image_info->debug;
1024 clone_info->signature=image_info->signature;
1061MagickExport MagickBooleanType CopyImagePixels(Image *image,
1062 const Image *source_image,
const RectangleInfo *geometry,
1063 const OffsetInfo *offset,ExceptionInfo *exception)
1065#define CopyImageTag "Copy/Image"
1080 assert(image != (Image *) NULL);
1081 assert(source_image != (Image *) NULL);
1082 assert(geometry != (RectangleInfo *) NULL);
1083 assert(offset != (OffsetInfo *) NULL);
1084 if (IsEventLogging() != MagickFalse)
1085 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1086 if ((offset->x < 0) || (offset->y < 0) ||
1087 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1088 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1089 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1091 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1092 return(MagickFalse);
1098 source_view=AcquireVirtualCacheView(source_image,exception);
1099 image_view=AcquireAuthenticCacheView(image,exception);
1100#if defined(MAGICKCORE_OPENMP_SUPPORT)
1101 #pragma omp parallel for schedule(static) shared(progress,status) \
1102 magick_number_threads(image,source_image,geometry->height,2)
1104 for (y=0; y < (ssize_t) geometry->height; y++)
1118 if (status == MagickFalse)
1120 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1121 geometry->width,1,exception);
1122 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1123 geometry->width,1,exception);
1124 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1129 for (x=0; x < (ssize_t) geometry->width; x++)
1134 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1136 PixelChannel channel = GetPixelChannelChannel(image,i);
1137 PixelTrait traits = GetPixelChannelTraits(image,channel);
1138 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1139 if ((traits == UndefinedPixelTrait) ||
1140 ((traits & UpdatePixelTrait) == 0) ||
1141 (source_traits == UndefinedPixelTrait))
1143 SetPixelChannel(image,channel,p[i],q);
1145 p+=(ptrdiff_t) GetPixelChannels(source_image);
1146 q+=(ptrdiff_t) GetPixelChannels(image);
1148 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1149 if (sync == MagickFalse)
1151 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1156#if defined(MAGICKCORE_OPENMP_SUPPORT)
1160 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1161 if (proceed == MagickFalse)
1165 source_view=DestroyCacheView(source_view);
1166 image_view=DestroyCacheView(image_view);
1193MagickExport Image *DestroyImage(Image *image)
1201 assert(image != (Image *) NULL);
1202 assert(image->signature == MagickCoreSignature);
1203 if (IsEventLogging() != MagickFalse)
1204 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1205 destroy=MagickFalse;
1206 LockSemaphoreInfo(image->semaphore);
1207 image->reference_count--;
1208 if (image->reference_count == 0)
1210 UnlockSemaphoreInfo(image->semaphore);
1211 if (destroy == MagickFalse)
1212 return((Image *) NULL);
1216 DestroyImagePixels(image);
1217 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1218 if (image->montage != (
char *) NULL)
1219 image->montage=DestroyString(image->montage);
1220 if (image->directory != (
char *) NULL)
1221 image->directory=DestroyString(image->directory);
1222 if (image->colormap != (PixelInfo *) NULL)
1223 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1224 if (image->geometry != (
char *) NULL)
1225 image->geometry=DestroyString(image->geometry);
1226 DestroyImageProfiles(image);
1227 DestroyImageProperties(image);
1228 DestroyImageArtifacts(image);
1229 if (image->ascii85 != (Ascii85Info *) NULL)
1230 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1231 if (image->image_info != (ImageInfo *) NULL)
1232 image->image_info=DestroyImageInfo(image->image_info);
1235 RelinquishSemaphoreInfo(&image->semaphore);
1236 image->signature=(~MagickCoreSignature);
1237 image=(Image *) RelinquishMagickMemory(image);
1264MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1266 assert(image_info != (ImageInfo *) NULL);
1267 assert(image_info->signature == MagickCoreSignature);
1268 if (IsEventLogging() != MagickFalse)
1269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1270 image_info->filename);
1271 if (image_info->size != (
char *) NULL)
1272 image_info->size=DestroyString(image_info->size);
1273 if (image_info->extract != (
char *) NULL)
1274 image_info->extract=DestroyString(image_info->extract);
1275 if (image_info->scenes != (
char *) NULL)
1276 image_info->scenes=DestroyString(image_info->scenes);
1277 if (image_info->page != (
char *) NULL)
1278 image_info->page=DestroyString(image_info->page);
1279 if (image_info->sampling_factor != (
char *) NULL)
1280 image_info->sampling_factor=DestroyString(
1281 image_info->sampling_factor);
1282 if (image_info->server_name != (
char *) NULL)
1283 image_info->server_name=DestroyString(
1284 image_info->server_name);
1285 if (image_info->font != (
char *) NULL)
1286 image_info->font=DestroyString(image_info->font);
1287 if (image_info->texture != (
char *) NULL)
1288 image_info->texture=DestroyString(image_info->texture);
1289 if (image_info->density != (
char *) NULL)
1290 image_info->density=DestroyString(image_info->density);
1291 if (image_info->cache != (
void *) NULL)
1292 image_info->cache=DestroyPixelCache(image_info->cache);
1293 if (image_info->profile != (StringInfo *) NULL)
1294 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1295 image_info->profile);
1296 DestroyImageOptions(image_info);
1297 image_info->signature=(~MagickCoreSignature);
1298 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1326MagickExport
void DisassociateImageStream(Image *image)
1328 assert(image != (Image *) NULL);
1329 assert(image->signature == MagickCoreSignature);
1330 if (IsEventLogging() != MagickFalse)
1331 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1332 DisassociateBlob(image);
1357MagickExport
void GetImageInfo(ImageInfo *image_info)
1365 assert(image_info != (ImageInfo *) NULL);
1366 if (IsEventLogging() != MagickFalse)
1367 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1368 (void) memset(image_info,0,
sizeof(*image_info));
1369 image_info->adjoin=MagickTrue;
1370 image_info->interlace=NoInterlace;
1371 image_info->channel=AllChannels;
1372 image_info->quality=UndefinedCompressionQuality;
1373 image_info->antialias=MagickTrue;
1374 image_info->dither=MagickTrue;
1375 image_info->depth=0;
1376 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1377 if (synchronize != (
const char *) NULL)
1379 image_info->synchronize=IsStringTrue(synchronize);
1380 synchronize=DestroyString(synchronize);
1382 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1383 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1384 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1385 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1386 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1388 image_info->signature=MagickCoreSignature;
1413MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1415 return(image_info->file);
1443MagickExport Image *GetImageMask(
const Image *image,
const PixelMask type,
1444 ExceptionInfo *exception)
1462 assert(image != (Image *) NULL);
1463 assert(image->signature == MagickCoreSignature);
1464 if (IsEventLogging() != MagickFalse)
1465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1470 if ((image->channels & ReadMaskChannel) == 0)
1471 return((Image *) NULL);
1474 case WritePixelMask:
1476 if ((image->channels & WriteMaskChannel) == 0)
1477 return((Image *) NULL);
1482 if ((image->channels & CompositeMaskChannel) == 0)
1483 return((Image *) NULL);
1487 mask_image=AcquireImage((ImageInfo *) NULL,exception);
1488 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1489 if (status == MagickFalse)
1490 return(DestroyImage(mask_image));
1492 mask_image->alpha_trait=UndefinedPixelTrait;
1493 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1494 image_view=AcquireVirtualCacheView(image,exception);
1495 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1496#if defined(MAGICKCORE_OPENMP_SUPPORT)
1497 #pragma omp parallel for schedule(static) shared(status) \
1498 magick_number_threads(image,image,image->rows,2)
1500 for (y=0; y < (ssize_t) image->rows; y++)
1511 if (status == MagickFalse)
1513 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1514 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1516 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1521 for (x=0; x < (ssize_t) image->columns; x++)
1527 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1530 case WritePixelMask:
1532 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1537 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1541 p+=(ptrdiff_t) GetPixelChannels(image);
1542 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1544 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1547 mask_view=DestroyCacheView(mask_view);
1548 image_view=DestroyCacheView(image_view);
1549 if (status == MagickFalse)
1550 mask_image=DestroyImage(mask_image);
1576MagickExport ssize_t GetImageReferenceCount(Image *image)
1581 assert(image != (Image *) NULL);
1582 assert(image->signature == MagickCoreSignature);
1583 if (IsEventLogging() != MagickFalse)
1584 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1585 LockSemaphoreInfo(image->semaphore);
1586 reference_count=image->reference_count;
1587 UnlockSemaphoreInfo(image->semaphore);
1588 return(reference_count);
1615MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1617 assert(image != (Image *) NULL);
1618 assert(image->signature == MagickCoreSignature);
1619 if (IsEventLogging() != MagickFalse)
1620 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1621 return(GetPixelCacheVirtualMethod(image));
1660static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1664 specifier = end[-1];
1667 length = (size_t) (end-start);
1672 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1673 return(MagickFalse);
1674 if ((length == 1) && (*start == specifier))
1683 if ((length >= 3) && (start[1] ==
'0'))
1684 return(MagickFalse);
1687 for ( ; i < (length-1); i++)
1688 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1689 return(MagickFalse);
1692 return(MagickFalse);
1695MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1696 Image *image,
const char *format,
int value,
char *filename,
1697 ExceptionInfo *exception)
1701 pattern[MagickPathExtent];
1706 assert(format != (
const char *) NULL);
1707 assert(filename != (
char *) NULL);
1708 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1710 (void) CopyMagickString(filename,format,MagickPathExtent);
1711 return(strlen(filename));
1713 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1731 specifier_start=cursor;
1732 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1734 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1737 *specifier_end = cursor+1;
1739 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1742 format_specifier[MagickPathExtent];
1745 length = (size_t) (cursor-specifier_start),
1751 (void) snprintf(format_specifier,
sizeof(format_specifier),
1752 "%%%.*s%c",(
int) length,specifier_start,*cursor);
1753 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1755 pattern_length=strlen(pattern);
1756 if ((count <= 0) || ((
size_t) count != pattern_length))
1758 if ((p-filename+pattern_length) >= MagickPathExtent)
1760 (void) CopyMagickString(p,pattern,(
size_t) (MagickPathExtent-
1779 *end = strchr(cursor,
']'),
1780 *option = (
const char *) NULL;
1786 if (end == (
const char *) NULL)
1788 extent=(size_t) (end-cursor-1);
1789 if (extent >=
sizeof(pattern))
1791 (void) CopyMagickString(pattern,cursor+1,extent+1);
1792 pattern[extent]=
'\0';
1795 option=GetImageProperty(image,pattern,exception);
1796 if (option == (
const char *) NULL)
1797 option=GetImageArtifact(image,pattern);
1799 if ((option == (
const char *) NULL) &&
1800 (image_info != (ImageInfo *) NULL))
1801 option=GetImageOption(image_info,pattern);
1802 if (option == (
const char *) NULL)
1804 option_length=strlen(option);
1805 if ((p-filename+option_length) >= MagickPathExtent)
1807 (void) CopyMagickString(p,option,(
size_t) (MagickPathExtent-
1817 if ((p-filename+1) >= MagickPathExtent)
1822 return(strlen(filename));
1852MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1853 ExceptionInfo *exception)
1855#if !defined(MAGICKCORE_HDRI_SUPPORT)
1858 return(MagickFalse);
1869 assert(image != (Image *) NULL);
1870 assert(image->signature == MagickCoreSignature);
1871 if (IsEventLogging() != MagickFalse)
1872 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1873 image_view=AcquireVirtualCacheView(image,exception);
1874#if defined(MAGICKCORE_OPENMP_SUPPORT)
1875 #pragma omp parallel for schedule(static) shared(hdri) \
1876 magick_number_threads(image,image,image->rows,2)
1878 for (y=0; y < (ssize_t) image->rows; y++)
1886 if (hdri != MagickFalse)
1888 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1889 if (p == (
const Quantum *) NULL)
1891 for (x=0; x < (ssize_t) image->columns; x++)
1896 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1904 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1905 if (traits == UndefinedPixelTrait)
1907 pixel=(double) p[i];
1908 if ((pixel < 0.0) || (pixel > (
double) QuantumRange) ||
1909 (pixel != (
double) ((QuantumAny) pixel)))
1915 if (hdri != MagickFalse)
1917 p+=(ptrdiff_t) GetPixelChannels(image);
1920 image_view=DestroyCacheView(image_view);
1948MagickExport MagickBooleanType IsImageObject(
const Image *image)
1953 assert(image != (Image *) NULL);
1954 if (IsEventLogging() != MagickFalse)
1955 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1956 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1957 if (p->signature != MagickCoreSignature)
1958 return(MagickFalse);
1985MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1988 magick[MagickPathExtent],
1989 filename[MagickPathExtent];
1994 assert(image != (Image *) NULL);
1995 assert(image->signature == MagickCoreSignature);
1996 if (IsEventLogging() != MagickFalse)
1997 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1998 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1999 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
2000 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2002 if (p->taint != MagickFalse)
2004 if (LocaleCompare(p->magick,magick) != 0)
2006 if (LocaleCompare(p->filename,filename) != 0)
2009 return(MagickFalse);
2038MagickExport MagickBooleanType ModifyImage(Image **image,
2039 ExceptionInfo *exception)
2044 assert(image != (Image **) NULL);
2045 assert(*image != (Image *) NULL);
2046 assert((*image)->signature == MagickCoreSignature);
2047 if (IsEventLogging() != MagickFalse)
2048 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2049 if (GetImageReferenceCount(*image) <= 1)
2051 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2052 LockSemaphoreInfo((*image)->semaphore);
2053 (*image)->reference_count--;
2054 UnlockSemaphoreInfo((*image)->semaphore);
2092MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2093 const size_t width,
const size_t height,
const PixelInfo *background,
2094 ExceptionInfo *exception)
2108 assert(image_info != (
const ImageInfo *) NULL);
2109 assert(image_info->signature == MagickCoreSignature);
2110 assert(background != (
const PixelInfo *) NULL);
2111 if (IsEventLogging() != MagickFalse)
2112 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2113 image=AcquireImage(image_info,exception);
2114 image->columns=width;
2116 image->colorspace=background->colorspace;
2117 image->alpha_trait=background->alpha_trait;
2118 image->fuzz=background->fuzz;
2119 image->depth=background->depth;
2121 image_view=AcquireAuthenticCacheView(image,exception);
2122#if defined(MAGICKCORE_OPENMP_SUPPORT)
2123 #pragma omp parallel for schedule(static) shared(status) \
2124 magick_number_threads(image,image,image->rows,2)
2126 for (y=0; y < (ssize_t) image->rows; y++)
2134 if (status == MagickFalse)
2136 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2137 if (q == (Quantum *) NULL)
2142 for (x=0; x < (ssize_t) image->columns; x++)
2144 SetPixelViaPixelInfo(image,background,q);
2145 q+=(ptrdiff_t) GetPixelChannels(image);
2147 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2150 image_view=DestroyCacheView(image_view);
2151 if (status == MagickFalse)
2152 image=DestroyImage(image);
2179MagickExport Image *ReferenceImage(Image *image)
2181 assert(image != (Image *) NULL);
2182 assert(image->signature == MagickCoreSignature);
2183 if (IsEventLogging() != MagickFalse)
2184 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2185 LockSemaphoreInfo(image->semaphore);
2186 image->reference_count++;
2187 UnlockSemaphoreInfo(image->semaphore);
2215MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2223 assert(image != (Image *) NULL);
2224 assert(image->signature == MagickCoreSignature);
2225 if (IsEventLogging() != MagickFalse)
2226 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2227 flags=ParseAbsoluteGeometry(page,&geometry);
2228 if ((flags & WidthValue) != 0)
2230 if ((flags & HeightValue) == 0)
2231 geometry.height=geometry.width;
2232 image->page.width=geometry.width;
2233 image->page.height=geometry.height;
2235 if ((flags & AspectValue) != 0)
2237 if ((flags & XValue) != 0)
2238 image->page.x+=geometry.x;
2239 if ((flags & YValue) != 0)
2240 image->page.y+=geometry.y;
2244 if ((flags & XValue) != 0)
2246 image->page.x=geometry.x;
2247 if ((image->page.width == 0) && (geometry.x > 0))
2248 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2250 if ((flags & YValue) != 0)
2252 image->page.y=geometry.y;
2253 if ((image->page.height == 0) && (geometry.y > 0))
2254 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2286MagickExport MagickBooleanType ResetImagePixels(Image *image,
2287 ExceptionInfo *exception)
2304 assert(image != (Image *) NULL);
2305 assert(image->signature == MagickCoreSignature);
2306 if (IsEventLogging() != MagickFalse)
2307 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2308 pixels=AcquirePixelCachePixels(image,&length,exception);
2309 if (pixels != (
void *) NULL)
2314 (void) memset(pixels,0,length);
2321 image_view=AcquireAuthenticCacheView(image,exception);
2322#if defined(MAGICKCORE_OPENMP_SUPPORT)
2323 #pragma omp parallel for schedule(static) shared(status) \
2324 magick_number_threads(image,image,image->rows,2)
2326 for (y=0; y < (ssize_t) image->rows; y++)
2334 if (status == MagickFalse)
2336 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2337 if (q == (Quantum *) NULL)
2342 for (x=0; x < (ssize_t) image->columns; x++)
2344 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2345 q+=(ptrdiff_t) GetPixelChannels(image);
2347 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2350 image_view=DestroyCacheView(image_view);
2382MagickExport MagickBooleanType SetImageAlpha(Image *image,
const Quantum alpha,
2383 ExceptionInfo *exception)
2394 assert(image != (Image *) NULL);
2395 assert(image->signature == MagickCoreSignature);
2396 if (IsEventLogging() != MagickFalse)
2397 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2398 image->alpha_trait=BlendPixelTrait;
2400 image_view=AcquireAuthenticCacheView(image,exception);
2401#if defined(MAGICKCORE_OPENMP_SUPPORT)
2402 #pragma omp parallel for schedule(static) shared(status) \
2403 magick_number_threads(image,image,image->rows,2)
2405 for (y=0; y < (ssize_t) image->rows; y++)
2413 if (status == MagickFalse)
2415 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2416 if (q == (Quantum *) NULL)
2421 for (x=0; x < (ssize_t) image->columns; x++)
2423 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2424 SetPixelAlpha(image,alpha,q);
2425 q+=(ptrdiff_t) GetPixelChannels(image);
2427 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2430 image_view=DestroyCacheView(image_view);
2461MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2462 ExceptionInfo *exception)
2476 assert(image != (Image *) NULL);
2477 assert(image->signature == MagickCoreSignature);
2478 if (IsEventLogging() != MagickFalse)
2479 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2480 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2481 return(MagickFalse);
2482 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2483 ((image->alpha_trait & BlendPixelTrait) == 0))
2484 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2485 ConformPixelInfo(image,&image->background_color,&background,exception);
2490 image_view=AcquireAuthenticCacheView(image,exception);
2491#if defined(MAGICKCORE_OPENMP_SUPPORT)
2492 #pragma omp parallel for schedule(static) shared(status) \
2493 magick_number_threads(image,image,image->rows,2)
2495 for (y=0; y < (ssize_t) image->rows; y++)
2503 if (status == MagickFalse)
2505 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2506 if (q == (Quantum *) NULL)
2511 for (x=0; x < (ssize_t) image->columns; x++)
2513 SetPixelViaPixelInfo(image,&background,q);
2514 q+=(ptrdiff_t) GetPixelChannels(image);
2516 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2519 image_view=DestroyCacheView(image_view);
2549MagickExport ChannelType SetImageChannelMask(Image *image,
2550 const ChannelType channel_mask)
2552 return(SetPixelChannelMask(image,channel_mask));
2582MagickExport MagickBooleanType SetImageColor(Image *image,
2583 const PixelInfo *color,ExceptionInfo *exception)
2594 assert(image != (Image *) NULL);
2595 assert(image->signature == MagickCoreSignature);
2596 assert(color != (
const PixelInfo *) NULL);
2597 if (IsEventLogging() != MagickFalse)
2598 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2599 image->colorspace=color->colorspace;
2600 image->alpha_trait=color->alpha_trait;
2601 image->fuzz=color->fuzz;
2602 image->depth=color->depth;
2604 image_view=AcquireAuthenticCacheView(image,exception);
2605#if defined(MAGICKCORE_OPENMP_SUPPORT)
2606 #pragma omp parallel for schedule(static) shared(status) \
2607 magick_number_threads(image,image,image->rows,2)
2609 for (y=0; y < (ssize_t) image->rows; y++)
2617 if (status == MagickFalse)
2619 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2620 if (q == (Quantum *) NULL)
2625 for (x=0; x < (ssize_t) image->columns; x++)
2627 SetPixelViaPixelInfo(image,color,q);
2628 q+=(ptrdiff_t) GetPixelChannels(image);
2630 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2633 image_view=DestroyCacheView(image_view);
2665MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2666 const ClassType storage_class,ExceptionInfo *exception)
2668 assert(image != (Image *) NULL);
2669 assert(image->signature == MagickCoreSignature);
2670 assert(exception != (ExceptionInfo *) NULL);
2671 assert(exception->signature == MagickCoreSignature);
2672 if (IsEventLogging() != MagickFalse)
2673 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2674 image->storage_class=storage_class;
2675 return(SyncImagePixelCache(image,exception));
2707MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2708 const size_t rows,ExceptionInfo *exception)
2710 if ((columns == 0) || (rows == 0))
2711 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2712 if ((columns > (
size_t) MAGICK_SSIZE_MAX) ||
2713 (rows > (
size_t) MAGICK_SSIZE_MAX))
2714 ThrowBinaryException(ImageError,
"ImageSizeLimitExceeded",image->filename);
2715 image->columns=columns;
2717 if (image->depth == 0)
2720 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2721 "ImageDepthNotSupported",
"`%s'",image->filename);
2723 if (image->depth > (8*
sizeof(MagickSizeType)))
2725 image->depth=8*
sizeof(MagickSizeType);
2726 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2727 "ImageDepthNotSupported",
"`%s'",image->filename);
2729 return(SyncImagePixelCache(image,exception));
2767static const MagickInfo *SetImageInfoFromExtension(ImageInfo *image_info,
2768 const char *component,
char *magic,ExceptionInfo *exception)
2780 *format_type_formats[] =
2804 (void) CopyMagickString(magic,component,MagickPathExtent);
2809 format_type=UndefinedFormatType;
2810 magick_info=GetMagickInfo(magic,exception);
2811 if ((magick_info != (
const MagickInfo *) NULL) &&
2812 (magick_info->format_type != UndefinedFormatType))
2813 format_type=magick_info->format_type;
2815 while ((format_type == UndefinedFormatType) &&
2816 (format_type_formats[i] != (
char *) NULL))
2818 if ((*magic == *format_type_formats[i]) &&
2819 (LocaleCompare(magic,format_type_formats[i]) == 0))
2820 format_type=ExplicitFormatType;
2823 if (format_type == UndefinedFormatType)
2824 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2826 if (format_type == ExplicitFormatType)
2828 image_info->affirm=MagickTrue;
2829 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2831 if (LocaleCompare(magic,
"RGB") == 0)
2832 image_info->affirm=MagickFalse;
2833 return(magick_info);
2836MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2837 const unsigned int frames,ExceptionInfo *exception)
2840 component[MagickPathExtent],
2841 magic[MagickPathExtent],
2842 path[MagickPathExtent],
2869 assert(image_info != (ImageInfo *) NULL);
2870 assert(image_info->signature == MagickCoreSignature);
2871 if (IsEventLogging() != MagickFalse)
2872 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2873 image_info->filename);
2875 GetPathComponent(image_info->filename,SubimagePath,component);
2876 if (*component !=
'\0')
2881 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2883 if (IsGeometry(component) != MagickFalse)
2884 (void) CloneString(&image_info->extract,component);
2892 (void) CloneString(&image_info->scenes,component);
2893 image_info->scene=StringToUnsignedLong(image_info->scenes);
2894 image_info->number_scenes=image_info->scene;
2895 p=image_info->scenes;
2896 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2898 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2900 first=(size_t) strtol(p,&q,10);
2902 while (isspace((
int) ((
unsigned char) *q)) != 0)
2905 last=(size_t) strtol(q+1,&q,10);
2908 if (first < image_info->scene)
2909 image_info->scene=first;
2910 if (last > image_info->number_scenes)
2911 image_info->number_scenes=last;
2914 image_info->number_scenes-=image_info->scene-1;
2918 if (*image_info->magick ==
'\0')
2919 GetPathComponent(image_info->filename,ExtensionPath,component);
2920 if (*component !=
'\0')
2925 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2926 GetPathComponent(path,ExtensionPath,component);
2928 image_info->affirm=MagickFalse;
2929 sans_exception=AcquireExceptionInfo();
2930 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2931 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2937 GetPathComponent(image_info->filename,MagickPath,magic);
2940 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2941 magick_info=GetMagickInfo(magic,sans_exception);
2942 if ((magick_info != (
const MagickInfo *) NULL) &&
2943 (magick_info->format_type == ExplicitFormatType))
2944 image_info->affirm=MagickTrue;
2946 GetPathComponent(image_info->filename,CanonicalPath,component);
2948 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2949 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2960 magick_info=GetMagickInfo(magic,sans_exception);
2961 delegate_info=(
const DelegateInfo *) NULL;
2962 if (magick_info == (
const MagickInfo *) NULL)
2964 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2965 if (delegate_info == (
const DelegateInfo *) NULL)
2966 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2967 if ((delegate_info == (
const DelegateInfo *) NULL) &&
2968 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2973 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2977 if (((magick_info != (
const MagickInfo *) NULL) ||
2978 (delegate_info != (
const DelegateInfo *) NULL)) &&
2979 (IsMagickConflict(magic) == MagickFalse))
2981 image_info->affirm=MagickTrue;
2982 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2983 GetPathComponent(image_info->filename,CanonicalPath,component);
2984 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
2985 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2986 (void) CopyMagickString(image_info->filename,component,
2990 sans_exception=DestroyExceptionInfo(sans_exception);
2991 if ((magick_info == (
const MagickInfo *) NULL) ||
2992 (GetMagickEndianSupport(magick_info) == MagickFalse))
2993 image_info->endian=UndefinedEndian;
2994 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2999 (void) InterpretImageFilename(image_info,(Image *) NULL,
3000 image_info->filename,(
int) image_info->scene,component,exception);
3001 if ((LocaleCompare(component,image_info->filename) != 0) &&
3002 (strchr(component,
'%') == (
char *) NULL))
3003 image_info->adjoin=MagickFalse;
3005 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3010 magick_info=GetMagickInfo(magic,exception);
3011 if (magick_info != (
const MagickInfo *) NULL)
3012 if (GetMagickAdjoin(magick_info) == MagickFalse)
3013 image_info->adjoin=MagickFalse;
3015 if (image_info->affirm != MagickFalse)
3028 magick_size=GetMagicPatternExtent(exception);
3029 if (magick_size == 0)
3030 return(MagickFalse);
3031 image=AcquireImage(image_info,exception);
3032 (void) CopyMagickString(image->filename,image_info->filename,
3034 sans_exception=AcquireExceptionInfo();
3035 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3036 sans_exception=DestroyExceptionInfo(sans_exception);
3037 if (status == MagickFalse)
3039 image=DestroyImage(image);
3040 return(MagickFalse);
3042 if ((IsBlobSeekable(image) == MagickFalse) ||
3043 (IsBlobExempt(image) != MagickFalse))
3049 status=ImageToFile(image,component,exception);
3050 if (CloseBlob(image) == MagickFalse)
3052 if (status == MagickFalse)
3054 (void) RelinquishUniqueFileResource(component);
3055 image=DestroyImage(image);
3056 return(MagickFalse);
3058 SetImageInfoFile(image_info,(FILE *) NULL);
3059 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3060 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3061 if (status == MagickFalse)
3063 (void) RelinquishUniqueFileResource(component);
3064 image=DestroyImage(image);
3065 return(MagickFalse);
3067 (void) CopyMagickString(image_info->filename,component,
3069 image_info->temporary=MagickTrue;
3071 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3072 if (magick == (
unsigned char *) NULL)
3074 (void) CloseBlob(image);
3075 image=DestroyImage(image);
3076 return(MagickFalse);
3078 (void) memset(magick,0,magick_size);
3079 count=ReadBlob(image,magick_size,magick);
3080 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3081 (void) CloseBlob(image);
3082 image=DestroyImage(image);
3086 sans_exception=AcquireExceptionInfo();
3087 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3088 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3089 if ((magic_info != (
const MagicInfo *) NULL) &&
3090 (GetMagicName(magic_info) != (
char *) NULL))
3095 if ((magick_info != (
const MagickInfo *) NULL) &&
3096 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3097 (LocaleCompare(magick_info->magick_module,GetMagicName(
3099 (void) CopyMagickString(image_info->magick,magick_info->name,
3103 (void) CopyMagickString(image_info->magick,GetMagicName(
3104 magic_info),MagickPathExtent);
3105 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3107 if ((magick_info == (
const MagickInfo *) NULL) ||
3108 (GetMagickEndianSupport(magick_info) == MagickFalse))
3109 image_info->endian=UndefinedEndian;
3110 sans_exception=DestroyExceptionInfo(sans_exception);
3113 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3114 if ((magick_info == (
const MagickInfo *) NULL) ||
3115 (GetMagickEndianSupport(magick_info) == MagickFalse))
3116 image_info->endian=UndefinedEndian;
3117 sans_exception=DestroyExceptionInfo(sans_exception);
3149MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3150 const size_t length)
3152 assert(image_info != (ImageInfo *) NULL);
3153 assert(image_info->signature == MagickCoreSignature);
3154 if (IsEventLogging() != MagickFalse)
3155 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3156 image_info->filename);
3157 image_info->blob=(
void *) blob;
3158 image_info->length=length;
3186MagickExport
void SetImageInfoCustomStream(ImageInfo *image_info,
3187 CustomStreamInfo *custom_stream)
3189 assert(image_info != (ImageInfo *) NULL);
3190 assert(image_info->signature == MagickCoreSignature);
3191 if (IsEventLogging() != MagickFalse)
3192 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3193 image_info->filename);
3194 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3221MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3223 assert(image_info != (ImageInfo *) NULL);
3224 assert(image_info->signature == MagickCoreSignature);
3225 if (IsEventLogging() != MagickFalse)
3226 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3227 image_info->filename);
3228 image_info->file=file;
3261MagickExport MagickBooleanType SetImageMask(Image *image,
const PixelMask type,
3262 const Image *mask,ExceptionInfo *exception)
3277 assert(image != (Image *) NULL);
3278 if (IsEventLogging() != MagickFalse)
3279 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3280 assert(image->signature == MagickCoreSignature);
3281 image->mask_trait=UndefinedPixelTrait;
3282 if (mask == (
const Image *) NULL)
3288 image->channels=(ChannelType) ((
unsigned int) image->channels &
3289 (
unsigned int) ~ReadMaskChannel);
3292 case WritePixelMask:
3294 image->channels=(ChannelType) ((
unsigned int) image->channels &
3295 (
unsigned int) ~WriteMaskChannel);
3300 image->channels=(ChannelType) ((
unsigned int) image->channels &
3301 (
unsigned int) ~CompositeMaskChannel);
3305 return(SyncImagePixelCache(image,exception));
3311 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3314 case WritePixelMask:
3316 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3321 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3325 if (SyncImagePixelCache(image,exception) == MagickFalse)
3326 return(MagickFalse);
3328 mask_view=AcquireVirtualCacheView(mask,exception);
3329 image_view=AcquireAuthenticCacheView(image,exception);
3330#if defined(MAGICKCORE_OPENMP_SUPPORT)
3331 #pragma omp parallel for schedule(static) shared(status) \
3332 magick_number_threads(mask,image,image->rows,2)
3334 for (y=0; y < (ssize_t) image->rows; y++)
3345 if (status == MagickFalse)
3347 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3348 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3349 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3354 for (x=0; x < (ssize_t) image->columns; x++)
3360 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3361 intensity=GetPixelIntensity(mask,p);
3366 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3369 case WritePixelMask:
3371 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3376 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3380 p+=(ptrdiff_t) GetPixelChannels(mask);
3381 q+=(ptrdiff_t) GetPixelChannels(image);
3383 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3386 mask_view=DestroyCacheView(mask_view);
3387 image_view=DestroyCacheView(image_view);
3388 image->mask_trait=UpdatePixelTrait;
3422MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3423 const PixelMask type,
const RectangleInfo *region,ExceptionInfo *exception)
3437 assert(image != (Image *) NULL);
3438 assert(image->signature == MagickCoreSignature);
3439 if (IsEventLogging() != MagickFalse)
3440 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3441 image->mask_trait=UndefinedPixelTrait;
3442 if (region == (
const RectangleInfo *) NULL)
3448 image->channels=(ChannelType) ((
unsigned int) image->channels &
3449 (
unsigned int) ~ReadMaskChannel);
3452 case WritePixelMask:
3454 image->channels=(ChannelType) ((
unsigned int) image->channels &
3455 (
unsigned int) ~WriteMaskChannel);
3460 image->channels=(ChannelType) ((
unsigned int) image->channels &
3461 (
unsigned int) ~CompositeMaskChannel);
3465 return(SyncImagePixelCache(image,exception));
3471 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3474 case WritePixelMask:
3476 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3481 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3485 if (SyncImagePixelCache(image,exception) == MagickFalse)
3486 return(MagickFalse);
3488 image_view=AcquireAuthenticCacheView(image,exception);
3489#if defined(MAGICKCORE_OPENMP_SUPPORT)
3490 #pragma omp parallel for schedule(static) shared(status) \
3491 magick_number_threads(image,image,image->rows,2)
3493 for (y=0; y < (ssize_t) image->rows; y++)
3501 if (status == MagickFalse)
3503 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3504 if (q == (Quantum *) NULL)
3509 for (x=0; x < (ssize_t) image->columns; x++)
3515 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3516 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3522 SetPixelReadMask(image,pixel,q);
3525 case WritePixelMask:
3527 SetPixelWriteMask(image,pixel,q);
3532 SetPixelCompositeMask(image,pixel,q);
3536 q+=(ptrdiff_t) GetPixelChannels(image);
3538 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3541 image->mask_trait=UpdatePixelTrait;
3542 image_view=DestroyCacheView(image_view);
3575MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3576 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3578 assert(image != (
const Image *) NULL);
3579 assert(image->signature == MagickCoreSignature);
3580 if (IsEventLogging() != MagickFalse)
3581 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3582 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3620static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3621 const ssize_t offset,ExceptionInfo *exception)
3648 if (images->previous == (Image *) NULL)
3651 SetGeometry(smush_image,&right_geometry);
3652 GravityAdjustGeometry(right_image->columns,right_image->rows,
3653 right_image->gravity,&right_geometry);
3654 left_image=images->previous;
3655 SetGeometry(smush_image,&left_geometry);
3656 GravityAdjustGeometry(left_image->columns,left_image->rows,
3657 left_image->gravity,&left_geometry);
3658 gap=right_image->columns;
3659 left_view=AcquireVirtualCacheView(left_image,exception);
3660 right_view=AcquireVirtualCacheView(right_image,exception);
3661 for (y=0; y < (ssize_t) smush_image->rows; y++)
3663 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3665 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3666 if ((p == (
const Quantum *) NULL) ||
3667 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3668 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3671 i=(ssize_t) left_image->columns-x-1;
3672 for (x=0; x < (ssize_t) right_image->columns; x++)
3674 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3676 if ((p == (
const Quantum *) NULL) ||
3677 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3678 ((x+i) >= (ssize_t) gap))
3681 if ((x+i) < (ssize_t) gap)
3684 right_view=DestroyCacheView(right_view);
3685 left_view=DestroyCacheView(left_view);
3686 if (y < (ssize_t) smush_image->rows)
3688 return((ssize_t) gap-offset);
3691static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3692 const ssize_t offset,ExceptionInfo *exception)
3719 if (images->previous == (Image *) NULL)
3721 bottom_image=images;
3722 SetGeometry(smush_image,&bottom_geometry);
3723 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3724 bottom_image->gravity,&bottom_geometry);
3725 top_image=images->previous;
3726 SetGeometry(smush_image,&top_geometry);
3727 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3729 gap=bottom_image->rows;
3730 top_view=AcquireVirtualCacheView(top_image,exception);
3731 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3732 for (x=0; x < (ssize_t) smush_image->columns; x++)
3734 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3736 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3737 if ((p == (
const Quantum *) NULL) ||
3738 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3739 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3742 i=(ssize_t) top_image->rows-y-1;
3743 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3745 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3747 if ((p == (
const Quantum *) NULL) ||
3748 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3749 ((y+i) >= (ssize_t) gap))
3752 if ((y+i) < (ssize_t) gap)
3755 bottom_view=DestroyCacheView(bottom_view);
3756 top_view=DestroyCacheView(top_view);
3757 if (x < (ssize_t) smush_image->columns)
3759 return((ssize_t) gap-offset);
3762MagickExport Image *SmushImages(
const Image *images,
3763 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3765#define SmushImageTag "Smush/Image"
3801 assert(images != (Image *) NULL);
3802 assert(images->signature == MagickCoreSignature);
3803 assert(exception != (ExceptionInfo *) NULL);
3804 assert(exception->signature == MagickCoreSignature);
3805 if (IsEventLogging() != MagickFalse)
3806 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3808 alpha_trait=image->alpha_trait;
3810 width=image->columns;
3812 next=GetNextImageInList(image);
3813 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3815 if (next->alpha_trait != UndefinedPixelTrait)
3816 alpha_trait=BlendPixelTrait;
3818 if (stack != MagickFalse)
3820 if (next->columns > width)
3821 width=next->columns;
3823 if (next->previous != (Image *) NULL)
3824 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3827 width+=next->columns;
3828 if (next->previous != (Image *) NULL)
3829 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3830 if (next->rows > height)
3836 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3837 if (smush_image == (Image *) NULL)
3838 return((Image *) NULL);
3839 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3841 smush_image=DestroyImage(smush_image);
3842 return((Image *) NULL);
3844 smush_image->alpha_trait=alpha_trait;
3845 (void) SetImageBackgroundColor(smush_image,exception);
3849 for (n=0; n < (MagickOffsetType) number_images; n++)
3851 SetGeometry(smush_image,&geometry);
3852 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3853 if (stack != MagickFalse)
3855 x_offset-=geometry.x;
3856 y_offset-=SmushYGap(smush_image,image,offset,exception);
3860 x_offset-=SmushXGap(smush_image,image,offset,exception);
3861 y_offset-=geometry.y;
3863 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3864 y_offset,exception);
3865 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3866 if (proceed == MagickFalse)
3868 if (stack == MagickFalse)
3870 x_offset+=(ssize_t) image->columns;
3876 y_offset+=(ssize_t) image->rows;
3878 image=GetNextImageInList(image);
3880 if (stack == MagickFalse)
3881 smush_image->columns=(size_t) x_offset;
3883 smush_image->rows=(size_t) y_offset;
3884 if (status == MagickFalse)
3885 smush_image=DestroyImage(smush_image);
3886 return(smush_image);
3913MagickExport MagickBooleanType StripImage(Image *image,
3914 ExceptionInfo *magick_unused(exception))
3919 magick_unreferenced(exception);
3920 assert(image != (Image *) NULL);
3921 if (IsEventLogging() != MagickFalse)
3922 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3923 DestroyImageProfiles(image);
3924 (void) DeleteImageProperty(image,
"comment");
3925 (void) DeleteImageProperty(image,
"date:create");
3926 (void) DeleteImageProperty(image,
"date:modify");
3927 (void) DeleteImageProperty(image,
"date:timestamp");
3928 status=SetImageArtifact(image,
"png:exclude-chunk",
3929 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3959static inline Quantum PushColormapIndex(Image *image,
const Quantum index,
3960 MagickBooleanType *range_exception)
3962 if ((
size_t) index < image->colors)
3964 *range_exception=MagickTrue;
3965 return((Quantum) 0);
3968MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3981 assert(image != (Image *) NULL);
3982 assert(image->signature == MagickCoreSignature);
3983 if (IsEventLogging() != MagickFalse)
3984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3985 if (image->ping != MagickFalse)
3987 if (image->storage_class != PseudoClass)
3988 return(MagickFalse);
3989 assert(image->colormap != (PixelInfo *) NULL);
3990 range_exception=MagickFalse;
3993 image_view=AcquireAuthenticCacheView(image,exception);
3994#if defined(MAGICKCORE_OPENMP_SUPPORT)
3995 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3996 magick_number_threads(image,image,image->rows,2)
3998 for (y=0; y < (ssize_t) image->rows; y++)
4009 if (status == MagickFalse)
4011 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4012 if (q == (Quantum *) NULL)
4017 for (x=0; x < (ssize_t) image->columns; x++)
4019 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4020 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4021 q+=(ptrdiff_t) GetPixelChannels(image);
4023 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4026 image_view=DestroyCacheView(image_view);
4028 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4029 (void) ThrowMagickException(exception,GetMagickModule(),
4030 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4071MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4072 Image *images,ExceptionInfo *exception)
4077 assert(image_info != (
const ImageInfo *) NULL);
4078 assert(image_info->signature == MagickCoreSignature);
4079 assert(images != (Image *) NULL);
4080 assert(images->signature == MagickCoreSignature);
4081 if (IsEventLogging() != MagickFalse)
4082 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4084 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4085 (
void) SyncImageSettings(image_info,image,exception);
4086 (void) DeleteImageOption(image_info,
"page");
4090MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4091 Image *image,ExceptionInfo *exception)
4108 assert(image_info != (
const ImageInfo *) NULL);
4109 assert(image_info->signature == MagickCoreSignature);
4110 assert(image != (Image *) NULL);
4111 assert(image->signature == MagickCoreSignature);
4112 if (IsEventLogging() != MagickFalse)
4113 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4114 option=GetImageOption(image_info,
"background");
4115 if (option != (
const char *) NULL)
4116 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4118 option=GetImageOption(image_info,
"black-point-compensation");
4119 if (option != (
const char *) NULL)
4120 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4121 MagickBooleanOptions,MagickFalse,option);
4122 option=GetImageOption(image_info,
"blue-primary");
4123 if (option != (
const char *) NULL)
4125 flags=ParseGeometry(option,&geometry_info);
4126 if ((flags & RhoValue) != 0)
4127 image->chromaticity.blue_primary.x=geometry_info.rho;
4128 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4129 if ((flags & SigmaValue) != 0)
4130 image->chromaticity.blue_primary.y=geometry_info.sigma;
4132 option=GetImageOption(image_info,
"bordercolor");
4133 if (option != (
const char *) NULL)
4134 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4137 option=GetImageOption(image_info,
"compose");
4138 if (option != (
const char *) NULL)
4139 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4140 MagickFalse,option);
4142 option=GetImageOption(image_info,
"compress");
4143 if (option != (
const char *) NULL)
4144 image->compression=(CompressionType) ParseCommandOption(
4145 MagickCompressOptions,MagickFalse,option);
4146 option=GetImageOption(image_info,
"debug");
4147 if (option != (
const char *) NULL)
4148 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4149 MagickFalse,option);
4150 option=GetImageOption(image_info,
"density");
4151 if (option != (
const char *) NULL)
4153 flags=ParseGeometry(option,&geometry_info);
4154 if ((flags & RhoValue) != 0)
4155 image->resolution.x=geometry_info.rho;
4156 image->resolution.y=image->resolution.x;
4157 if ((flags & SigmaValue) != 0)
4158 image->resolution.y=geometry_info.sigma;
4160 option=GetImageOption(image_info,
"depth");
4161 if (option != (
const char *) NULL)
4162 image->depth=StringToUnsignedLong(option);
4163 option=GetImageOption(image_info,
"endian");
4164 if (option != (
const char *) NULL)
4165 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4166 MagickFalse,option);
4167 option=GetImageOption(image_info,
"filter");
4168 if (option != (
const char *) NULL)
4169 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4170 MagickFalse,option);
4171 option=GetImageOption(image_info,
"fuzz");
4172 if (option != (
const char *) NULL)
4173 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4174 option=GetImageOption(image_info,
"gravity");
4175 if (option != (
const char *) NULL)
4176 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4177 MagickFalse,option);
4178 option=GetImageOption(image_info,
"green-primary");
4179 if (option != (
const char *) NULL)
4181 flags=ParseGeometry(option,&geometry_info);
4182 if ((flags & RhoValue) != 0)
4183 image->chromaticity.green_primary.x=geometry_info.rho;
4184 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4185 if ((flags & SigmaValue) != 0)
4186 image->chromaticity.green_primary.y=geometry_info.sigma;
4188 option=GetImageOption(image_info,
"intent");
4189 if (option != (
const char *) NULL)
4190 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4191 MagickIntentOptions,MagickFalse,option);
4192 option=GetImageOption(image_info,
"intensity");
4193 if (option != (
const char *) NULL)
4194 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4195 MagickPixelIntensityOptions,MagickFalse,option);
4196 option=GetImageOption(image_info,
"interlace");
4197 if (option != (
const char *) NULL)
4198 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4199 MagickFalse,option);
4200 option=GetImageOption(image_info,
"interpolate");
4201 if (option != (
const char *) NULL)
4202 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4203 MagickInterpolateOptions,MagickFalse,option);
4204 option=GetImageOption(image_info,
"loop");
4205 if (option != (
const char *) NULL)
4206 image->iterations=StringToUnsignedLong(option);
4207 option=GetImageOption(image_info,
"mattecolor");
4208 if (option != (
const char *) NULL)
4209 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4211 option=GetImageOption(image_info,
"orient");
4212 if (option != (
const char *) NULL)
4213 image->orientation=(OrientationType) ParseCommandOption(
4214 MagickOrientationOptions,MagickFalse,option);
4215 option=GetImageOption(image_info,
"page");
4216 if (option != (
const char *) NULL)
4221 geometry=GetPageGeometry(option);
4222 flags=ParseAbsoluteGeometry(geometry,&image->page);
4223 geometry=DestroyString(geometry);
4225 option=GetImageOption(image_info,
"quality");
4226 if (option != (
const char *) NULL)
4227 image->quality=StringToUnsignedLong(option);
4228 option=GetImageOption(image_info,
"red-primary");
4229 if (option != (
const char *) NULL)
4231 flags=ParseGeometry(option,&geometry_info);
4232 if ((flags & RhoValue) != 0)
4233 image->chromaticity.red_primary.x=geometry_info.rho;
4234 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4235 if ((flags & SigmaValue) != 0)
4236 image->chromaticity.red_primary.y=geometry_info.sigma;
4238 if (image_info->quality != UndefinedCompressionQuality)
4239 image->quality=image_info->quality;
4240 option=GetImageOption(image_info,
"scene");
4241 if (option != (
const char *) NULL)
4242 image->scene=StringToUnsignedLong(option);
4243 option=GetImageOption(image_info,
"taint");
4244 if (option != (
const char *) NULL)
4245 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4246 MagickFalse,option);
4247 option=GetImageOption(image_info,
"tile-offset");
4248 if (option != (
const char *) NULL)
4253 geometry=GetPageGeometry(option);
4254 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4255 geometry=DestroyString(geometry);
4257 option=GetImageOption(image_info,
"transparent-color");
4258 if (option != (
const char *) NULL)
4259 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4261 option=GetImageOption(image_info,
"type");
4262 if (option != (
const char *) NULL)
4263 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4265 option=GetImageOption(image_info,
"units");
4266 units=image_info->units;
4267 if (option != (
const char *) NULL)
4268 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4269 MagickFalse,option);
4270 if (units != UndefinedResolution)
4272 if (image->units != units)
4273 switch (image->units)
4275 case PixelsPerInchResolution:
4277 if (units == PixelsPerCentimeterResolution)
4279 image->resolution.x/=2.54;
4280 image->resolution.y/=2.54;
4284 case PixelsPerCentimeterResolution:
4286 if (units == PixelsPerInchResolution)
4288 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4289 image->resolution.x+0.5))/100.0;
4290 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4291 image->resolution.y+0.5))/100.0;
4299 option=GetImageOption(image_info,
"density");
4300 if (option != (
const char *) NULL)
4302 flags=ParseGeometry(option,&geometry_info);
4303 if ((flags & RhoValue) != 0)
4304 image->resolution.x=geometry_info.rho;
4305 image->resolution.y=image->resolution.x;
4306 if ((flags & SigmaValue) != 0)
4307 image->resolution.y=geometry_info.sigma;
4310 option=GetImageOption(image_info,
"virtual-pixel");
4311 if (option != (
const char *) NULL)
4312 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4313 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4315 option=GetImageOption(image_info,
"white-point");
4316 if (option != (
const char *) NULL)
4318 flags=ParseGeometry(option,&geometry_info);
4319 if ((flags & RhoValue) != 0)
4320 image->chromaticity.white_point.x=geometry_info.rho;
4321 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4322 if ((flags & SigmaValue) != 0)
4323 image->chromaticity.white_point.y=geometry_info.sigma;
4331 if (image->image_info != (ImageInfo *) NULL)
4332 image->image_info=DestroyImageInfo(image->image_info);
4333 image->image_info=CloneImageInfo(image_info);