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 image->timestamp=GetMagickTime();
190 time_limit=(int) GetMagickResourceLimit(TimeResource);
192 image->ttl=image->timestamp+time_limit;
193 image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
194 != 0 ? MagickTrue : MagickFalse;
195 image->reference_count=1;
196 image->semaphore=AcquireSemaphoreInfo();
197 image->signature=MagickCoreSignature;
203 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
205 (void) CopyMagickString(image->filename,image_info->filename,
207 (void) CopyMagickString(image->magick_filename,image_info->filename,
209 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
210 if (image_info->size != (
char *) NULL)
212 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
213 image->columns=image->extract_info.width;
214 image->rows=image->extract_info.height;
215 image->offset=image->extract_info.x;
216 image->extract_info.x=0;
217 image->extract_info.y=0;
219 if (image_info->extract != (
char *) NULL)
224 (void) memset(&geometry,0,
sizeof(geometry));
225 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
226 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
228 image->extract_info=geometry;
229 Swap(image->columns,image->extract_info.width);
230 Swap(image->rows,image->extract_info.height);
233 image->compression=image_info->compression;
234 image->quality=image_info->quality;
235 image->endian=image_info->endian;
236 image->interlace=image_info->interlace;
237 image->units=image_info->units;
238 if (image_info->density != (
char *) NULL)
243 flags=ParseGeometry(image_info->density,&geometry_info);
244 if ((flags & RhoValue) != 0)
245 image->resolution.x=geometry_info.rho;
246 image->resolution.y=image->resolution.x;
247 if ((flags & SigmaValue) != 0)
248 image->resolution.y=geometry_info.sigma;
250 if (image_info->page != (
char *) NULL)
255 image->page=image->extract_info;
256 geometry=GetPageGeometry(image_info->page);
257 (void) ParseAbsoluteGeometry(geometry,&image->page);
258 geometry=DestroyString(geometry);
260 if (image_info->depth != 0)
261 image->depth=image_info->depth;
262 image->dither=image_info->dither;
263 image->matte_color=image_info->matte_color;
264 image->background_color=image_info->background_color;
265 image->border_color=image_info->border_color;
266 image->transparent_color=image_info->transparent_color;
267 image->ping=image_info->ping;
268 image->progress_monitor=image_info->progress_monitor;
269 image->client_data=image_info->client_data;
270 if (image_info->cache != (
void *) NULL)
271 ClonePixelCacheMethods(image->cache,image_info->cache);
275 (void) SyncImageSettings(image_info,image,exception);
279 option=GetImageOption(image_info,
"delay");
280 if (option != (
const char *) NULL)
285 flags=ParseGeometry(option,&geometry_info);
286 if ((flags & GreaterValue) != 0)
288 if ((
double) image->delay > floor(geometry_info.rho+0.5))
289 image->delay=(size_t) CastDoubleToLong(floor(
290 geometry_info.rho+0.5));
293 if ((flags & LessValue) != 0)
295 if ((
double) image->delay < floor(geometry_info.rho+0.5))
296 image->ticks_per_second=CastDoubleToLong(floor(
297 geometry_info.sigma+0.5));
300 image->delay=(size_t) CastDoubleToLong(floor(geometry_info.rho+0.5));
301 if ((flags & SigmaValue) != 0)
302 image->ticks_per_second=CastDoubleToLong(floor(
303 geometry_info.sigma+0.5));
305 option=GetImageOption(image_info,
"dispose");
306 if (option != (
const char *) NULL)
307 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
330MagickExport
ImageInfo *AcquireImageInfo(
void)
335 image_info=(
ImageInfo *) AcquireCriticalMemory(
sizeof(*image_info));
336 GetImageInfo(image_info);
371MagickExport
void AcquireNextImage(
const ImageInfo *image_info,
Image *image,
377 assert(image != (
Image *) NULL);
378 assert(image->signature == MagickCoreSignature);
379 if (IsEventLogging() != MagickFalse)
380 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
381 image->next=AcquireImage(image_info,exception);
382 if (GetNextImageInList(image) == (
Image *) NULL)
384 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
387 (
void) CopyMagickString(GetNextImageInList(image)->filename,
388 image_info->filename,MagickPathExtent);
389 DestroyBlob(GetNextImageInList(image));
390 image->next->blob=ReferenceBlob(image->blob);
391 image->next->endian=image->endian;
392 image->next->scene=image->scene+1;
393 image->next->previous=image;
428MagickExport
Image *AppendImages(
const Image *images,
431#define AppendImageTag "Append/Image"
443 homogeneous_colorspace,
472 assert(images != (
Image *) NULL);
473 assert(images->signature == MagickCoreSignature);
475 assert(exception->signature == MagickCoreSignature);
476 if (IsEventLogging() != MagickFalse)
477 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
478 alpha_trait=images->alpha_trait;
480 width=images->columns;
483 image_type=images->type;
484 homogeneous_colorspace=MagickTrue;
485 next=GetNextImageInList(images);
486 for ( ; next != (
Image *) NULL; next=GetNextImageInList(next))
488 if (next->depth > depth)
490 if (next->type != images->type)
491 image_type=UndefinedType;
492 if (next->colorspace != images->colorspace)
493 homogeneous_colorspace=MagickFalse;
494 if (next->alpha_trait != UndefinedPixelTrait)
495 alpha_trait=BlendPixelTrait;
497 if (stack != MagickFalse)
499 if (next->columns > width)
504 width+=next->columns;
505 if (next->rows > height)
511 append_image=CloneImage(images,width,height,MagickTrue,exception);
512 if (append_image == (
Image *) NULL)
513 return((
Image *) NULL);
514 if (image_type != BilevelType)
516 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
518 append_image=DestroyImage(append_image);
519 return((
Image *) NULL);
521 if (homogeneous_colorspace == MagickFalse)
522 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
524 append_image->depth=depth;
525 append_image->alpha_trait=alpha_trait;
526 append_image->page=images->page;
527 (void) SetImageBackgroundColor(append_image,exception);
532 append_view=AcquireAuthenticCacheView(append_image,exception);
533 for (n=0; n < (MagickOffsetType) number_images; n++)
541 SetGeometry(append_image,&geometry);
542 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
543 if (stack != MagickFalse)
544 x_offset-=geometry.x;
546 y_offset-=geometry.y;
547 image_view=AcquireVirtualCacheView(next,exception);
548#if defined(MAGICKCORE_OPENMP_SUPPORT)
549 #pragma omp parallel for schedule(static) shared(status) \
550 magick_number_threads(next,next,next->rows,2)
552 for (y=0; y < (ssize_t) next->rows; y++)
569 if (status == MagickFalse)
571 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
572 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
573 next->columns,1,exception);
574 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
579 GetPixelInfo(next,&pixel);
580 for (x=0; x < (ssize_t) next->columns; x++)
582 GetPixelInfoPixel(next,p,&pixel);
583 SetPixelViaPixelInfo(append_image,&pixel,q);
584 p+=(ptrdiff_t) GetPixelChannels(next);
585 q+=(ptrdiff_t) GetPixelChannels(append_image);
587 sync=SyncCacheViewAuthenticPixels(append_view,exception);
588 if (sync == MagickFalse)
591 image_view=DestroyCacheView(image_view);
592 if (stack == MagickFalse)
594 x_offset+=(ssize_t) next->columns;
600 y_offset+=(ssize_t) next->rows;
602 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
603 if (proceed == MagickFalse)
605 next=GetNextImageInList(next);
607 append_view=DestroyCacheView(append_view);
608 if (status == MagickFalse)
609 append_image=DestroyImage(append_image);
610 return(append_image);
637MagickExport ExceptionType CatchImageException(
Image *image)
645 assert(image != (
const Image *) NULL);
646 assert(image->signature == MagickCoreSignature);
647 if (IsEventLogging() != MagickFalse)
648 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
649 exception=AcquireExceptionInfo();
650 CatchException(exception);
651 severity=exception->severity;
652 exception=DestroyExceptionInfo(exception);
691 return(ClipImagePath(image,
"#1",MagickTrue,exception));
694MagickExport MagickBooleanType ClipImagePath(
Image *image,
const char *pathname,
697#define ClipImagePathTag "ClipPath/Image"
711 assert(image != (
const Image *) NULL);
712 assert(image->signature == MagickCoreSignature);
713 assert(pathname != NULL);
714 if (IsEventLogging() != MagickFalse)
715 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
716 property=AcquireString(pathname);
717 (void) FormatLocaleString(property,MagickPathExtent,
"8BIM:1999,2998:%s",
719 value=GetImageProperty(image,property,exception);
720 property=DestroyString(property);
721 if (value == (
const char *) NULL)
723 ThrowFileException(exception,OptionError,
"NoClipPathDefined",
727 image_info=AcquireImageInfo();
728 (void) CopyMagickString(image_info->filename,image->filename,
730 (void) ConcatenateMagickString(image_info->filename,pathname,
732 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
733 image_info=DestroyImageInfo(image_info);
734 if (clip_mask == (
Image *) NULL)
736 if (clip_mask->storage_class == PseudoClass)
738 (void) SyncImage(clip_mask,exception);
739 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
742 if (inside != MagickFalse)
743 (void) NegateImage(clip_mask,MagickFalse,exception);
744 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
745 "8BIM:1999,2998:%s\nPS",pathname);
746 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
747 image->mask_trait=UpdatePixelTrait;
748 clip_mask=DestroyImage(clip_mask);
791MagickExport
Image *CloneImage(
const Image *image,
const size_t columns,
792 const size_t rows,
const MagickBooleanType detach,
ExceptionInfo *exception)
807 assert(image != (
const Image *) NULL);
808 assert(image->signature == MagickCoreSignature);
810 assert(exception->signature == MagickCoreSignature);
811 if (IsEventLogging() != MagickFalse)
812 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
813 if ((image->columns == 0) || (image->rows == 0))
815 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
816 "NegativeOrZeroImageSize",
"`%s'",image->filename);
817 return((
Image *) NULL);
819 clone_image=(
Image *) AcquireCriticalMemory(
sizeof(*clone_image));
820 (void) memset(clone_image,0,
sizeof(*clone_image));
821 clone_image->signature=MagickCoreSignature;
822 clone_image->storage_class=image->storage_class;
823 clone_image->number_channels=image->number_channels;
824 clone_image->number_meta_channels=image->number_meta_channels;
825 clone_image->metacontent_extent=image->metacontent_extent;
826 clone_image->colorspace=image->colorspace;
827 clone_image->alpha_trait=image->alpha_trait;
828 clone_image->channels=image->channels;
829 clone_image->mask_trait=image->mask_trait;
830 clone_image->columns=image->columns;
831 clone_image->rows=image->rows;
832 clone_image->dither=image->dither;
833 clone_image->image_info=CloneImageInfo(image->image_info);
834 (void) CloneImageProfiles(clone_image,image);
835 (void) CloneImageProperties(clone_image,image);
836 (void) CloneImageArtifacts(clone_image,image);
837 GetTimerInfo(&clone_image->timer);
838 if (image->ascii85 != (
void *) NULL)
839 Ascii85Initialize(clone_image);
840 clone_image->extent=image->extent;
841 clone_image->magick_columns=image->magick_columns;
842 clone_image->magick_rows=image->magick_rows;
843 clone_image->type=image->type;
844 clone_image->channel_mask=image->channel_mask;
845 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
846 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
848 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
849 (void) CopyMagickString(clone_image->filename,image->filename,
851 clone_image->progress_monitor=image->progress_monitor;
852 clone_image->client_data=image->client_data;
853 clone_image->reference_count=1;
854 clone_image->next=image->next;
855 clone_image->previous=image->previous;
856 clone_image->list=NewImageList();
857 if (detach == MagickFalse)
858 clone_image->blob=ReferenceBlob(image->blob);
861 clone_image->next=NewImageList();
862 clone_image->previous=NewImageList();
863 clone_image->blob=CloneBlobInfo((
BlobInfo *) NULL);
865 clone_image->ping=image->ping;
866 clone_image->timestamp=image->timestamp;
867 clone_image->ttl=image->ttl;
868 clone_image->debug=image->debug;
869 clone_image->semaphore=AcquireSemaphoreInfo();
870 if (image->colormap != (
PixelInfo *) NULL)
875 clone_image->colors=image->colors;
876 length=(size_t) image->colors;
877 clone_image->colormap=(
PixelInfo *) AcquireQuantumMemory(length+1,
878 sizeof(*clone_image->colormap));
879 if (clone_image->colormap == (
PixelInfo *) NULL)
881 clone_image=DestroyImage(clone_image);
882 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
884 (void) memcpy(clone_image->colormap,image->colormap,length*
885 sizeof(*clone_image->colormap));
887 if ((columns == 0) || (rows == 0))
889 if (image->montage != (
char *) NULL)
890 (
void) CloneString(&clone_image->montage,image->montage);
891 if (image->directory != (
char *) NULL)
892 (void) CloneString(&clone_image->directory,image->directory);
893 clone_image->cache=ReferencePixelCache(image->cache);
898 if (image->columns != 0)
899 scale_x=(double) columns/(
double) image->columns;
900 if (image->rows != 0)
901 scale_y=(double) rows/(
double) image->rows;
902 clone_image->page.width=(size_t) CastDoubleToLong(floor(scale_x*
903 image->page.width+0.5));
904 clone_image->page.height=(size_t) CastDoubleToLong(floor(scale_y*
905 image->page.height+0.5));
906 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
907 scale_x=scale_y=MagickMin(scale_x,scale_y);
908 clone_image->page.x=CastDoubleToLong(ceil(scale_x*image->page.x-0.5));
909 clone_image->tile_offset.x=CastDoubleToLong(ceil(scale_x*
910 image->tile_offset.x-0.5));
911 clone_image->page.y=CastDoubleToLong(ceil(scale_y*image->page.y-0.5));
912 clone_image->tile_offset.y=CastDoubleToLong(ceil(scale_y*
913 image->tile_offset.y-0.5));
914 clone_image->cache=ClonePixelCache(image->cache);
915 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
916 clone_image=DestroyImage(clone_image);
949 clone_info=AcquireImageInfo();
952 clone_info->compression=image_info->compression;
953 clone_info->temporary=image_info->temporary;
954 clone_info->adjoin=image_info->adjoin;
955 clone_info->antialias=image_info->antialias;
956 clone_info->scene=image_info->scene;
957 clone_info->number_scenes=image_info->number_scenes;
958 clone_info->depth=image_info->depth;
959 if (image_info->size != (
char *) NULL)
960 (void) CloneString(&clone_info->size,image_info->size);
961 if (image_info->extract != (
char *) NULL)
962 (
void) CloneString(&clone_info->extract,image_info->extract);
963 if (image_info->scenes != (
char *) NULL)
964 (void) CloneString(&clone_info->scenes,image_info->scenes);
965 if (image_info->page != (
char *) NULL)
966 (
void) CloneString(&clone_info->page,image_info->page);
967 clone_info->interlace=image_info->interlace;
968 clone_info->endian=image_info->endian;
969 clone_info->units=image_info->units;
970 clone_info->quality=image_info->quality;
971 if (image_info->sampling_factor != (
char *) NULL)
972 (void) CloneString(&clone_info->sampling_factor,
973 image_info->sampling_factor);
974 if (image_info->server_name != (
char *) NULL)
975 (
void) CloneString(&clone_info->server_name,image_info->server_name);
976 if (image_info->font != (
char *) NULL)
977 (void) CloneString(&clone_info->font,image_info->font);
978 if (image_info->texture != (
char *) NULL)
979 (
void) CloneString(&clone_info->texture,image_info->texture);
980 if (image_info->density != (
char *) NULL)
981 (void) CloneString(&clone_info->density,image_info->density);
982 clone_info->pointsize=image_info->pointsize;
983 clone_info->fuzz=image_info->fuzz;
984 clone_info->matte_color=image_info->matte_color;
985 clone_info->background_color=image_info->background_color;
986 clone_info->border_color=image_info->border_color;
987 clone_info->transparent_color=image_info->transparent_color;
988 clone_info->dither=image_info->dither;
989 clone_info->monochrome=image_info->monochrome;
990 clone_info->colorspace=image_info->colorspace;
991 clone_info->type=image_info->type;
992 clone_info->orientation=image_info->orientation;
993 clone_info->ping=image_info->ping;
994 clone_info->verbose=image_info->verbose;
995 clone_info->progress_monitor=image_info->progress_monitor;
996 clone_info->client_data=image_info->client_data;
997 clone_info->cache=image_info->cache;
998 if (image_info->cache != (
void *) NULL)
999 clone_info->cache=ReferencePixelCache(image_info->cache);
1000 if (image_info->profile != (
void *) NULL)
1001 clone_info->profile=(
void *) CloneStringInfo((
StringInfo *)
1002 image_info->profile);
1003 SetImageInfoFile(clone_info,image_info->file);
1004 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1005 clone_info->stream=image_info->stream;
1006 clone_info->custom_stream=image_info->custom_stream;
1007 (void) CopyMagickString(clone_info->magick,image_info->magick,
1009 (void) CopyMagickString(clone_info->unique,image_info->unique,
1011 (void) CopyMagickString(clone_info->filename,image_info->filename,
1013 clone_info->channel=image_info->channel;
1014 (void) CloneImageOptions(clone_info,image_info);
1015 clone_info->coder_depth=image_info->coder_depth;
1016 clone_info->debug=image_info->debug;
1017 clone_info->signature=image_info->signature;
1054MagickExport MagickBooleanType CopyImagePixels(
Image *image,
1058#define CopyImageTag "Copy/Image"
1073 assert(image != (
Image *) NULL);
1074 assert(source_image != (
Image *) NULL);
1077 if (IsEventLogging() != MagickFalse)
1078 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1079 if ((offset->x < 0) || (offset->y < 0) ||
1080 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1081 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1082 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1084 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1085 return(MagickFalse);
1091 source_view=AcquireVirtualCacheView(source_image,exception);
1092 image_view=AcquireAuthenticCacheView(image,exception);
1093#if defined(MAGICKCORE_OPENMP_SUPPORT)
1094 #pragma omp parallel for schedule(static) shared(progress,status) \
1095 magick_number_threads(image,source_image,geometry->height,2)
1097 for (y=0; y < (ssize_t) geometry->height; y++)
1111 if (status == MagickFalse)
1113 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1114 geometry->width,1,exception);
1115 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1116 geometry->width,1,exception);
1117 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1122 for (x=0; x < (ssize_t) geometry->width; x++)
1127 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1129 PixelChannel channel = GetPixelChannelChannel(image,i);
1130 PixelTrait traits = GetPixelChannelTraits(image,channel);
1131 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1132 if ((traits == UndefinedPixelTrait) ||
1133 ((traits & UpdatePixelTrait) == 0) ||
1134 (source_traits == UndefinedPixelTrait))
1136 SetPixelChannel(image,channel,p[i],q);
1138 p+=(ptrdiff_t) GetPixelChannels(source_image);
1139 q+=(ptrdiff_t) GetPixelChannels(image);
1141 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1142 if (sync == MagickFalse)
1144 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1149#if defined(MAGICKCORE_OPENMP_SUPPORT)
1153 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1154 if (proceed == MagickFalse)
1158 source_view=DestroyCacheView(source_view);
1159 image_view=DestroyCacheView(image_view);
1186MagickExport
Image *DestroyImage(
Image *image)
1194 assert(image != (
Image *) NULL);
1195 assert(image->signature == MagickCoreSignature);
1196 if (IsEventLogging() != MagickFalse)
1197 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1198 destroy=MagickFalse;
1199 LockSemaphoreInfo(image->semaphore);
1200 image->reference_count--;
1201 if (image->reference_count == 0)
1203 UnlockSemaphoreInfo(image->semaphore);
1204 if (destroy == MagickFalse)
1205 return((
Image *) NULL);
1209 DestroyImagePixels(image);
1210 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1211 if (image->montage != (
char *) NULL)
1212 image->montage=DestroyString(image->montage);
1213 if (image->directory != (
char *) NULL)
1214 image->directory=DestroyString(image->directory);
1215 if (image->colormap != (
PixelInfo *) NULL)
1216 image->colormap=(
PixelInfo *) RelinquishMagickMemory(image->colormap);
1217 if (image->geometry != (
char *) NULL)
1218 image->geometry=DestroyString(image->geometry);
1219 DestroyImageProfiles(image);
1220 DestroyImageProperties(image);
1221 DestroyImageArtifacts(image);
1223 image->ascii85=(
Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1224 if (image->image_info != (
ImageInfo *) NULL)
1225 image->image_info=DestroyImageInfo(image->image_info);
1228 RelinquishSemaphoreInfo(&image->semaphore);
1229 image->signature=(~MagickCoreSignature);
1230 image=(
Image *) RelinquishMagickMemory(image);
1259 assert(image_info != (
ImageInfo *) NULL);
1260 assert(image_info->signature == MagickCoreSignature);
1261 if (IsEventLogging() != MagickFalse)
1262 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1263 image_info->filename);
1264 if (image_info->size != (
char *) NULL)
1265 image_info->size=DestroyString(image_info->size);
1266 if (image_info->extract != (
char *) NULL)
1267 image_info->extract=DestroyString(image_info->extract);
1268 if (image_info->scenes != (
char *) NULL)
1269 image_info->scenes=DestroyString(image_info->scenes);
1270 if (image_info->page != (
char *) NULL)
1271 image_info->page=DestroyString(image_info->page);
1272 if (image_info->sampling_factor != (
char *) NULL)
1273 image_info->sampling_factor=DestroyString(
1274 image_info->sampling_factor);
1275 if (image_info->server_name != (
char *) NULL)
1276 image_info->server_name=DestroyString(
1277 image_info->server_name);
1278 if (image_info->font != (
char *) NULL)
1279 image_info->font=DestroyString(image_info->font);
1280 if (image_info->texture != (
char *) NULL)
1281 image_info->texture=DestroyString(image_info->texture);
1282 if (image_info->density != (
char *) NULL)
1283 image_info->density=DestroyString(image_info->density);
1284 if (image_info->cache != (
void *) NULL)
1285 image_info->cache=DestroyPixelCache(image_info->cache);
1286 if (image_info->profile != (
StringInfo *) NULL)
1287 image_info->profile=(
void *) DestroyStringInfo((
StringInfo *)
1288 image_info->profile);
1289 DestroyImageOptions(image_info);
1290 image_info->signature=(~MagickCoreSignature);
1291 image_info=(
ImageInfo *) RelinquishMagickMemory(image_info);
1319MagickExport
void DisassociateImageStream(
Image *image)
1321 assert(image != (
Image *) NULL);
1322 assert(image->signature == MagickCoreSignature);
1323 if (IsEventLogging() != MagickFalse)
1324 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1325 DisassociateBlob(image);
1350MagickExport
void GetImageInfo(
ImageInfo *image_info)
1358 assert(image_info != (
ImageInfo *) NULL);
1359 if (IsEventLogging() != MagickFalse)
1360 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1361 (void) memset(image_info,0,
sizeof(*image_info));
1362 image_info->adjoin=MagickTrue;
1363 image_info->interlace=NoInterlace;
1364 image_info->channel=AllChannels;
1365 image_info->quality=UndefinedCompressionQuality;
1366 image_info->antialias=MagickTrue;
1367 image_info->dither=MagickTrue;
1368 image_info->depth=0;
1369 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1370 if (synchronize != (
const char *) NULL)
1372 image_info->synchronize=IsStringTrue(synchronize);
1373 synchronize=DestroyString(synchronize);
1375 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1376 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1377 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1378 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1379 image_info->coder_depth=0;
1380 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1382 image_info->signature=MagickCoreSignature;
1407MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1409 return(image_info->file);
1437MagickExport
Image *GetImageMask(
const Image *image,
const PixelMask type,
1456 assert(image != (
Image *) NULL);
1457 assert(image->signature == MagickCoreSignature);
1458 if (IsEventLogging() != MagickFalse)
1459 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1464 if ((image->channels & ReadMaskChannel) == 0)
1465 return((
Image *) NULL);
1468 case WritePixelMask:
1470 if ((image->channels & WriteMaskChannel) == 0)
1471 return((
Image *) NULL);
1476 if ((image->channels & CompositeMaskChannel) == 0)
1477 return((
Image *) NULL);
1481 mask_image=AcquireImage((
ImageInfo *) NULL,exception);
1482 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1483 if (status == MagickFalse)
1484 return(DestroyImage(mask_image));
1486 mask_image->alpha_trait=UndefinedPixelTrait;
1487 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1488 image_view=AcquireVirtualCacheView(image,exception);
1489 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1490#if defined(MAGICKCORE_OPENMP_SUPPORT)
1491 #pragma omp parallel for schedule(static) shared(status) \
1492 magick_number_threads(image,image,image->rows,2)
1494 for (y=0; y < (ssize_t) image->rows; y++)
1505 if (status == MagickFalse)
1507 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1508 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1510 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1515 for (x=0; x < (ssize_t) image->columns; x++)
1521 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1524 case WritePixelMask:
1526 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1531 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1535 p+=(ptrdiff_t) GetPixelChannels(image);
1536 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1538 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1541 mask_view=DestroyCacheView(mask_view);
1542 image_view=DestroyCacheView(image_view);
1543 if (status == MagickFalse)
1544 mask_image=DestroyImage(mask_image);
1570MagickExport ssize_t GetImageReferenceCount(
Image *image)
1575 assert(image != (
Image *) NULL);
1576 assert(image->signature == MagickCoreSignature);
1577 if (IsEventLogging() != MagickFalse)
1578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1579 LockSemaphoreInfo(image->semaphore);
1580 reference_count=image->reference_count;
1581 UnlockSemaphoreInfo(image->semaphore);
1582 return(reference_count);
1609MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1611 assert(image != (
Image *) NULL);
1612 assert(image->signature == MagickCoreSignature);
1613 if (IsEventLogging() != MagickFalse)
1614 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1615 return(GetPixelCacheVirtualMethod(image));
1654static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1658 specifier = end[-1];
1661 length = (size_t) (end-start);
1666 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1667 return(MagickFalse);
1668 if ((length == 1) && (*start == specifier))
1677 if ((length >= 3) && (start[1] ==
'0'))
1678 return(MagickFalse);
1681 for ( ; i < (length-1); i++)
1682 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1683 return(MagickFalse);
1686 return(MagickFalse);
1689MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1690 Image *image,
const char *format,
int value,
char *filename,
1695 pattern[MagickPathExtent];
1700 assert(format != (
const char *) NULL);
1701 assert(filename != (
char *) NULL);
1702 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1704 (void) CopyMagickString(filename,format,MagickPathExtent);
1705 return(strlen(filename));
1707 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1725 specifier_start=cursor;
1726 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1728 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1731 *specifier_end = cursor+1;
1733 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1736 format_specifier[MagickPathExtent];
1739 length = (size_t) (cursor-specifier_start),
1745 (void) snprintf(format_specifier,
sizeof(format_specifier),
1746 "%%%.*s%c",(int) length,specifier_start,*cursor);
1747 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1749 pattern_length=strlen(pattern);
1750 if ((count <= 0) || ((
size_t) count != pattern_length))
1752 if ((p-filename+pattern_length) >= MagickPathExtent)
1754 (void) CopyMagickString(p,pattern,(
size_t) (MagickPathExtent-
1773 *end = strchr(cursor,
']'),
1774 *option = (
const char *) NULL;
1780 if (end == (
const char *) NULL)
1782 extent=(size_t) (end-cursor-1);
1783 if (extent >=
sizeof(pattern))
1785 (void) CopyMagickString(pattern,cursor+1,extent+1);
1786 pattern[extent]=
'\0';
1789 option=GetImageProperty(image,pattern,exception);
1790 if (option == (
const char *) NULL)
1791 option=GetImageArtifact(image,pattern);
1793 if ((option == (
const char *) NULL) &&
1795 option=GetImageOption(image_info,pattern);
1796 if (option == (
const char *) NULL)
1798 option_length=strlen(option);
1799 if ((p-filename+option_length) >= MagickPathExtent)
1801 (void) CopyMagickString(p,option,(
size_t) (MagickPathExtent-
1811 if ((p-filename+1) >= MagickPathExtent)
1816 return(strlen(filename));
1846MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1849#if !defined(MAGICKCORE_HDRI_SUPPORT)
1852 return(MagickFalse);
1863 assert(image != (
Image *) NULL);
1864 assert(image->signature == MagickCoreSignature);
1865 if (IsEventLogging() != MagickFalse)
1866 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1867 image_view=AcquireVirtualCacheView(image,exception);
1868#if defined(MAGICKCORE_OPENMP_SUPPORT)
1869 #pragma omp parallel for schedule(static) shared(hdri) \
1870 magick_number_threads(image,image,image->rows,2)
1872 for (y=0; y < (ssize_t) image->rows; y++)
1880 if (hdri != MagickFalse)
1882 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1883 if (p == (
const Quantum *) NULL)
1885 for (x=0; x < (ssize_t) image->columns; x++)
1890 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1898 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1899 if (traits == UndefinedPixelTrait)
1901 pixel=(double) p[i];
1902 if ((pixel < 0.0) || (pixel > (double) QuantumRange) ||
1903 (pixel != (double) ((QuantumAny) pixel)))
1909 if (hdri != MagickFalse)
1911 p+=(ptrdiff_t) GetPixelChannels(image);
1914 image_view=DestroyCacheView(image_view);
1942MagickExport MagickBooleanType IsImageObject(
const Image *image)
1947 assert(image != (
Image *) NULL);
1948 if (IsEventLogging() != MagickFalse)
1949 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1950 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1951 if (p->signature != MagickCoreSignature)
1952 return(MagickFalse);
1979MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1982 magick[MagickPathExtent],
1983 filename[MagickPathExtent];
1988 assert(image != (
Image *) NULL);
1989 assert(image->signature == MagickCoreSignature);
1990 if (IsEventLogging() != MagickFalse)
1991 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1992 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1993 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1994 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1996 if (p->taint != MagickFalse)
1998 if (LocaleCompare(p->magick,magick) != 0)
2000 if (LocaleCompare(p->filename,filename) != 0)
2003 return(MagickFalse);
2032MagickExport MagickBooleanType ModifyImage(
Image **image,
2038 assert(image != (
Image **) NULL);
2039 assert(*image != (
Image *) NULL);
2040 assert((*image)->signature == MagickCoreSignature);
2041 if (IsEventLogging() != MagickFalse)
2042 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2043 if (GetImageReferenceCount(*image) <= 1)
2045 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2046 LockSemaphoreInfo((*image)->semaphore);
2047 (*image)->reference_count--;
2048 UnlockSemaphoreInfo((*image)->semaphore);
2087 const size_t width,
const size_t height,
const PixelInfo *background,
2102 assert(image_info != (
const ImageInfo *) NULL);
2103 assert(image_info->signature == MagickCoreSignature);
2104 assert(background != (
const PixelInfo *) NULL);
2105 if (IsEventLogging() != MagickFalse)
2106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2107 image=AcquireImage(image_info,exception);
2108 image->columns=width;
2110 image->colorspace=background->colorspace;
2111 image->alpha_trait=background->alpha_trait;
2112 image->fuzz=background->fuzz;
2113 image->depth=background->depth;
2115 image_view=AcquireAuthenticCacheView(image,exception);
2116#if defined(MAGICKCORE_OPENMP_SUPPORT)
2117 #pragma omp parallel for schedule(static) shared(status) \
2118 magick_number_threads(image,image,image->rows,2)
2120 for (y=0; y < (ssize_t) image->rows; y++)
2128 if (status == MagickFalse)
2130 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2131 if (q == (Quantum *) NULL)
2136 for (x=0; x < (ssize_t) image->columns; x++)
2138 SetPixelViaPixelInfo(image,background,q);
2139 q+=(ptrdiff_t) GetPixelChannels(image);
2141 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2144 image_view=DestroyCacheView(image_view);
2145 if (status == MagickFalse)
2146 image=DestroyImage(image);
2173MagickExport
Image *ReferenceImage(
Image *image)
2175 assert(image != (
Image *) NULL);
2176 assert(image->signature == MagickCoreSignature);
2177 if (IsEventLogging() != MagickFalse)
2178 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2179 LockSemaphoreInfo(image->semaphore);
2180 image->reference_count++;
2181 UnlockSemaphoreInfo(image->semaphore);
2209MagickExport MagickBooleanType ResetImagePage(
Image *image,
const char *page)
2217 assert(image != (
Image *) NULL);
2218 assert(image->signature == MagickCoreSignature);
2219 if (IsEventLogging() != MagickFalse)
2220 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2221 flags=ParseAbsoluteGeometry(page,&geometry);
2222 if ((flags & WidthValue) != 0)
2224 if ((flags & HeightValue) == 0)
2225 geometry.height=geometry.width;
2226 image->page.width=geometry.width;
2227 image->page.height=geometry.height;
2229 if ((flags & AspectValue) != 0)
2231 if ((flags & XValue) != 0)
2232 image->page.x+=geometry.x;
2233 if ((flags & YValue) != 0)
2234 image->page.y+=geometry.y;
2238 if ((flags & XValue) != 0)
2240 image->page.x=geometry.x;
2241 if ((image->page.width == 0) && (geometry.x > 0))
2242 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2244 if ((flags & YValue) != 0)
2246 image->page.y=geometry.y;
2247 if ((image->page.height == 0) && (geometry.y > 0))
2248 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2280MagickExport MagickBooleanType ResetImagePixels(
Image *image,
2298 assert(image != (
Image *) NULL);
2299 assert(image->signature == MagickCoreSignature);
2300 if (IsEventLogging() != MagickFalse)
2301 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2302 pixels=AcquirePixelCachePixels(image,&length,exception);
2303 if (pixels != (
void *) NULL)
2308 (void) memset(pixels,0,length);
2315 image_view=AcquireAuthenticCacheView(image,exception);
2316#if defined(MAGICKCORE_OPENMP_SUPPORT)
2317 #pragma omp parallel for schedule(static) shared(status) \
2318 magick_number_threads(image,image,image->rows,2)
2320 for (y=0; y < (ssize_t) image->rows; y++)
2328 if (status == MagickFalse)
2330 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2331 if (q == (Quantum *) NULL)
2336 for (x=0; x < (ssize_t) image->columns; x++)
2338 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2339 q+=(ptrdiff_t) GetPixelChannels(image);
2341 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2344 image_view=DestroyCacheView(image_view);
2376MagickExport MagickBooleanType SetImageAlpha(
Image *image,
const Quantum alpha,
2388 assert(image != (
Image *) NULL);
2389 assert(image->signature == MagickCoreSignature);
2390 if (IsEventLogging() != MagickFalse)
2391 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2392 image->alpha_trait=BlendPixelTrait;
2394 image_view=AcquireAuthenticCacheView(image,exception);
2395#if defined(MAGICKCORE_OPENMP_SUPPORT)
2396 #pragma omp parallel for schedule(static) shared(status) \
2397 magick_number_threads(image,image,image->rows,2)
2399 for (y=0; y < (ssize_t) image->rows; y++)
2407 if (status == MagickFalse)
2409 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2410 if (q == (Quantum *) NULL)
2415 for (x=0; x < (ssize_t) image->columns; x++)
2417 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2418 SetPixelAlpha(image,alpha,q);
2419 q+=(ptrdiff_t) GetPixelChannels(image);
2421 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2424 image_view=DestroyCacheView(image_view);
2455MagickExport MagickBooleanType SetImageBackgroundColor(
Image *image,
2470 assert(image != (
Image *) NULL);
2471 assert(image->signature == MagickCoreSignature);
2472 if (IsEventLogging() != MagickFalse)
2473 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2474 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2475 return(MagickFalse);
2476 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2477 ((image->alpha_trait & BlendPixelTrait) == 0))
2478 (
void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2479 ConformPixelInfo(image,&image->background_color,&background,exception);
2484 image_view=AcquireAuthenticCacheView(image,exception);
2485#if defined(MAGICKCORE_OPENMP_SUPPORT)
2486 #pragma omp parallel for schedule(static) shared(status) \
2487 magick_number_threads(image,image,image->rows,2)
2489 for (y=0; y < (ssize_t) image->rows; y++)
2497 if (status == MagickFalse)
2499 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2500 if (q == (Quantum *) NULL)
2505 for (x=0; x < (ssize_t) image->columns; x++)
2507 SetPixelViaPixelInfo(image,&background,q);
2508 q+=(ptrdiff_t) GetPixelChannels(image);
2510 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2513 image_view=DestroyCacheView(image_view);
2543MagickExport ChannelType SetImageChannelMask(
Image *image,
2544 const ChannelType channel_mask)
2546 return(SetPixelChannelMask(image,channel_mask));
2576MagickExport MagickBooleanType SetImageColor(
Image *image,
2588 assert(image != (
Image *) NULL);
2589 assert(image->signature == MagickCoreSignature);
2590 assert(color != (
const PixelInfo *) NULL);
2591 if (IsEventLogging() != MagickFalse)
2592 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2593 image->colorspace=color->colorspace;
2594 image->alpha_trait=color->alpha_trait;
2595 image->fuzz=color->fuzz;
2596 image->depth=color->depth;
2598 image_view=AcquireAuthenticCacheView(image,exception);
2599#if defined(MAGICKCORE_OPENMP_SUPPORT)
2600 #pragma omp parallel for schedule(static) shared(status) \
2601 magick_number_threads(image,image,image->rows,2)
2603 for (y=0; y < (ssize_t) image->rows; y++)
2611 if (status == MagickFalse)
2613 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2614 if (q == (Quantum *) NULL)
2619 for (x=0; x < (ssize_t) image->columns; x++)
2621 SetPixelViaPixelInfo(image,color,q);
2622 q+=(ptrdiff_t) GetPixelChannels(image);
2624 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2627 image_view=DestroyCacheView(image_view);
2659MagickExport MagickBooleanType SetImageStorageClass(
Image *image,
2662 assert(image != (
Image *) NULL);
2663 assert(image->signature == MagickCoreSignature);
2665 assert(exception->signature == MagickCoreSignature);
2666 if (IsEventLogging() != MagickFalse)
2667 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2668 image->storage_class=storage_class;
2669 return(SyncImagePixelCache(image,exception));
2701MagickExport MagickBooleanType SetImageExtent(
Image *image,
const size_t columns,
2704 if ((columns == 0) || (rows == 0))
2705 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2706 image->columns=columns;
2708 if (image->depth == 0)
2711 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2712 "ImageDepthNotSupported",
"`%s'",image->filename);
2714 if (image->depth > (8*
sizeof(MagickSizeType)))
2716 image->depth=8*
sizeof(MagickSizeType);
2717 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2718 "ImageDepthNotSupported",
"`%s'",image->filename);
2720 return(SyncImagePixelCache(image,exception));
2771 *format_type_formats[] =
2795 (void) CopyMagickString(magic,component,MagickPathExtent);
2800 format_type=UndefinedFormatType;
2801 magick_info=GetMagickInfo(magic,exception);
2802 if ((magick_info != (
const MagickInfo *) NULL) &&
2803 (magick_info->format_type != UndefinedFormatType))
2804 format_type=magick_info->format_type;
2806 while ((format_type == UndefinedFormatType) &&
2807 (format_type_formats[i] != (
char *) NULL))
2809 if ((*magic == *format_type_formats[i]) &&
2810 (LocaleCompare(magic,format_type_formats[i]) == 0))
2811 format_type=ExplicitFormatType;
2814 if (format_type == UndefinedFormatType)
2815 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2817 if (format_type == ExplicitFormatType)
2819 image_info->affirm=MagickTrue;
2820 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2822 if (LocaleCompare(magic,
"RGB") == 0)
2823 image_info->affirm=MagickFalse;
2824 return(magick_info);
2827MagickExport MagickBooleanType SetImageInfo(
ImageInfo *image_info,
2831 component[MagickPathExtent],
2832 magic[MagickPathExtent],
2833 path[MagickPathExtent],
2860 assert(image_info != (
ImageInfo *) NULL);
2861 assert(image_info->signature == MagickCoreSignature);
2862 if (IsEventLogging() != MagickFalse)
2863 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2864 image_info->filename);
2866 GetPathComponent(image_info->filename,SubimagePath,component);
2867 if (*component !=
'\0')
2872 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2874 if (IsGeometry(component) != MagickFalse)
2875 (void) CloneString(&image_info->extract,component);
2883 (void) CloneString(&image_info->scenes,component);
2884 image_info->scene=StringToUnsignedLong(image_info->scenes);
2885 image_info->number_scenes=image_info->scene;
2886 p=image_info->scenes;
2887 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2889 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2891 first=(size_t) strtol(p,&q,10);
2893 while (isspace((
int) ((
unsigned char) *q)) != 0)
2896 last=(size_t) strtol(q+1,&q,10);
2899 if (first < image_info->scene)
2900 image_info->scene=first;
2901 if (last > image_info->number_scenes)
2902 image_info->number_scenes=last;
2905 image_info->number_scenes-=image_info->scene-1;
2909 if (*image_info->magick ==
'\0')
2910 GetPathComponent(image_info->filename,ExtensionPath,component);
2911 if (*component !=
'\0')
2916 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2917 GetPathComponent(path,ExtensionPath,component);
2919 image_info->affirm=MagickFalse;
2920 sans_exception=AcquireExceptionInfo();
2921 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2922 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2928 GetPathComponent(image_info->filename,MagickPath,magic);
2931 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2932 magick_info=GetMagickInfo(magic,sans_exception);
2933 if ((magick_info != (
const MagickInfo *) NULL) &&
2934 (magick_info->format_type == ExplicitFormatType))
2935 image_info->affirm=MagickTrue;
2937 GetPathComponent(image_info->filename,CanonicalPath,component);
2939 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2940 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2951 magick_info=GetMagickInfo(magic,sans_exception);
2953 if (magick_info == (
const MagickInfo *) NULL)
2955 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2957 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2959 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2964 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2968 if (((magick_info != (
const MagickInfo *) NULL) ||
2970 (IsMagickConflict(magic) == MagickFalse))
2972 image_info->affirm=MagickTrue;
2973 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2974 GetPathComponent(image_info->filename,CanonicalPath,component);
2975 (void) CopyMagickString(image_info->filename,component,
2979 sans_exception=DestroyExceptionInfo(sans_exception);
2980 if ((magick_info == (
const MagickInfo *) NULL) ||
2981 (GetMagickEndianSupport(magick_info) == MagickFalse))
2982 image_info->endian=UndefinedEndian;
2983 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2988 (void) InterpretImageFilename(image_info,(
Image *) NULL,
2989 image_info->filename,(int) image_info->scene,component,exception);
2990 if ((LocaleCompare(component,image_info->filename) != 0) &&
2991 (strchr(component,
'%') == (
char *) NULL))
2992 image_info->adjoin=MagickFalse;
2994 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2999 magick_info=GetMagickInfo(magic,exception);
3000 if (magick_info != (
const MagickInfo *) NULL)
3001 if (GetMagickAdjoin(magick_info) == MagickFalse)
3002 image_info->adjoin=MagickFalse;
3004 if (image_info->affirm != MagickFalse)
3017 magick_size=GetMagicPatternExtent(exception);
3018 if (magick_size == 0)
3019 return(MagickFalse);
3020 image=AcquireImage(image_info,exception);
3021 (void) CopyMagickString(image->filename,image_info->filename,
3023 sans_exception=AcquireExceptionInfo();
3024 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3025 sans_exception=DestroyExceptionInfo(sans_exception);
3026 if (status == MagickFalse)
3028 image=DestroyImage(image);
3029 return(MagickFalse);
3031 if ((IsBlobSeekable(image) == MagickFalse) ||
3032 (IsBlobExempt(image) != MagickFalse))
3038 status=ImageToFile(image,component,exception);
3039 if (CloseBlob(image) == MagickFalse)
3041 if (status == MagickFalse)
3043 (void) RelinquishUniqueFileResource(component);
3044 image=DestroyImage(image);
3045 return(MagickFalse);
3047 SetImageInfoFile(image_info,(FILE *) NULL);
3048 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3049 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3050 if (status == MagickFalse)
3052 (void) RelinquishUniqueFileResource(component);
3053 image=DestroyImage(image);
3054 return(MagickFalse);
3056 (void) CopyMagickString(image_info->filename,component,
3058 image_info->temporary=MagickTrue;
3060 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3061 if (magick == (
unsigned char *) NULL)
3063 (void) CloseBlob(image);
3064 image=DestroyImage(image);
3065 return(MagickFalse);
3067 (void) memset(magick,0,magick_size);
3068 count=ReadBlob(image,magick_size,magick);
3069 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3070 (void) CloseBlob(image);
3071 image=DestroyImage(image);
3075 sans_exception=AcquireExceptionInfo();
3076 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3077 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3078 if ((magic_info != (
const MagicInfo *) NULL) &&
3079 (GetMagicName(magic_info) != (
char *) NULL))
3084 if ((magick_info != (
const MagickInfo *) NULL) &&
3085 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3086 (LocaleCompare(magick_info->magick_module,GetMagicName(
3088 (
void) CopyMagickString(image_info->magick,magick_info->name,
3092 (void) CopyMagickString(image_info->magick,GetMagicName(
3093 magic_info),MagickPathExtent);
3094 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3096 if ((magick_info == (
const MagickInfo *) NULL) ||
3097 (GetMagickEndianSupport(magick_info) == MagickFalse))
3098 image_info->endian=UndefinedEndian;
3099 sans_exception=DestroyExceptionInfo(sans_exception);
3102 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);
3138MagickExport
void SetImageInfoBlob(
ImageInfo *image_info,
const void *blob,
3139 const size_t length)
3141 assert(image_info != (
ImageInfo *) NULL);
3142 assert(image_info->signature == MagickCoreSignature);
3143 if (IsEventLogging() != MagickFalse)
3144 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3145 image_info->filename);
3146 image_info->blob=(
void *) blob;
3147 image_info->length=length;
3175MagickExport
void SetImageInfoCustomStream(
ImageInfo *image_info,
3178 assert(image_info != (
ImageInfo *) NULL);
3179 assert(image_info->signature == MagickCoreSignature);
3180 if (IsEventLogging() != MagickFalse)
3181 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3182 image_info->filename);
3210MagickExport
void SetImageInfoFile(
ImageInfo *image_info,FILE *file)
3212 assert(image_info != (
ImageInfo *) NULL);
3213 assert(image_info->signature == MagickCoreSignature);
3214 if (IsEventLogging() != MagickFalse)
3215 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3216 image_info->filename);
3217 image_info->file=file;
3250MagickExport MagickBooleanType SetImageMask(
Image *image,
const PixelMask type,
3266 assert(image != (
Image *) NULL);
3267 if (IsEventLogging() != MagickFalse)
3268 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3269 assert(image->signature == MagickCoreSignature);
3270 if (mask == (
const Image *) NULL)
3276 image->channels=(ChannelType) ((
unsigned int) image->channels &
3277 (
unsigned int) ~ReadMaskChannel);
3280 case WritePixelMask:
3282 image->channels=(ChannelType) ((
unsigned int) image->channels &
3283 (
unsigned int) ~WriteMaskChannel);
3288 image->channels=(ChannelType) ((
unsigned int) image->channels &
3289 (
unsigned int) ~CompositeMaskChannel);
3293 return(SyncImagePixelCache(image,exception));
3299 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3302 case WritePixelMask:
3304 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3309 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3313 if (SyncImagePixelCache(image,exception) == MagickFalse)
3314 return(MagickFalse);
3316 image->mask_trait=UpdatePixelTrait;
3317 mask_view=AcquireVirtualCacheView(mask,exception);
3318 image_view=AcquireAuthenticCacheView(image,exception);
3319#if defined(MAGICKCORE_OPENMP_SUPPORT)
3320 #pragma omp parallel for schedule(static) shared(status) \
3321 magick_number_threads(mask,image,image->rows,2)
3323 for (y=0; y < (ssize_t) image->rows; y++)
3334 if (status == MagickFalse)
3336 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3337 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3338 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3343 for (x=0; x < (ssize_t) image->columns; x++)
3349 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3350 intensity=GetPixelIntensity(mask,p);
3355 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3358 case WritePixelMask:
3360 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3365 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3369 p+=(ptrdiff_t) GetPixelChannels(mask);
3370 q+=(ptrdiff_t) GetPixelChannels(image);
3372 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3375 image->mask_trait=UndefinedPixelTrait;
3376 mask_view=DestroyCacheView(mask_view);
3377 image_view=DestroyCacheView(image_view);
3411MagickExport MagickBooleanType SetImageRegionMask(
Image *image,
3426 assert(image != (
Image *) NULL);
3427 assert(image->signature == MagickCoreSignature);
3428 if (IsEventLogging() != MagickFalse)
3429 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3436 image->channels=(ChannelType) ((
unsigned int) image->channels &
3437 (
unsigned int) ~ReadMaskChannel);
3440 case WritePixelMask:
3442 image->channels=(ChannelType) ((
unsigned int) image->channels &
3443 (
unsigned int) ~WriteMaskChannel);
3448 image->channels=(ChannelType) ((
unsigned int) image->channels &
3449 (
unsigned int) ~CompositeMaskChannel);
3453 return(SyncImagePixelCache(image,exception));
3459 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3462 case WritePixelMask:
3464 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3469 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3473 if (SyncImagePixelCache(image,exception) == MagickFalse)
3474 return(MagickFalse);
3476 image->mask_trait=UpdatePixelTrait;
3477 image_view=AcquireAuthenticCacheView(image,exception);
3478#if defined(MAGICKCORE_OPENMP_SUPPORT)
3479 #pragma omp parallel for schedule(static) shared(status) \
3480 magick_number_threads(image,image,image->rows,2)
3482 for (y=0; y < (ssize_t) image->rows; y++)
3490 if (status == MagickFalse)
3492 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3493 if (q == (Quantum *) NULL)
3498 for (x=0; x < (ssize_t) image->columns; x++)
3504 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3505 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3511 SetPixelReadMask(image,pixel,q);
3514 case WritePixelMask:
3516 SetPixelWriteMask(image,pixel,q);
3521 SetPixelCompositeMask(image,pixel,q);
3525 q+=(ptrdiff_t) GetPixelChannels(image);
3527 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3530 image->mask_trait=UndefinedPixelTrait;
3531 image_view=DestroyCacheView(image_view);
3564MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(
Image *image,
3565 const VirtualPixelMethod virtual_pixel_method,
ExceptionInfo *exception)
3567 assert(image != (
const Image *) NULL);
3568 assert(image->signature == MagickCoreSignature);
3569 if (IsEventLogging() != MagickFalse)
3570 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3571 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3609static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3637 if (images->previous == (
Image *) NULL)
3640 SetGeometry(smush_image,&right_geometry);
3641 GravityAdjustGeometry(right_image->columns,right_image->rows,
3642 right_image->gravity,&right_geometry);
3643 left_image=images->previous;
3644 SetGeometry(smush_image,&left_geometry);
3645 GravityAdjustGeometry(left_image->columns,left_image->rows,
3646 left_image->gravity,&left_geometry);
3647 gap=right_image->columns;
3648 left_view=AcquireVirtualCacheView(left_image,exception);
3649 right_view=AcquireVirtualCacheView(right_image,exception);
3650 for (y=0; y < (ssize_t) smush_image->rows; y++)
3652 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3654 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3655 if ((p == (
const Quantum *) NULL) ||
3656 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3657 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3660 i=(ssize_t) left_image->columns-x-1;
3661 for (x=0; x < (ssize_t) right_image->columns; x++)
3663 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3665 if ((p == (
const Quantum *) NULL) ||
3666 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3667 ((x+i) >= (ssize_t) gap))
3670 if ((x+i) < (ssize_t) gap)
3673 right_view=DestroyCacheView(right_view);
3674 left_view=DestroyCacheView(left_view);
3675 if (y < (ssize_t) smush_image->rows)
3677 return((ssize_t) gap-offset);
3680static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3708 if (images->previous == (
Image *) NULL)
3710 bottom_image=images;
3711 SetGeometry(smush_image,&bottom_geometry);
3712 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3713 bottom_image->gravity,&bottom_geometry);
3714 top_image=images->previous;
3715 SetGeometry(smush_image,&top_geometry);
3716 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3718 gap=bottom_image->rows;
3719 top_view=AcquireVirtualCacheView(top_image,exception);
3720 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3721 for (x=0; x < (ssize_t) smush_image->columns; x++)
3723 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3725 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3726 if ((p == (
const Quantum *) NULL) ||
3727 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3728 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3731 i=(ssize_t) top_image->rows-y-1;
3732 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3734 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3736 if ((p == (
const Quantum *) NULL) ||
3737 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3738 ((y+i) >= (ssize_t) gap))
3741 if ((y+i) < (ssize_t) gap)
3744 bottom_view=DestroyCacheView(bottom_view);
3745 top_view=DestroyCacheView(top_view);
3746 if (x < (ssize_t) smush_image->columns)
3748 return((ssize_t) gap-offset);
3751MagickExport
Image *SmushImages(
const Image *images,
3752 const MagickBooleanType stack,
const ssize_t offset,
ExceptionInfo *exception)
3754#define SmushImageTag "Smush/Image"
3790 assert(images != (
Image *) NULL);
3791 assert(images->signature == MagickCoreSignature);
3793 assert(exception->signature == MagickCoreSignature);
3794 if (IsEventLogging() != MagickFalse)
3795 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3797 alpha_trait=image->alpha_trait;
3799 width=image->columns;
3801 next=GetNextImageInList(image);
3802 for ( ; next != (
Image *) NULL; next=GetNextImageInList(next))
3804 if (next->alpha_trait != UndefinedPixelTrait)
3805 alpha_trait=BlendPixelTrait;
3807 if (stack != MagickFalse)
3809 if (next->columns > width)
3810 width=next->columns;
3812 if (next->previous != (
Image *) NULL)
3813 height=(
size_t) MagickMax((ssize_t) height+offset,0U);
3816 width+=next->columns;
3817 if (next->previous != (
Image *) NULL)
3818 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3819 if (next->rows > height)
3825 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3826 if (smush_image == (
Image *) NULL)
3827 return((
Image *) NULL);
3828 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3830 smush_image=DestroyImage(smush_image);
3831 return((
Image *) NULL);
3833 smush_image->alpha_trait=alpha_trait;
3834 (void) SetImageBackgroundColor(smush_image,exception);
3838 for (n=0; n < (MagickOffsetType) number_images; n++)
3840 SetGeometry(smush_image,&geometry);
3841 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3842 if (stack != MagickFalse)
3844 x_offset-=geometry.x;
3845 y_offset-=SmushYGap(smush_image,image,offset,exception);
3849 x_offset-=SmushXGap(smush_image,image,offset,exception);
3850 y_offset-=geometry.y;
3852 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3853 y_offset,exception);
3854 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3855 if (proceed == MagickFalse)
3857 if (stack == MagickFalse)
3859 x_offset+=(ssize_t) image->columns;
3865 y_offset+=(ssize_t) image->rows;
3867 image=GetNextImageInList(image);
3869 if (stack == MagickFalse)
3870 smush_image->columns=(size_t) x_offset;
3872 smush_image->rows=(size_t) y_offset;
3873 if (status == MagickFalse)
3874 smush_image=DestroyImage(smush_image);
3875 return(smush_image);
3902MagickExport MagickBooleanType StripImage(
Image *image,
3908 magick_unreferenced(exception);
3909 assert(image != (
Image *) NULL);
3910 if (IsEventLogging() != MagickFalse)
3911 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3912 DestroyImageProfiles(image);
3913 (void) DeleteImageProperty(image,
"comment");
3914 (void) DeleteImageProperty(image,
"date:create");
3915 (void) DeleteImageProperty(image,
"date:modify");
3916 (void) DeleteImageProperty(image,
"date:timestamp");
3917 status=SetImageArtifact(image,
"png:exclude-chunk",
3918 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3948static inline Quantum PushColormapIndex(
Image *image,
const Quantum index,
3949 MagickBooleanType *range_exception)
3951 if ((
size_t) index < image->colors)
3953 *range_exception=MagickTrue;
3954 return((Quantum) 0);
3970 assert(image != (
Image *) NULL);
3971 assert(image->signature == MagickCoreSignature);
3972 if (IsEventLogging() != MagickFalse)
3973 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3974 if (image->ping != MagickFalse)
3976 if (image->storage_class != PseudoClass)
3977 return(MagickFalse);
3978 assert(image->colormap != (
PixelInfo *) NULL);
3979 range_exception=MagickFalse;
3982 image_view=AcquireAuthenticCacheView(image,exception);
3983#if defined(MAGICKCORE_OPENMP_SUPPORT)
3984 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3985 magick_number_threads(image,image,image->rows,2)
3987 for (y=0; y < (ssize_t) image->rows; y++)
3998 if (status == MagickFalse)
4000 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4001 if (q == (Quantum *) NULL)
4006 for (x=0; x < (ssize_t) image->columns; x++)
4008 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4009 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4010 q+=(ptrdiff_t) GetPixelChannels(image);
4012 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4015 image_view=DestroyCacheView(image_view);
4017 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4018 (void) ThrowMagickException(exception,GetMagickModule(),
4019 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4060MagickExport MagickBooleanType SyncImagesSettings(
ImageInfo *image_info,
4066 assert(image_info != (
const ImageInfo *) NULL);
4067 assert(image_info->signature == MagickCoreSignature);
4068 assert(images != (
Image *) NULL);
4069 assert(images->signature == MagickCoreSignature);
4070 if (IsEventLogging() != MagickFalse)
4071 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4073 for ( ; image != (
Image *) NULL; image=GetNextImageInList(image))
4074 (
void) SyncImageSettings(image_info,image,exception);
4075 (void) DeleteImageOption(image_info,
"page");
4079MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4097 assert(image_info != (
const ImageInfo *) NULL);
4098 assert(image_info->signature == MagickCoreSignature);
4099 assert(image != (
Image *) NULL);
4100 assert(image->signature == MagickCoreSignature);
4101 if (IsEventLogging() != MagickFalse)
4102 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4103 option=GetImageOption(image_info,
"background");
4104 if (option != (
const char *) NULL)
4105 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4107 option=GetImageOption(image_info,
"black-point-compensation");
4108 if (option != (
const char *) NULL)
4109 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4110 MagickBooleanOptions,MagickFalse,option);
4111 option=GetImageOption(image_info,
"blue-primary");
4112 if (option != (
const char *) NULL)
4114 flags=ParseGeometry(option,&geometry_info);
4115 if ((flags & RhoValue) != 0)
4116 image->chromaticity.blue_primary.x=geometry_info.rho;
4117 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4118 if ((flags & SigmaValue) != 0)
4119 image->chromaticity.blue_primary.y=geometry_info.sigma;
4121 option=GetImageOption(image_info,
"bordercolor");
4122 if (option != (
const char *) NULL)
4123 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4126 option=GetImageOption(image_info,
"compose");
4127 if (option != (
const char *) NULL)
4128 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4129 MagickFalse,option);
4131 option=GetImageOption(image_info,
"compress");
4132 if (option != (
const char *) NULL)
4133 image->compression=(CompressionType) ParseCommandOption(
4134 MagickCompressOptions,MagickFalse,option);
4135 option=GetImageOption(image_info,
"debug");
4136 if (option != (
const char *) NULL)
4137 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4138 MagickFalse,option);
4139 option=GetImageOption(image_info,
"density");
4140 if (option != (
const char *) NULL)
4142 flags=ParseGeometry(option,&geometry_info);
4143 if ((flags & RhoValue) != 0)
4144 image->resolution.x=geometry_info.rho;
4145 image->resolution.y=image->resolution.x;
4146 if ((flags & SigmaValue) != 0)
4147 image->resolution.y=geometry_info.sigma;
4149 option=GetImageOption(image_info,
"depth");
4150 if (option != (
const char *) NULL)
4151 image->depth=StringToUnsignedLong(option);
4152 option=GetImageOption(image_info,
"endian");
4153 if (option != (
const char *) NULL)
4154 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4155 MagickFalse,option);
4156 option=GetImageOption(image_info,
"filter");
4157 if (option != (
const char *) NULL)
4158 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4159 MagickFalse,option);
4160 option=GetImageOption(image_info,
"fuzz");
4161 if (option != (
const char *) NULL)
4162 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4163 option=GetImageOption(image_info,
"gravity");
4164 if (option != (
const char *) NULL)
4165 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4166 MagickFalse,option);
4167 option=GetImageOption(image_info,
"green-primary");
4168 if (option != (
const char *) NULL)
4170 flags=ParseGeometry(option,&geometry_info);
4171 if ((flags & RhoValue) != 0)
4172 image->chromaticity.green_primary.x=geometry_info.rho;
4173 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4174 if ((flags & SigmaValue) != 0)
4175 image->chromaticity.green_primary.y=geometry_info.sigma;
4177 option=GetImageOption(image_info,
"intent");
4178 if (option != (
const char *) NULL)
4179 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4180 MagickIntentOptions,MagickFalse,option);
4181 option=GetImageOption(image_info,
"intensity");
4182 if (option != (
const char *) NULL)
4183 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4184 MagickPixelIntensityOptions,MagickFalse,option);
4185 option=GetImageOption(image_info,
"interlace");
4186 if (option != (
const char *) NULL)
4187 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4188 MagickFalse,option);
4189 option=GetImageOption(image_info,
"interpolate");
4190 if (option != (
const char *) NULL)
4191 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4192 MagickInterpolateOptions,MagickFalse,option);
4193 option=GetImageOption(image_info,
"loop");
4194 if (option != (
const char *) NULL)
4195 image->iterations=StringToUnsignedLong(option);
4196 option=GetImageOption(image_info,
"mattecolor");
4197 if (option != (
const char *) NULL)
4198 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4200 option=GetImageOption(image_info,
"orient");
4201 if (option != (
const char *) NULL)
4202 image->orientation=(OrientationType) ParseCommandOption(
4203 MagickOrientationOptions,MagickFalse,option);
4204 option=GetImageOption(image_info,
"page");
4205 if (option != (
const char *) NULL)
4210 geometry=GetPageGeometry(option);
4211 flags=ParseAbsoluteGeometry(geometry,&image->page);
4212 geometry=DestroyString(geometry);
4214 option=GetImageOption(image_info,
"quality");
4215 if (option != (
const char *) NULL)
4216 image->quality=StringToUnsignedLong(option);
4217 option=GetImageOption(image_info,
"red-primary");
4218 if (option != (
const char *) NULL)
4220 flags=ParseGeometry(option,&geometry_info);
4221 if ((flags & RhoValue) != 0)
4222 image->chromaticity.red_primary.x=geometry_info.rho;
4223 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4224 if ((flags & SigmaValue) != 0)
4225 image->chromaticity.red_primary.y=geometry_info.sigma;
4227 if (image_info->quality != UndefinedCompressionQuality)
4228 image->quality=image_info->quality;
4229 option=GetImageOption(image_info,
"scene");
4230 if (option != (
const char *) NULL)
4231 image->scene=StringToUnsignedLong(option);
4232 option=GetImageOption(image_info,
"taint");
4233 if (option != (
const char *) NULL)
4234 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4235 MagickFalse,option);
4236 option=GetImageOption(image_info,
"tile-offset");
4237 if (option != (
const char *) NULL)
4242 geometry=GetPageGeometry(option);
4243 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4244 geometry=DestroyString(geometry);
4246 option=GetImageOption(image_info,
"transparent-color");
4247 if (option != (
const char *) NULL)
4248 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4250 option=GetImageOption(image_info,
"type");
4251 if (option != (
const char *) NULL)
4252 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4254 option=GetImageOption(image_info,
"units");
4255 units=image_info->units;
4256 if (option != (
const char *) NULL)
4257 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4258 MagickFalse,option);
4259 if (units != UndefinedResolution)
4261 if (image->units != units)
4262 switch (image->units)
4264 case PixelsPerInchResolution:
4266 if (units == PixelsPerCentimeterResolution)
4268 image->resolution.x/=2.54;
4269 image->resolution.y/=2.54;
4273 case PixelsPerCentimeterResolution:
4275 if (units == PixelsPerInchResolution)
4277 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4278 image->resolution.x+0.5))/100.0;
4279 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4280 image->resolution.y+0.5))/100.0;
4288 option=GetImageOption(image_info,
"density");
4289 if (option != (
const char *) NULL)
4291 flags=ParseGeometry(option,&geometry_info);
4292 if ((flags & RhoValue) != 0)
4293 image->resolution.x=geometry_info.rho;
4294 image->resolution.y=image->resolution.x;
4295 if ((flags & SigmaValue) != 0)
4296 image->resolution.y=geometry_info.sigma;
4299 option=GetImageOption(image_info,
"virtual-pixel");
4300 if (option != (
const char *) NULL)
4301 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4302 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4304 option=GetImageOption(image_info,
"white-point");
4305 if (option != (
const char *) NULL)
4307 flags=ParseGeometry(option,&geometry_info);
4308 if ((flags & RhoValue) != 0)
4309 image->chromaticity.white_point.x=geometry_info.rho;
4310 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4311 if ((flags & SigmaValue) != 0)
4312 image->chromaticity.white_point.y=geometry_info.sigma;
4320 if (image->image_info != (
ImageInfo *) NULL)
4321 image->image_info=DestroyImageInfo(image->image_info);
4322 image->image_info=CloneImageInfo(image_info);