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"
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;
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,
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,
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,
436#define AppendImageTag "Append/Image"
448 homogeneous_colorspace,
477 assert(images != (
Image *) NULL);
478 assert(images->signature == MagickCoreSignature);
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);
696 return(ClipImagePath(image,
"#1",MagickTrue,exception));
699MagickExport MagickBooleanType ClipImagePath(
Image *image,
const char *pathname,
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 image->mask_trait=UpdatePixelTrait;
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);
819 assert(exception->signature == MagickCoreSignature);
820 if (IsEventLogging() != MagickFalse)
821 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
822 if ((image->columns == 0) || (image->rows == 0))
824 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
825 "NegativeOrZeroImageSize",
"`%s'",image->filename);
826 return((
Image *) NULL);
828 clone_image=(
Image *) AcquireCriticalMemory(
sizeof(*clone_image));
829 (void) memset(clone_image,0,
sizeof(*clone_image));
830 clone_image->signature=MagickCoreSignature;
831 clone_image->storage_class=image->storage_class;
832 clone_image->number_channels=image->number_channels;
833 clone_image->number_meta_channels=image->number_meta_channels;
834 clone_image->metacontent_extent=image->metacontent_extent;
835 clone_image->colorspace=image->colorspace;
836 clone_image->alpha_trait=image->alpha_trait;
837 clone_image->channels=image->channels;
838 clone_image->mask_trait=image->mask_trait;
839 clone_image->columns=image->columns;
840 clone_image->rows=image->rows;
841 clone_image->dither=image->dither;
842 clone_image->image_info=CloneImageInfo(image->image_info);
843 (void) CloneImageProfiles(clone_image,image);
844 (void) CloneImageProperties(clone_image,image);
845 (void) CloneImageArtifacts(clone_image,image);
846 GetTimerInfo(&clone_image->timer);
847 if (image->ascii85 != (
void *) NULL)
848 Ascii85Initialize(clone_image);
849 clone_image->extent=image->extent;
850 clone_image->magick_columns=image->magick_columns;
851 clone_image->magick_rows=image->magick_rows;
852 clone_image->type=image->type;
853 clone_image->channel_mask=image->channel_mask;
854 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
855 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
857 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
858 (void) CopyMagickString(clone_image->filename,image->filename,
860 clone_image->progress_monitor=image->progress_monitor;
861 clone_image->client_data=image->client_data;
862 clone_image->reference_count=1;
863 clone_image->next=image->next;
864 clone_image->previous=image->previous;
865 clone_image->list=NewImageList();
866 if (detach == MagickFalse)
867 clone_image->blob=ReferenceBlob(image->blob);
870 clone_image->next=NewImageList();
871 clone_image->previous=NewImageList();
872 clone_image->blob=CloneBlobInfo((
BlobInfo *) NULL);
874 clone_image->ping=image->ping;
875 clone_image->timestamp=image->timestamp;
876 clone_image->ttl=image->ttl;
877 clone_image->debug=image->debug;
878 clone_image->semaphore=AcquireSemaphoreInfo();
879 if (image->colormap != (
PixelInfo *) NULL)
884 clone_image->colors=image->colors;
885 length=(size_t) image->colors;
886 clone_image->colormap=(
PixelInfo *) AcquireQuantumMemory(length+1,
887 sizeof(*clone_image->colormap));
888 if (clone_image->colormap == (
PixelInfo *) NULL)
890 clone_image=DestroyImage(clone_image);
891 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
893 (void) memcpy(clone_image->colormap,image->colormap,length*
894 sizeof(*clone_image->colormap));
896 if ((columns == 0) || (rows == 0))
898 if (image->montage != (
char *) NULL)
899 (
void) CloneString(&clone_image->montage,image->montage);
900 if (image->directory != (
char *) NULL)
901 (void) CloneString(&clone_image->directory,image->directory);
902 clone_image->cache=ReferencePixelCache(image->cache);
907 if (image->columns != 0)
908 scale_x=(double) columns/(
double) image->columns;
909 if (image->rows != 0)
910 scale_y=(double) rows/(
double) image->rows;
911 clone_image->page.width=(size_t) CastDoubleToSsizeT(floor(scale_x*
912 image->page.width+0.5));
913 clone_image->page.height=(size_t) CastDoubleToSsizeT(floor(scale_y*
914 image->page.height+0.5));
915 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
916 scale_x=scale_y=MagickMin(scale_x,scale_y);
917 clone_image->page.x=CastDoubleToSsizeT(ceil(scale_x*image->page.x-0.5));
918 clone_image->tile_offset.x=CastDoubleToSsizeT(ceil(scale_x*
919 image->tile_offset.x-0.5));
920 clone_image->page.y=CastDoubleToSsizeT(ceil(scale_y*image->page.y-0.5));
921 clone_image->tile_offset.y=CastDoubleToSsizeT(ceil(scale_y*
922 image->tile_offset.y-0.5));
923 clone_image->cache=ClonePixelCache(image->cache);
924 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
925 clone_image=DestroyImage(clone_image);
958 clone_info=AcquireImageInfo();
961 clone_info->compression=image_info->compression;
962 clone_info->temporary=image_info->temporary;
963 clone_info->adjoin=image_info->adjoin;
964 clone_info->antialias=image_info->antialias;
965 clone_info->scene=image_info->scene;
966 clone_info->number_scenes=image_info->number_scenes;
967 clone_info->depth=image_info->depth;
968 if (image_info->size != (
char *) NULL)
969 (void) CloneString(&clone_info->size,image_info->size);
970 if (image_info->extract != (
char *) NULL)
971 (
void) CloneString(&clone_info->extract,image_info->extract);
972 if (image_info->scenes != (
char *) NULL)
973 (void) CloneString(&clone_info->scenes,image_info->scenes);
974 if (image_info->page != (
char *) NULL)
975 (
void) CloneString(&clone_info->page,image_info->page);
976 clone_info->interlace=image_info->interlace;
977 clone_info->endian=image_info->endian;
978 clone_info->units=image_info->units;
979 clone_info->quality=image_info->quality;
980 if (image_info->sampling_factor != (
char *) NULL)
981 (void) CloneString(&clone_info->sampling_factor,
982 image_info->sampling_factor);
983 if (image_info->server_name != (
char *) NULL)
984 (
void) CloneString(&clone_info->server_name,image_info->server_name);
985 if (image_info->font != (
char *) NULL)
986 (void) CloneString(&clone_info->font,image_info->font);
987 if (image_info->texture != (
char *) NULL)
988 (
void) CloneString(&clone_info->texture,image_info->texture);
989 if (image_info->density != (
char *) NULL)
990 (void) CloneString(&clone_info->density,image_info->density);
991 clone_info->pointsize=image_info->pointsize;
992 clone_info->fuzz=image_info->fuzz;
993 clone_info->matte_color=image_info->matte_color;
994 clone_info->background_color=image_info->background_color;
995 clone_info->border_color=image_info->border_color;
996 clone_info->transparent_color=image_info->transparent_color;
997 clone_info->dither=image_info->dither;
998 clone_info->monochrome=image_info->monochrome;
999 clone_info->colorspace=image_info->colorspace;
1000 clone_info->type=image_info->type;
1001 clone_info->orientation=image_info->orientation;
1002 clone_info->ping=image_info->ping;
1003 clone_info->verbose=image_info->verbose;
1004 clone_info->progress_monitor=image_info->progress_monitor;
1005 clone_info->client_data=image_info->client_data;
1006 clone_info->cache=image_info->cache;
1007 if (image_info->cache != (
void *) NULL)
1008 clone_info->cache=ReferencePixelCache(image_info->cache);
1009 if (image_info->profile != (
void *) NULL)
1010 clone_info->profile=(
void *) CloneStringInfo((
StringInfo *)
1011 image_info->profile);
1012 SetImageInfoFile(clone_info,image_info->file);
1013 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1014 clone_info->stream=image_info->stream;
1015 clone_info->custom_stream=image_info->custom_stream;
1016 (void) CopyMagickString(clone_info->magick,image_info->magick,
1018 (void) CopyMagickString(clone_info->unique,image_info->unique,
1020 (void) CopyMagickString(clone_info->filename,image_info->filename,
1022 clone_info->channel=image_info->channel;
1023 (void) CloneImageOptions(clone_info,image_info);
1024 clone_info->debug=image_info->debug;
1025 clone_info->signature=image_info->signature;
1062MagickExport MagickBooleanType CopyImagePixels(
Image *image,
1066#define CopyImageTag "Copy/Image"
1081 assert(image != (
Image *) NULL);
1082 assert(source_image != (
Image *) NULL);
1085 if (IsEventLogging() != MagickFalse)
1086 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1087 if ((offset->x < 0) || (offset->y < 0) ||
1088 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1089 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1090 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1092 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1093 return(MagickFalse);
1099 source_view=AcquireVirtualCacheView(source_image,exception);
1100 image_view=AcquireAuthenticCacheView(image,exception);
1101#if defined(MAGICKCORE_OPENMP_SUPPORT)
1102 #pragma omp parallel for schedule(static) shared(progress,status) \
1103 magick_number_threads(image,source_image,geometry->height,2)
1105 for (y=0; y < (ssize_t) geometry->height; y++)
1119 if (status == MagickFalse)
1121 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1122 geometry->width,1,exception);
1123 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1124 geometry->width,1,exception);
1125 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1130 for (x=0; x < (ssize_t) geometry->width; x++)
1135 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1137 PixelChannel channel = GetPixelChannelChannel(image,i);
1138 PixelTrait traits = GetPixelChannelTraits(image,channel);
1139 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1140 if ((traits == UndefinedPixelTrait) ||
1141 ((traits & UpdatePixelTrait) == 0) ||
1142 (source_traits == UndefinedPixelTrait))
1144 SetPixelChannel(image,channel,p[i],q);
1146 p+=(ptrdiff_t) GetPixelChannels(source_image);
1147 q+=(ptrdiff_t) GetPixelChannels(image);
1149 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1150 if (sync == MagickFalse)
1152 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1157#if defined(MAGICKCORE_OPENMP_SUPPORT)
1161 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1162 if (proceed == MagickFalse)
1166 source_view=DestroyCacheView(source_view);
1167 image_view=DestroyCacheView(image_view);
1194MagickExport
Image *DestroyImage(
Image *image)
1202 assert(image != (
Image *) NULL);
1203 assert(image->signature == MagickCoreSignature);
1204 if (IsEventLogging() != MagickFalse)
1205 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1206 destroy=MagickFalse;
1207 LockSemaphoreInfo(image->semaphore);
1208 image->reference_count--;
1209 if (image->reference_count == 0)
1211 UnlockSemaphoreInfo(image->semaphore);
1212 if (destroy == MagickFalse)
1213 return((
Image *) NULL);
1217 DestroyImagePixels(image);
1218 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1219 if (image->montage != (
char *) NULL)
1220 image->montage=DestroyString(image->montage);
1221 if (image->directory != (
char *) NULL)
1222 image->directory=DestroyString(image->directory);
1223 if (image->colormap != (
PixelInfo *) NULL)
1224 image->colormap=(
PixelInfo *) RelinquishMagickMemory(image->colormap);
1225 if (image->geometry != (
char *) NULL)
1226 image->geometry=DestroyString(image->geometry);
1227 DestroyImageProfiles(image);
1228 DestroyImageProperties(image);
1229 DestroyImageArtifacts(image);
1231 image->ascii85=(
Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1232 if (image->image_info != (
ImageInfo *) NULL)
1233 image->image_info=DestroyImageInfo(image->image_info);
1236 RelinquishSemaphoreInfo(&image->semaphore);
1237 image->signature=(~MagickCoreSignature);
1238 image=(
Image *) RelinquishMagickMemory(image);
1267 assert(image_info != (
ImageInfo *) NULL);
1268 assert(image_info->signature == MagickCoreSignature);
1269 if (IsEventLogging() != MagickFalse)
1270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1271 image_info->filename);
1272 if (image_info->size != (
char *) NULL)
1273 image_info->size=DestroyString(image_info->size);
1274 if (image_info->extract != (
char *) NULL)
1275 image_info->extract=DestroyString(image_info->extract);
1276 if (image_info->scenes != (
char *) NULL)
1277 image_info->scenes=DestroyString(image_info->scenes);
1278 if (image_info->page != (
char *) NULL)
1279 image_info->page=DestroyString(image_info->page);
1280 if (image_info->sampling_factor != (
char *) NULL)
1281 image_info->sampling_factor=DestroyString(
1282 image_info->sampling_factor);
1283 if (image_info->server_name != (
char *) NULL)
1284 image_info->server_name=DestroyString(
1285 image_info->server_name);
1286 if (image_info->font != (
char *) NULL)
1287 image_info->font=DestroyString(image_info->font);
1288 if (image_info->texture != (
char *) NULL)
1289 image_info->texture=DestroyString(image_info->texture);
1290 if (image_info->density != (
char *) NULL)
1291 image_info->density=DestroyString(image_info->density);
1292 if (image_info->cache != (
void *) NULL)
1293 image_info->cache=DestroyPixelCache(image_info->cache);
1294 if (image_info->profile != (
StringInfo *) NULL)
1295 image_info->profile=(
void *) DestroyStringInfo((
StringInfo *)
1296 image_info->profile);
1297 DestroyImageOptions(image_info);
1298 image_info->signature=(~MagickCoreSignature);
1299 image_info=(
ImageInfo *) RelinquishMagickMemory(image_info);
1327MagickExport
void DisassociateImageStream(
Image *image)
1329 assert(image != (
Image *) NULL);
1330 assert(image->signature == MagickCoreSignature);
1331 if (IsEventLogging() != MagickFalse)
1332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1333 DisassociateBlob(image);
1358MagickExport
void GetImageInfo(
ImageInfo *image_info)
1366 assert(image_info != (
ImageInfo *) NULL);
1367 if (IsEventLogging() != MagickFalse)
1368 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1369 (void) memset(image_info,0,
sizeof(*image_info));
1370 image_info->adjoin=MagickTrue;
1371 image_info->interlace=NoInterlace;
1372 image_info->channel=AllChannels;
1373 image_info->quality=UndefinedCompressionQuality;
1374 image_info->antialias=MagickTrue;
1375 image_info->dither=MagickTrue;
1376 image_info->depth=0;
1377 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1378 if (synchronize != (
const char *) NULL)
1380 image_info->synchronize=IsStringTrue(synchronize);
1381 synchronize=DestroyString(synchronize);
1383 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1384 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1385 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1386 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1387 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1389 image_info->signature=MagickCoreSignature;
1414MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1416 return(image_info->file);
1444MagickExport
Image *GetImageMask(
const Image *image,
const PixelMask type,
1463 assert(image != (
Image *) NULL);
1464 assert(image->signature == MagickCoreSignature);
1465 if (IsEventLogging() != MagickFalse)
1466 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1471 if ((image->channels & ReadMaskChannel) == 0)
1472 return((
Image *) NULL);
1475 case WritePixelMask:
1477 if ((image->channels & WriteMaskChannel) == 0)
1478 return((
Image *) NULL);
1483 if ((image->channels & CompositeMaskChannel) == 0)
1484 return((
Image *) NULL);
1488 mask_image=AcquireImage((
ImageInfo *) NULL,exception);
1489 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1490 if (status == MagickFalse)
1491 return(DestroyImage(mask_image));
1493 mask_image->alpha_trait=UndefinedPixelTrait;
1494 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1495 image_view=AcquireVirtualCacheView(image,exception);
1496 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1497#if defined(MAGICKCORE_OPENMP_SUPPORT)
1498 #pragma omp parallel for schedule(static) shared(status) \
1499 magick_number_threads(image,image,image->rows,2)
1501 for (y=0; y < (ssize_t) image->rows; y++)
1512 if (status == MagickFalse)
1514 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1515 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1517 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1522 for (x=0; x < (ssize_t) image->columns; x++)
1528 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1531 case WritePixelMask:
1533 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1538 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1542 p+=(ptrdiff_t) GetPixelChannels(image);
1543 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1545 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1548 mask_view=DestroyCacheView(mask_view);
1549 image_view=DestroyCacheView(image_view);
1550 if (status == MagickFalse)
1551 mask_image=DestroyImage(mask_image);
1577MagickExport ssize_t GetImageReferenceCount(
Image *image)
1582 assert(image != (
Image *) NULL);
1583 assert(image->signature == MagickCoreSignature);
1584 if (IsEventLogging() != MagickFalse)
1585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1586 LockSemaphoreInfo(image->semaphore);
1587 reference_count=image->reference_count;
1588 UnlockSemaphoreInfo(image->semaphore);
1589 return(reference_count);
1616MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1618 assert(image != (
Image *) NULL);
1619 assert(image->signature == MagickCoreSignature);
1620 if (IsEventLogging() != MagickFalse)
1621 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1622 return(GetPixelCacheVirtualMethod(image));
1661static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1665 specifier = end[-1];
1673 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1674 return(MagickFalse);
1675 if ((length == 1) && (*start == specifier))
1684 if ((length >= 3) && (start[1] ==
'0'))
1685 return(MagickFalse);
1688 for ( ; i < (length-1); i++)
1689 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1690 return(MagickFalse);
1693 return(MagickFalse);
1696MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1697 Image *image,
const char *format,
int value,
char *filename,
1702 pattern[MagickPathExtent];
1707 assert(format != (
const char *) NULL);
1708 assert(filename != (
char *) NULL);
1709 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1711 (void) CopyMagickString(filename,format,MagickPathExtent);
1712 return(strlen(filename));
1714 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1732 specifier_start=cursor;
1733 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1735 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1738 *specifier_end = cursor+1;
1740 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1743 format_specifier[MagickPathExtent];
1746 length = cursor-specifier_start,
1752 (void) snprintf(format_specifier,
sizeof(format_specifier),
1753 "%%%.*s%c",(int) length,specifier_start,*cursor);
1754 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1756 pattern_length=strlen(pattern);
1757 if ((count <= 0) || ((
size_t) count != pattern_length))
1759 if ((p-filename+pattern_length) >= MagickPathExtent)
1761 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
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) &&
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,MagickPathExtent-(p-filename));
1816 if ((p-filename+1) >= MagickPathExtent)
1821 return(strlen(filename));
1851MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1854#if !defined(MAGICKCORE_HDRI_SUPPORT)
1857 return(MagickFalse);
1868 assert(image != (
Image *) NULL);
1869 assert(image->signature == MagickCoreSignature);
1870 if (IsEventLogging() != MagickFalse)
1871 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1872 image_view=AcquireVirtualCacheView(image,exception);
1873#if defined(MAGICKCORE_OPENMP_SUPPORT)
1874 #pragma omp parallel for schedule(static) shared(hdri) \
1875 magick_number_threads(image,image,image->rows,2)
1877 for (y=0; y < (ssize_t) image->rows; y++)
1885 if (hdri != MagickFalse)
1887 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1888 if (p == (
const Quantum *) NULL)
1890 for (x=0; x < (ssize_t) image->columns; x++)
1895 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1903 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1904 if (traits == UndefinedPixelTrait)
1906 pixel=(double) p[i];
1907 if ((pixel < 0.0) || (pixel > (double) QuantumRange) ||
1908 (pixel != (double) ((QuantumAny) pixel)))
1914 if (hdri != MagickFalse)
1916 p+=(ptrdiff_t) GetPixelChannels(image);
1919 image_view=DestroyCacheView(image_view);
1947MagickExport MagickBooleanType IsImageObject(
const Image *image)
1952 assert(image != (
Image *) NULL);
1953 if (IsEventLogging() != MagickFalse)
1954 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1955 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1956 if (p->signature != MagickCoreSignature)
1957 return(MagickFalse);
1984MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1987 magick[MagickPathExtent],
1988 filename[MagickPathExtent];
1993 assert(image != (
Image *) NULL);
1994 assert(image->signature == MagickCoreSignature);
1995 if (IsEventLogging() != MagickFalse)
1996 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1997 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1998 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1999 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
2001 if (p->taint != MagickFalse)
2003 if (LocaleCompare(p->magick,magick) != 0)
2005 if (LocaleCompare(p->filename,filename) != 0)
2008 return(MagickFalse);
2037MagickExport MagickBooleanType ModifyImage(
Image **image,
2043 assert(image != (
Image **) NULL);
2044 assert(*image != (
Image *) NULL);
2045 assert((*image)->signature == MagickCoreSignature);
2046 if (IsEventLogging() != MagickFalse)
2047 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2048 if (GetImageReferenceCount(*image) <= 1)
2050 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2051 LockSemaphoreInfo((*image)->semaphore);
2052 (*image)->reference_count--;
2053 UnlockSemaphoreInfo((*image)->semaphore);
2092 const size_t width,
const size_t height,
const PixelInfo *background,
2107 assert(image_info != (
const ImageInfo *) NULL);
2108 assert(image_info->signature == MagickCoreSignature);
2109 assert(background != (
const PixelInfo *) NULL);
2110 if (IsEventLogging() != MagickFalse)
2111 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2112 image=AcquireImage(image_info,exception);
2113 image->columns=width;
2115 image->colorspace=background->colorspace;
2116 image->alpha_trait=background->alpha_trait;
2117 image->fuzz=background->fuzz;
2118 image->depth=background->depth;
2120 image_view=AcquireAuthenticCacheView(image,exception);
2121#if defined(MAGICKCORE_OPENMP_SUPPORT)
2122 #pragma omp parallel for schedule(static) shared(status) \
2123 magick_number_threads(image,image,image->rows,2)
2125 for (y=0; y < (ssize_t) image->rows; y++)
2133 if (status == MagickFalse)
2135 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2136 if (q == (Quantum *) NULL)
2141 for (x=0; x < (ssize_t) image->columns; x++)
2143 SetPixelViaPixelInfo(image,background,q);
2144 q+=(ptrdiff_t) GetPixelChannels(image);
2146 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2149 image_view=DestroyCacheView(image_view);
2150 if (status == MagickFalse)
2151 image=DestroyImage(image);
2178MagickExport
Image *ReferenceImage(
Image *image)
2180 assert(image != (
Image *) NULL);
2181 assert(image->signature == MagickCoreSignature);
2182 if (IsEventLogging() != MagickFalse)
2183 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2184 LockSemaphoreInfo(image->semaphore);
2185 image->reference_count++;
2186 UnlockSemaphoreInfo(image->semaphore);
2214MagickExport MagickBooleanType ResetImagePage(
Image *image,
const char *page)
2222 assert(image != (
Image *) NULL);
2223 assert(image->signature == MagickCoreSignature);
2224 if (IsEventLogging() != MagickFalse)
2225 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2226 flags=ParseAbsoluteGeometry(page,&geometry);
2227 if ((flags & WidthValue) != 0)
2229 if ((flags & HeightValue) == 0)
2230 geometry.height=geometry.width;
2231 image->page.width=geometry.width;
2232 image->page.height=geometry.height;
2234 if ((flags & AspectValue) != 0)
2236 if ((flags & XValue) != 0)
2237 image->page.x+=geometry.x;
2238 if ((flags & YValue) != 0)
2239 image->page.y+=geometry.y;
2243 if ((flags & XValue) != 0)
2245 image->page.x=geometry.x;
2246 if ((image->page.width == 0) && (geometry.x > 0))
2247 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2249 if ((flags & YValue) != 0)
2251 image->page.y=geometry.y;
2252 if ((image->page.height == 0) && (geometry.y > 0))
2253 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2285MagickExport MagickBooleanType ResetImagePixels(
Image *image,
2303 assert(image != (
Image *) NULL);
2304 assert(image->signature == MagickCoreSignature);
2305 if (IsEventLogging() != MagickFalse)
2306 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2307 pixels=AcquirePixelCachePixels(image,&length,exception);
2308 if (pixels != (
void *) NULL)
2313 (void) memset(pixels,0,length);
2320 image_view=AcquireAuthenticCacheView(image,exception);
2321#if defined(MAGICKCORE_OPENMP_SUPPORT)
2322 #pragma omp parallel for schedule(static) shared(status) \
2323 magick_number_threads(image,image,image->rows,2)
2325 for (y=0; y < (ssize_t) image->rows; y++)
2333 if (status == MagickFalse)
2335 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2336 if (q == (Quantum *) NULL)
2341 for (x=0; x < (ssize_t) image->columns; x++)
2343 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2344 q+=(ptrdiff_t) GetPixelChannels(image);
2346 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2349 image_view=DestroyCacheView(image_view);
2381MagickExport MagickBooleanType SetImageAlpha(
Image *image,
const Quantum alpha,
2393 assert(image != (
Image *) NULL);
2394 assert(image->signature == MagickCoreSignature);
2395 if (IsEventLogging() != MagickFalse)
2396 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2397 image->alpha_trait=BlendPixelTrait;
2399 image_view=AcquireAuthenticCacheView(image,exception);
2400#if defined(MAGICKCORE_OPENMP_SUPPORT)
2401 #pragma omp parallel for schedule(static) shared(status) \
2402 magick_number_threads(image,image,image->rows,2)
2404 for (y=0; y < (ssize_t) image->rows; y++)
2412 if (status == MagickFalse)
2414 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2415 if (q == (Quantum *) NULL)
2420 for (x=0; x < (ssize_t) image->columns; x++)
2422 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2423 SetPixelAlpha(image,alpha,q);
2424 q+=(ptrdiff_t) GetPixelChannels(image);
2426 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2429 image_view=DestroyCacheView(image_view);
2460MagickExport MagickBooleanType SetImageBackgroundColor(
Image *image,
2475 assert(image != (
Image *) NULL);
2476 assert(image->signature == MagickCoreSignature);
2477 if (IsEventLogging() != MagickFalse)
2478 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2479 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2480 return(MagickFalse);
2481 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2482 ((image->alpha_trait & BlendPixelTrait) == 0))
2483 (
void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2484 ConformPixelInfo(image,&image->background_color,&background,exception);
2489 image_view=AcquireAuthenticCacheView(image,exception);
2490#if defined(MAGICKCORE_OPENMP_SUPPORT)
2491 #pragma omp parallel for schedule(static) shared(status) \
2492 magick_number_threads(image,image,image->rows,2)
2494 for (y=0; y < (ssize_t) image->rows; y++)
2502 if (status == MagickFalse)
2504 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2505 if (q == (Quantum *) NULL)
2510 for (x=0; x < (ssize_t) image->columns; x++)
2512 SetPixelViaPixelInfo(image,&background,q);
2513 q+=(ptrdiff_t) GetPixelChannels(image);
2515 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2518 image_view=DestroyCacheView(image_view);
2548MagickExport ChannelType SetImageChannelMask(
Image *image,
2549 const ChannelType channel_mask)
2551 return(SetPixelChannelMask(image,channel_mask));
2581MagickExport MagickBooleanType SetImageColor(
Image *image,
2593 assert(image != (
Image *) NULL);
2594 assert(image->signature == MagickCoreSignature);
2595 assert(color != (
const PixelInfo *) NULL);
2596 if (IsEventLogging() != MagickFalse)
2597 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2598 image->colorspace=color->colorspace;
2599 image->alpha_trait=color->alpha_trait;
2600 image->fuzz=color->fuzz;
2601 image->depth=color->depth;
2603 image_view=AcquireAuthenticCacheView(image,exception);
2604#if defined(MAGICKCORE_OPENMP_SUPPORT)
2605 #pragma omp parallel for schedule(static) shared(status) \
2606 magick_number_threads(image,image,image->rows,2)
2608 for (y=0; y < (ssize_t) image->rows; y++)
2616 if (status == MagickFalse)
2618 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2619 if (q == (Quantum *) NULL)
2624 for (x=0; x < (ssize_t) image->columns; x++)
2626 SetPixelViaPixelInfo(image,color,q);
2627 q+=(ptrdiff_t) GetPixelChannels(image);
2629 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2632 image_view=DestroyCacheView(image_view);
2664MagickExport MagickBooleanType SetImageStorageClass(
Image *image,
2667 assert(image != (
Image *) NULL);
2668 assert(image->signature == MagickCoreSignature);
2670 assert(exception->signature == MagickCoreSignature);
2671 if (IsEventLogging() != MagickFalse)
2672 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2673 image->storage_class=storage_class;
2674 return(SyncImagePixelCache(image,exception));
2706MagickExport MagickBooleanType SetImageExtent(
Image *image,
const size_t columns,
2709 if ((columns == 0) || (rows == 0))
2710 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2711 image->columns=columns;
2713 if (image->depth == 0)
2716 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2717 "ImageDepthNotSupported",
"`%s'",image->filename);
2719 if (image->depth > (8*
sizeof(MagickSizeType)))
2721 image->depth=8*
sizeof(MagickSizeType);
2722 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2723 "ImageDepthNotSupported",
"`%s'",image->filename);
2725 return(SyncImagePixelCache(image,exception));
2776 *format_type_formats[] =
2800 (void) CopyMagickString(magic,component,MagickPathExtent);
2805 format_type=UndefinedFormatType;
2806 magick_info=GetMagickInfo(magic,exception);
2807 if ((magick_info != (
const MagickInfo *) NULL) &&
2808 (magick_info->format_type != UndefinedFormatType))
2809 format_type=magick_info->format_type;
2811 while ((format_type == UndefinedFormatType) &&
2812 (format_type_formats[i] != (
char *) NULL))
2814 if ((*magic == *format_type_formats[i]) &&
2815 (LocaleCompare(magic,format_type_formats[i]) == 0))
2816 format_type=ExplicitFormatType;
2819 if (format_type == UndefinedFormatType)
2820 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2822 if (format_type == ExplicitFormatType)
2824 image_info->affirm=MagickTrue;
2825 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2827 if (LocaleCompare(magic,
"RGB") == 0)
2828 image_info->affirm=MagickFalse;
2829 return(magick_info);
2832MagickExport MagickBooleanType SetImageInfo(
ImageInfo *image_info,
2836 component[MagickPathExtent],
2837 magic[MagickPathExtent],
2838 path[MagickPathExtent],
2865 assert(image_info != (
ImageInfo *) NULL);
2866 assert(image_info->signature == MagickCoreSignature);
2867 if (IsEventLogging() != MagickFalse)
2868 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2869 image_info->filename);
2871 GetPathComponent(image_info->filename,SubimagePath,component);
2872 if (*component !=
'\0')
2877 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2879 if (IsGeometry(component) != MagickFalse)
2880 (void) CloneString(&image_info->extract,component);
2888 (void) CloneString(&image_info->scenes,component);
2889 image_info->scene=StringToUnsignedLong(image_info->scenes);
2890 image_info->number_scenes=image_info->scene;
2891 p=image_info->scenes;
2892 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2894 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2896 first=(size_t) strtol(p,&q,10);
2898 while (isspace((
int) ((
unsigned char) *q)) != 0)
2901 last=(size_t) strtol(q+1,&q,10);
2904 if (first < image_info->scene)
2905 image_info->scene=first;
2906 if (last > image_info->number_scenes)
2907 image_info->number_scenes=last;
2910 image_info->number_scenes-=image_info->scene-1;
2914 if (*image_info->magick ==
'\0')
2915 GetPathComponent(image_info->filename,ExtensionPath,component);
2916 if (*component !=
'\0')
2921 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2922 GetPathComponent(path,ExtensionPath,component);
2924 image_info->affirm=MagickFalse;
2925 sans_exception=AcquireExceptionInfo();
2926 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2927 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2933 GetPathComponent(image_info->filename,MagickPath,magic);
2936 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2937 magick_info=GetMagickInfo(magic,sans_exception);
2938 if ((magick_info != (
const MagickInfo *) NULL) &&
2939 (magick_info->format_type == ExplicitFormatType))
2940 image_info->affirm=MagickTrue;
2942 GetPathComponent(image_info->filename,CanonicalPath,component);
2944 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2945 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2956 magick_info=GetMagickInfo(magic,sans_exception);
2958 if (magick_info == (
const MagickInfo *) NULL)
2960 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2962 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2964 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2969 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2973 if (((magick_info != (
const MagickInfo *) NULL) ||
2975 (IsMagickConflict(magic) == MagickFalse))
2977 image_info->affirm=MagickTrue;
2978 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2979 GetPathComponent(image_info->filename,CanonicalPath,component);
2980 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
2981 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2982 (void) CopyMagickString(image_info->filename,component,
2986 sans_exception=DestroyExceptionInfo(sans_exception);
2987 if ((magick_info == (
const MagickInfo *) NULL) ||
2988 (GetMagickEndianSupport(magick_info) == MagickFalse))
2989 image_info->endian=UndefinedEndian;
2990 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2995 (void) InterpretImageFilename(image_info,(
Image *) NULL,
2996 image_info->filename,(int) image_info->scene,component,exception);
2997 if ((LocaleCompare(component,image_info->filename) != 0) &&
2998 (strchr(component,
'%') == (
char *) NULL))
2999 image_info->adjoin=MagickFalse;
3001 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3006 magick_info=GetMagickInfo(magic,exception);
3007 if (magick_info != (
const MagickInfo *) NULL)
3008 if (GetMagickAdjoin(magick_info) == MagickFalse)
3009 image_info->adjoin=MagickFalse;
3011 if (image_info->affirm != MagickFalse)
3024 magick_size=GetMagicPatternExtent(exception);
3025 if (magick_size == 0)
3026 return(MagickFalse);
3027 image=AcquireImage(image_info,exception);
3028 (void) CopyMagickString(image->filename,image_info->filename,
3030 sans_exception=AcquireExceptionInfo();
3031 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3032 sans_exception=DestroyExceptionInfo(sans_exception);
3033 if (status == MagickFalse)
3035 image=DestroyImage(image);
3036 return(MagickFalse);
3038 if ((IsBlobSeekable(image) == MagickFalse) ||
3039 (IsBlobExempt(image) != MagickFalse))
3045 status=ImageToFile(image,component,exception);
3046 if (CloseBlob(image) == MagickFalse)
3048 if (status == MagickFalse)
3050 (void) RelinquishUniqueFileResource(component);
3051 image=DestroyImage(image);
3052 return(MagickFalse);
3054 SetImageInfoFile(image_info,(FILE *) NULL);
3055 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3056 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3057 if (status == MagickFalse)
3059 (void) RelinquishUniqueFileResource(component);
3060 image=DestroyImage(image);
3061 return(MagickFalse);
3063 (void) CopyMagickString(image_info->filename,component,
3065 image_info->temporary=MagickTrue;
3067 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3068 if (magick == (
unsigned char *) NULL)
3070 (void) CloseBlob(image);
3071 image=DestroyImage(image);
3072 return(MagickFalse);
3074 (void) memset(magick,0,magick_size);
3075 count=ReadBlob(image,magick_size,magick);
3076 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3077 (void) CloseBlob(image);
3078 image=DestroyImage(image);
3082 sans_exception=AcquireExceptionInfo();
3083 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3084 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3085 if ((magic_info != (
const MagicInfo *) NULL) &&
3086 (GetMagicName(magic_info) != (
char *) NULL))
3091 if ((magick_info != (
const MagickInfo *) NULL) &&
3092 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3093 (LocaleCompare(magick_info->magick_module,GetMagicName(
3095 (
void) CopyMagickString(image_info->magick,magick_info->name,
3099 (void) CopyMagickString(image_info->magick,GetMagicName(
3100 magic_info),MagickPathExtent);
3101 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3103 if ((magick_info == (
const MagickInfo *) NULL) ||
3104 (GetMagickEndianSupport(magick_info) == MagickFalse))
3105 image_info->endian=UndefinedEndian;
3106 sans_exception=DestroyExceptionInfo(sans_exception);
3109 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3110 if ((magick_info == (
const MagickInfo *) NULL) ||
3111 (GetMagickEndianSupport(magick_info) == MagickFalse))
3112 image_info->endian=UndefinedEndian;
3113 sans_exception=DestroyExceptionInfo(sans_exception);
3145MagickExport
void SetImageInfoBlob(
ImageInfo *image_info,
const void *blob,
3146 const size_t length)
3148 assert(image_info != (
ImageInfo *) NULL);
3149 assert(image_info->signature == MagickCoreSignature);
3150 if (IsEventLogging() != MagickFalse)
3151 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3152 image_info->filename);
3153 image_info->blob=(
void *) blob;
3154 image_info->length=length;
3182MagickExport
void SetImageInfoCustomStream(
ImageInfo *image_info,
3185 assert(image_info != (
ImageInfo *) NULL);
3186 assert(image_info->signature == MagickCoreSignature);
3187 if (IsEventLogging() != MagickFalse)
3188 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3189 image_info->filename);
3217MagickExport
void SetImageInfoFile(
ImageInfo *image_info,FILE *file)
3219 assert(image_info != (
ImageInfo *) NULL);
3220 assert(image_info->signature == MagickCoreSignature);
3221 if (IsEventLogging() != MagickFalse)
3222 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3223 image_info->filename);
3224 image_info->file=file;
3257MagickExport MagickBooleanType SetImageMask(
Image *image,
const PixelMask type,
3273 assert(image != (
Image *) NULL);
3274 if (IsEventLogging() != MagickFalse)
3275 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3276 assert(image->signature == MagickCoreSignature);
3277 if (mask == (
const Image *) NULL)
3283 image->channels=(ChannelType) ((
unsigned int) image->channels &
3284 (
unsigned int) ~ReadMaskChannel);
3287 case WritePixelMask:
3289 image->channels=(ChannelType) ((
unsigned int) image->channels &
3290 (
unsigned int) ~WriteMaskChannel);
3295 image->channels=(ChannelType) ((
unsigned int) image->channels &
3296 (
unsigned int) ~CompositeMaskChannel);
3300 return(SyncImagePixelCache(image,exception));
3306 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3309 case WritePixelMask:
3311 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3316 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3320 if (SyncImagePixelCache(image,exception) == MagickFalse)
3321 return(MagickFalse);
3323 image->mask_trait=UpdatePixelTrait;
3324 mask_view=AcquireVirtualCacheView(mask,exception);
3325 image_view=AcquireAuthenticCacheView(image,exception);
3326#if defined(MAGICKCORE_OPENMP_SUPPORT)
3327 #pragma omp parallel for schedule(static) shared(status) \
3328 magick_number_threads(mask,image,image->rows,2)
3330 for (y=0; y < (ssize_t) image->rows; y++)
3341 if (status == MagickFalse)
3343 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3344 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3345 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3350 for (x=0; x < (ssize_t) image->columns; x++)
3356 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3357 intensity=GetPixelIntensity(mask,p);
3362 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3365 case WritePixelMask:
3367 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3372 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3376 p+=(ptrdiff_t) GetPixelChannels(mask);
3377 q+=(ptrdiff_t) GetPixelChannels(image);
3379 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3382 image->mask_trait=UndefinedPixelTrait;
3383 mask_view=DestroyCacheView(mask_view);
3384 image_view=DestroyCacheView(image_view);
3418MagickExport MagickBooleanType SetImageRegionMask(
Image *image,
3433 assert(image != (
Image *) NULL);
3434 assert(image->signature == MagickCoreSignature);
3435 if (IsEventLogging() != MagickFalse)
3436 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3443 image->channels=(ChannelType) ((
unsigned int) image->channels &
3444 (
unsigned int) ~ReadMaskChannel);
3447 case WritePixelMask:
3449 image->channels=(ChannelType) ((
unsigned int) image->channels &
3450 (
unsigned int) ~WriteMaskChannel);
3455 image->channels=(ChannelType) ((
unsigned int) image->channels &
3456 (
unsigned int) ~CompositeMaskChannel);
3460 return(SyncImagePixelCache(image,exception));
3466 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3469 case WritePixelMask:
3471 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3476 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3480 if (SyncImagePixelCache(image,exception) == MagickFalse)
3481 return(MagickFalse);
3483 image->mask_trait=UpdatePixelTrait;
3484 image_view=AcquireAuthenticCacheView(image,exception);
3485#if defined(MAGICKCORE_OPENMP_SUPPORT)
3486 #pragma omp parallel for schedule(static) shared(status) \
3487 magick_number_threads(image,image,image->rows,2)
3489 for (y=0; y < (ssize_t) image->rows; y++)
3497 if (status == MagickFalse)
3499 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3500 if (q == (Quantum *) NULL)
3505 for (x=0; x < (ssize_t) image->columns; x++)
3511 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3512 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3518 SetPixelReadMask(image,pixel,q);
3521 case WritePixelMask:
3523 SetPixelWriteMask(image,pixel,q);
3528 SetPixelCompositeMask(image,pixel,q);
3532 q+=(ptrdiff_t) GetPixelChannels(image);
3534 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3537 image->mask_trait=UndefinedPixelTrait;
3538 image_view=DestroyCacheView(image_view);
3571MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(
Image *image,
3572 const VirtualPixelMethod virtual_pixel_method,
ExceptionInfo *exception)
3574 assert(image != (
const Image *) NULL);
3575 assert(image->signature == MagickCoreSignature);
3576 if (IsEventLogging() != MagickFalse)
3577 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3578 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3616static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3644 if (images->previous == (
Image *) NULL)
3647 SetGeometry(smush_image,&right_geometry);
3648 GravityAdjustGeometry(right_image->columns,right_image->rows,
3649 right_image->gravity,&right_geometry);
3650 left_image=images->previous;
3651 SetGeometry(smush_image,&left_geometry);
3652 GravityAdjustGeometry(left_image->columns,left_image->rows,
3653 left_image->gravity,&left_geometry);
3654 gap=right_image->columns;
3655 left_view=AcquireVirtualCacheView(left_image,exception);
3656 right_view=AcquireVirtualCacheView(right_image,exception);
3657 for (y=0; y < (ssize_t) smush_image->rows; y++)
3659 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3661 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3662 if ((p == (
const Quantum *) NULL) ||
3663 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3664 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3667 i=(ssize_t) left_image->columns-x-1;
3668 for (x=0; x < (ssize_t) right_image->columns; x++)
3670 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3672 if ((p == (
const Quantum *) NULL) ||
3673 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3674 ((x+i) >= (ssize_t) gap))
3677 if ((x+i) < (ssize_t) gap)
3680 right_view=DestroyCacheView(right_view);
3681 left_view=DestroyCacheView(left_view);
3682 if (y < (ssize_t) smush_image->rows)
3684 return((ssize_t) gap-offset);
3687static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3715 if (images->previous == (
Image *) NULL)
3717 bottom_image=images;
3718 SetGeometry(smush_image,&bottom_geometry);
3719 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3720 bottom_image->gravity,&bottom_geometry);
3721 top_image=images->previous;
3722 SetGeometry(smush_image,&top_geometry);
3723 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3725 gap=bottom_image->rows;
3726 top_view=AcquireVirtualCacheView(top_image,exception);
3727 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3728 for (x=0; x < (ssize_t) smush_image->columns; x++)
3730 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3732 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3733 if ((p == (
const Quantum *) NULL) ||
3734 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3735 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3738 i=(ssize_t) top_image->rows-y-1;
3739 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3741 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3743 if ((p == (
const Quantum *) NULL) ||
3744 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3745 ((y+i) >= (ssize_t) gap))
3748 if ((y+i) < (ssize_t) gap)
3751 bottom_view=DestroyCacheView(bottom_view);
3752 top_view=DestroyCacheView(top_view);
3753 if (x < (ssize_t) smush_image->columns)
3755 return((ssize_t) gap-offset);
3758MagickExport
Image *SmushImages(
const Image *images,
3759 const MagickBooleanType stack,
const ssize_t offset,
ExceptionInfo *exception)
3761#define SmushImageTag "Smush/Image"
3797 assert(images != (
Image *) NULL);
3798 assert(images->signature == MagickCoreSignature);
3800 assert(exception->signature == MagickCoreSignature);
3801 if (IsEventLogging() != MagickFalse)
3802 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3804 alpha_trait=image->alpha_trait;
3806 width=image->columns;
3808 next=GetNextImageInList(image);
3809 for ( ; next != (
Image *) NULL; next=GetNextImageInList(next))
3811 if (next->alpha_trait != UndefinedPixelTrait)
3812 alpha_trait=BlendPixelTrait;
3814 if (stack != MagickFalse)
3816 if (next->columns > width)
3817 width=next->columns;
3819 if (next->previous != (
Image *) NULL)
3820 height=(
size_t) MagickMax((ssize_t) height+offset,0U);
3823 width+=next->columns;
3824 if (next->previous != (
Image *) NULL)
3825 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3826 if (next->rows > height)
3832 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3833 if (smush_image == (
Image *) NULL)
3834 return((
Image *) NULL);
3835 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3837 smush_image=DestroyImage(smush_image);
3838 return((
Image *) NULL);
3840 smush_image->alpha_trait=alpha_trait;
3841 (void) SetImageBackgroundColor(smush_image,exception);
3845 for (n=0; n < (MagickOffsetType) number_images; n++)
3847 SetGeometry(smush_image,&geometry);
3848 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3849 if (stack != MagickFalse)
3851 x_offset-=geometry.x;
3852 y_offset-=SmushYGap(smush_image,image,offset,exception);
3856 x_offset-=SmushXGap(smush_image,image,offset,exception);
3857 y_offset-=geometry.y;
3859 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3860 y_offset,exception);
3861 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3862 if (proceed == MagickFalse)
3864 if (stack == MagickFalse)
3866 x_offset+=(ssize_t) image->columns;
3872 y_offset+=(ssize_t) image->rows;
3874 image=GetNextImageInList(image);
3876 if (stack == MagickFalse)
3877 smush_image->columns=(size_t) x_offset;
3879 smush_image->rows=(size_t) y_offset;
3880 if (status == MagickFalse)
3881 smush_image=DestroyImage(smush_image);
3882 return(smush_image);
3909MagickExport MagickBooleanType StripImage(
Image *image,
3915 magick_unreferenced(exception);
3916 assert(image != (
Image *) NULL);
3917 if (IsEventLogging() != MagickFalse)
3918 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3919 DestroyImageProfiles(image);
3920 (void) DeleteImageProperty(image,
"comment");
3921 (void) DeleteImageProperty(image,
"date:create");
3922 (void) DeleteImageProperty(image,
"date:modify");
3923 (void) DeleteImageProperty(image,
"date:timestamp");
3924 status=SetImageArtifact(image,
"png:exclude-chunk",
3925 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3955static inline Quantum PushColormapIndex(
Image *image,
const Quantum index,
3956 MagickBooleanType *range_exception)
3958 if ((
size_t) index < image->colors)
3960 *range_exception=MagickTrue;
3961 return((Quantum) 0);
3977 assert(image != (
Image *) NULL);
3978 assert(image->signature == MagickCoreSignature);
3979 if (IsEventLogging() != MagickFalse)
3980 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3981 if (image->ping != MagickFalse)
3983 if (image->storage_class != PseudoClass)
3984 return(MagickFalse);
3985 assert(image->colormap != (
PixelInfo *) NULL);
3986 range_exception=MagickFalse;
3989 image_view=AcquireAuthenticCacheView(image,exception);
3990#if defined(MAGICKCORE_OPENMP_SUPPORT)
3991 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3992 magick_number_threads(image,image,image->rows,2)
3994 for (y=0; y < (ssize_t) image->rows; y++)
4005 if (status == MagickFalse)
4007 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4008 if (q == (Quantum *) NULL)
4013 for (x=0; x < (ssize_t) image->columns; x++)
4015 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4016 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4017 q+=(ptrdiff_t) GetPixelChannels(image);
4019 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4022 image_view=DestroyCacheView(image_view);
4024 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4025 (void) ThrowMagickException(exception,GetMagickModule(),
4026 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4067MagickExport MagickBooleanType SyncImagesSettings(
ImageInfo *image_info,
4073 assert(image_info != (
const ImageInfo *) NULL);
4074 assert(image_info->signature == MagickCoreSignature);
4075 assert(images != (
Image *) NULL);
4076 assert(images->signature == MagickCoreSignature);
4077 if (IsEventLogging() != MagickFalse)
4078 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4080 for ( ; image != (
Image *) NULL; image=GetNextImageInList(image))
4081 (
void) SyncImageSettings(image_info,image,exception);
4082 (void) DeleteImageOption(image_info,
"page");
4086MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4104 assert(image_info != (
const ImageInfo *) NULL);
4105 assert(image_info->signature == MagickCoreSignature);
4106 assert(image != (
Image *) NULL);
4107 assert(image->signature == MagickCoreSignature);
4108 if (IsEventLogging() != MagickFalse)
4109 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4110 option=GetImageOption(image_info,
"background");
4111 if (option != (
const char *) NULL)
4112 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4114 option=GetImageOption(image_info,
"black-point-compensation");
4115 if (option != (
const char *) NULL)
4116 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4117 MagickBooleanOptions,MagickFalse,option);
4118 option=GetImageOption(image_info,
"blue-primary");
4119 if (option != (
const char *) NULL)
4121 flags=ParseGeometry(option,&geometry_info);
4122 if ((flags & RhoValue) != 0)
4123 image->chromaticity.blue_primary.x=geometry_info.rho;
4124 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4125 if ((flags & SigmaValue) != 0)
4126 image->chromaticity.blue_primary.y=geometry_info.sigma;
4128 option=GetImageOption(image_info,
"bordercolor");
4129 if (option != (
const char *) NULL)
4130 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4133 option=GetImageOption(image_info,
"compose");
4134 if (option != (
const char *) NULL)
4135 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4136 MagickFalse,option);
4138 option=GetImageOption(image_info,
"compress");
4139 if (option != (
const char *) NULL)
4140 image->compression=(CompressionType) ParseCommandOption(
4141 MagickCompressOptions,MagickFalse,option);
4142 option=GetImageOption(image_info,
"debug");
4143 if (option != (
const char *) NULL)
4144 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4145 MagickFalse,option);
4146 option=GetImageOption(image_info,
"density");
4147 if (option != (
const char *) NULL)
4149 flags=ParseGeometry(option,&geometry_info);
4150 if ((flags & RhoValue) != 0)
4151 image->resolution.x=geometry_info.rho;
4152 image->resolution.y=image->resolution.x;
4153 if ((flags & SigmaValue) != 0)
4154 image->resolution.y=geometry_info.sigma;
4156 option=GetImageOption(image_info,
"depth");
4157 if (option != (
const char *) NULL)
4158 image->depth=StringToUnsignedLong(option);
4159 option=GetImageOption(image_info,
"endian");
4160 if (option != (
const char *) NULL)
4161 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4162 MagickFalse,option);
4163 option=GetImageOption(image_info,
"filter");
4164 if (option != (
const char *) NULL)
4165 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4166 MagickFalse,option);
4167 option=GetImageOption(image_info,
"fuzz");
4168 if (option != (
const char *) NULL)
4169 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4170 option=GetImageOption(image_info,
"gravity");
4171 if (option != (
const char *) NULL)
4172 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4173 MagickFalse,option);
4174 option=GetImageOption(image_info,
"green-primary");
4175 if (option != (
const char *) NULL)
4177 flags=ParseGeometry(option,&geometry_info);
4178 if ((flags & RhoValue) != 0)
4179 image->chromaticity.green_primary.x=geometry_info.rho;
4180 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4181 if ((flags & SigmaValue) != 0)
4182 image->chromaticity.green_primary.y=geometry_info.sigma;
4184 option=GetImageOption(image_info,
"intent");
4185 if (option != (
const char *) NULL)
4186 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4187 MagickIntentOptions,MagickFalse,option);
4188 option=GetImageOption(image_info,
"intensity");
4189 if (option != (
const char *) NULL)
4190 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4191 MagickPixelIntensityOptions,MagickFalse,option);
4192 option=GetImageOption(image_info,
"interlace");
4193 if (option != (
const char *) NULL)
4194 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4195 MagickFalse,option);
4196 option=GetImageOption(image_info,
"interpolate");
4197 if (option != (
const char *) NULL)
4198 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4199 MagickInterpolateOptions,MagickFalse,option);
4200 option=GetImageOption(image_info,
"loop");
4201 if (option != (
const char *) NULL)
4202 image->iterations=StringToUnsignedLong(option);
4203 option=GetImageOption(image_info,
"mattecolor");
4204 if (option != (
const char *) NULL)
4205 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4207 option=GetImageOption(image_info,
"orient");
4208 if (option != (
const char *) NULL)
4209 image->orientation=(OrientationType) ParseCommandOption(
4210 MagickOrientationOptions,MagickFalse,option);
4211 option=GetImageOption(image_info,
"page");
4212 if (option != (
const char *) NULL)
4217 geometry=GetPageGeometry(option);
4218 flags=ParseAbsoluteGeometry(geometry,&image->page);
4219 geometry=DestroyString(geometry);
4221 option=GetImageOption(image_info,
"quality");
4222 if (option != (
const char *) NULL)
4223 image->quality=StringToUnsignedLong(option);
4224 option=GetImageOption(image_info,
"red-primary");
4225 if (option != (
const char *) NULL)
4227 flags=ParseGeometry(option,&geometry_info);
4228 if ((flags & RhoValue) != 0)
4229 image->chromaticity.red_primary.x=geometry_info.rho;
4230 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4231 if ((flags & SigmaValue) != 0)
4232 image->chromaticity.red_primary.y=geometry_info.sigma;
4234 if (image_info->quality != UndefinedCompressionQuality)
4235 image->quality=image_info->quality;
4236 option=GetImageOption(image_info,
"scene");
4237 if (option != (
const char *) NULL)
4238 image->scene=StringToUnsignedLong(option);
4239 option=GetImageOption(image_info,
"taint");
4240 if (option != (
const char *) NULL)
4241 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4242 MagickFalse,option);
4243 option=GetImageOption(image_info,
"tile-offset");
4244 if (option != (
const char *) NULL)
4249 geometry=GetPageGeometry(option);
4250 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4251 geometry=DestroyString(geometry);
4253 option=GetImageOption(image_info,
"transparent-color");
4254 if (option != (
const char *) NULL)
4255 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4257 option=GetImageOption(image_info,
"type");
4258 if (option != (
const char *) NULL)
4259 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4261 option=GetImageOption(image_info,
"units");
4262 units=image_info->units;
4263 if (option != (
const char *) NULL)
4264 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4265 MagickFalse,option);
4266 if (units != UndefinedResolution)
4268 if (image->units != units)
4269 switch (image->units)
4271 case PixelsPerInchResolution:
4273 if (units == PixelsPerCentimeterResolution)
4275 image->resolution.x/=2.54;
4276 image->resolution.y/=2.54;
4280 case PixelsPerCentimeterResolution:
4282 if (units == PixelsPerInchResolution)
4284 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4285 image->resolution.x+0.5))/100.0;
4286 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4287 image->resolution.y+0.5))/100.0;
4295 option=GetImageOption(image_info,
"density");
4296 if (option != (
const char *) NULL)
4298 flags=ParseGeometry(option,&geometry_info);
4299 if ((flags & RhoValue) != 0)
4300 image->resolution.x=geometry_info.rho;
4301 image->resolution.y=image->resolution.x;
4302 if ((flags & SigmaValue) != 0)
4303 image->resolution.y=geometry_info.sigma;
4306 option=GetImageOption(image_info,
"virtual-pixel");
4307 if (option != (
const char *) NULL)
4308 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4309 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4311 option=GetImageOption(image_info,
"white-point");
4312 if (option != (
const char *) NULL)
4314 flags=ParseGeometry(option,&geometry_info);
4315 if ((flags & RhoValue) != 0)
4316 image->chromaticity.white_point.x=geometry_info.rho;
4317 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4318 if ((flags & SigmaValue) != 0)
4319 image->chromaticity.white_point.y=geometry_info.sigma;
4327 if (image->image_info != (
ImageInfo *) NULL)
4328 image->image_info=DestroyImageInfo(image->image_info);
4329 image->image_info=CloneImageInfo(image_info);