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->debug=image_info->debug;
1016 clone_info->signature=image_info->signature;
1053MagickExport MagickBooleanType CopyImagePixels(
Image *image,
1057#define CopyImageTag "Copy/Image"
1072 assert(image != (
Image *) NULL);
1073 assert(source_image != (
Image *) NULL);
1076 if (IsEventLogging() != MagickFalse)
1077 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1078 if ((offset->x < 0) || (offset->y < 0) ||
1079 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1080 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1081 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1083 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1084 return(MagickFalse);
1090 source_view=AcquireVirtualCacheView(source_image,exception);
1091 image_view=AcquireAuthenticCacheView(image,exception);
1092#if defined(MAGICKCORE_OPENMP_SUPPORT)
1093 #pragma omp parallel for schedule(static) shared(progress,status) \
1094 magick_number_threads(image,source_image,geometry->height,2)
1096 for (y=0; y < (ssize_t) geometry->height; y++)
1110 if (status == MagickFalse)
1112 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1113 geometry->width,1,exception);
1114 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1115 geometry->width,1,exception);
1116 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1121 for (x=0; x < (ssize_t) geometry->width; x++)
1126 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1128 PixelChannel channel = GetPixelChannelChannel(image,i);
1129 PixelTrait traits = GetPixelChannelTraits(image,channel);
1130 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1131 if ((traits == UndefinedPixelTrait) ||
1132 ((traits & UpdatePixelTrait) == 0) ||
1133 (source_traits == UndefinedPixelTrait))
1135 SetPixelChannel(image,channel,p[i],q);
1137 p+=(ptrdiff_t) GetPixelChannels(source_image);
1138 q+=(ptrdiff_t) GetPixelChannels(image);
1140 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1141 if (sync == MagickFalse)
1143 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1148#if defined(MAGICKCORE_OPENMP_SUPPORT)
1152 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1153 if (proceed == MagickFalse)
1157 source_view=DestroyCacheView(source_view);
1158 image_view=DestroyCacheView(image_view);
1185MagickExport
Image *DestroyImage(
Image *image)
1193 assert(image != (
Image *) NULL);
1194 assert(image->signature == MagickCoreSignature);
1195 if (IsEventLogging() != MagickFalse)
1196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1197 destroy=MagickFalse;
1198 LockSemaphoreInfo(image->semaphore);
1199 image->reference_count--;
1200 if (image->reference_count == 0)
1202 UnlockSemaphoreInfo(image->semaphore);
1203 if (destroy == MagickFalse)
1204 return((
Image *) NULL);
1208 DestroyImagePixels(image);
1209 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1210 if (image->montage != (
char *) NULL)
1211 image->montage=DestroyString(image->montage);
1212 if (image->directory != (
char *) NULL)
1213 image->directory=DestroyString(image->directory);
1214 if (image->colormap != (
PixelInfo *) NULL)
1215 image->colormap=(
PixelInfo *) RelinquishMagickMemory(image->colormap);
1216 if (image->geometry != (
char *) NULL)
1217 image->geometry=DestroyString(image->geometry);
1218 DestroyImageProfiles(image);
1219 DestroyImageProperties(image);
1220 DestroyImageArtifacts(image);
1222 image->ascii85=(
Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1223 if (image->image_info != (
ImageInfo *) NULL)
1224 image->image_info=DestroyImageInfo(image->image_info);
1227 RelinquishSemaphoreInfo(&image->semaphore);
1228 image->signature=(~MagickCoreSignature);
1229 image=(
Image *) RelinquishMagickMemory(image);
1258 assert(image_info != (
ImageInfo *) NULL);
1259 assert(image_info->signature == MagickCoreSignature);
1260 if (IsEventLogging() != MagickFalse)
1261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1262 image_info->filename);
1263 if (image_info->size != (
char *) NULL)
1264 image_info->size=DestroyString(image_info->size);
1265 if (image_info->extract != (
char *) NULL)
1266 image_info->extract=DestroyString(image_info->extract);
1267 if (image_info->scenes != (
char *) NULL)
1268 image_info->scenes=DestroyString(image_info->scenes);
1269 if (image_info->page != (
char *) NULL)
1270 image_info->page=DestroyString(image_info->page);
1271 if (image_info->sampling_factor != (
char *) NULL)
1272 image_info->sampling_factor=DestroyString(
1273 image_info->sampling_factor);
1274 if (image_info->server_name != (
char *) NULL)
1275 image_info->server_name=DestroyString(
1276 image_info->server_name);
1277 if (image_info->font != (
char *) NULL)
1278 image_info->font=DestroyString(image_info->font);
1279 if (image_info->texture != (
char *) NULL)
1280 image_info->texture=DestroyString(image_info->texture);
1281 if (image_info->density != (
char *) NULL)
1282 image_info->density=DestroyString(image_info->density);
1283 if (image_info->cache != (
void *) NULL)
1284 image_info->cache=DestroyPixelCache(image_info->cache);
1285 if (image_info->profile != (
StringInfo *) NULL)
1286 image_info->profile=(
void *) DestroyStringInfo((
StringInfo *)
1287 image_info->profile);
1288 DestroyImageOptions(image_info);
1289 image_info->signature=(~MagickCoreSignature);
1290 image_info=(
ImageInfo *) RelinquishMagickMemory(image_info);
1318MagickExport
void DisassociateImageStream(
Image *image)
1320 assert(image != (
Image *) NULL);
1321 assert(image->signature == MagickCoreSignature);
1322 if (IsEventLogging() != MagickFalse)
1323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1324 DisassociateBlob(image);
1349MagickExport
void GetImageInfo(
ImageInfo *image_info)
1357 assert(image_info != (
ImageInfo *) NULL);
1358 if (IsEventLogging() != MagickFalse)
1359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1360 (void) memset(image_info,0,
sizeof(*image_info));
1361 image_info->adjoin=MagickTrue;
1362 image_info->interlace=NoInterlace;
1363 image_info->channel=AllChannels;
1364 image_info->quality=UndefinedCompressionQuality;
1365 image_info->antialias=MagickTrue;
1366 image_info->dither=MagickTrue;
1367 image_info->depth=0;
1368 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1369 if (synchronize != (
const char *) NULL)
1371 image_info->synchronize=IsStringTrue(synchronize);
1372 synchronize=DestroyString(synchronize);
1374 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1375 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1376 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1377 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1378 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1380 image_info->signature=MagickCoreSignature;
1405MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1407 return(image_info->file);
1435MagickExport
Image *GetImageMask(
const Image *image,
const PixelMask type,
1454 assert(image != (
Image *) NULL);
1455 assert(image->signature == MagickCoreSignature);
1456 if (IsEventLogging() != MagickFalse)
1457 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1462 if ((image->channels & ReadMaskChannel) == 0)
1463 return((
Image *) NULL);
1466 case WritePixelMask:
1468 if ((image->channels & WriteMaskChannel) == 0)
1469 return((
Image *) NULL);
1474 if ((image->channels & CompositeMaskChannel) == 0)
1475 return((
Image *) NULL);
1479 mask_image=AcquireImage((
ImageInfo *) NULL,exception);
1480 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1481 if (status == MagickFalse)
1482 return(DestroyImage(mask_image));
1484 mask_image->alpha_trait=UndefinedPixelTrait;
1485 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1486 image_view=AcquireVirtualCacheView(image,exception);
1487 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1488#if defined(MAGICKCORE_OPENMP_SUPPORT)
1489 #pragma omp parallel for schedule(static) shared(status) \
1490 magick_number_threads(image,image,image->rows,2)
1492 for (y=0; y < (ssize_t) image->rows; y++)
1503 if (status == MagickFalse)
1505 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1506 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1508 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1513 for (x=0; x < (ssize_t) image->columns; x++)
1519 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1522 case WritePixelMask:
1524 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1529 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1533 p+=(ptrdiff_t) GetPixelChannels(image);
1534 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1536 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1539 mask_view=DestroyCacheView(mask_view);
1540 image_view=DestroyCacheView(image_view);
1541 if (status == MagickFalse)
1542 mask_image=DestroyImage(mask_image);
1568MagickExport ssize_t GetImageReferenceCount(
Image *image)
1573 assert(image != (
Image *) NULL);
1574 assert(image->signature == MagickCoreSignature);
1575 if (IsEventLogging() != MagickFalse)
1576 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1577 LockSemaphoreInfo(image->semaphore);
1578 reference_count=image->reference_count;
1579 UnlockSemaphoreInfo(image->semaphore);
1580 return(reference_count);
1607MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1609 assert(image != (
Image *) NULL);
1610 assert(image->signature == MagickCoreSignature);
1611 if (IsEventLogging() != MagickFalse)
1612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1613 return(GetPixelCacheVirtualMethod(image));
1651MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1652 Image *image,
const char *format,
int value,
char *filename,
1671 canonical=MagickFalse;
1673 (void) CopyMagickString(filename,format,MagickPathExtent);
1674 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1675 return(strlen(filename));
1676 for (p=strchr(format,
'%'); p != (
char *) NULL; p=strchr(p+1,
'%'))
1686 field_width=(ssize_t) strtol(q,&q,10);
1696 (void) FormatLocaleString(filename+(p-format-offset),(
size_t)
1697 (MagickPathExtent-(p-format-offset)),p,value);
1698 offset+=(4-field_width);
1700 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1701 canonical=MagickTrue;
1710 pattern[MagickPathExtent];
1727 if (strchr(p,
']') == (
char *) NULL)
1731 for (i=0; (i < (MagickPathExtent-1L)) && (*r !=
'\0'); i++)
1742 if (LocaleNCompare(pattern,
"filename:",9) != 0)
1744 option=(
const char *) NULL;
1745 if (image != (
Image *) NULL)
1746 option=GetImageProperty(image,pattern,exception);
1747 if ((option == (
const char *) NULL) && (image != (
Image *) NULL))
1748 option=GetImageArtifact(image,pattern);
1749 if ((option == (
const char *) NULL) &&
1751 option=GetImageOption(image_info,pattern);
1752 if (option == (
const char *) NULL)
1757 (void) CopyMagickString(filename+(p-format-offset),option,(
size_t)
1758 (MagickPathExtent-(p-format-offset)));
1759 offset+=(ssize_t) strlen(pattern)-(ssize_t) strlen(option)+3;
1761 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1762 canonical=MagickTrue;
1772 if (canonical == MagickFalse)
1773 (void) CopyMagickString(filename,format,MagickPathExtent);
1775 for (q=filename; *q !=
'\0'; q++)
1776 if ((*q ==
'%') && (*(q+1) ==
'%'))
1777 (void) CopyMagickString(q,q+1,(
size_t) (MagickPathExtent-(q-filename)));
1778 return(strlen(filename));
1808MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1811#if !defined(MAGICKCORE_HDRI_SUPPORT)
1814 return(MagickFalse);
1825 assert(image != (
Image *) NULL);
1826 assert(image->signature == MagickCoreSignature);
1827 if (IsEventLogging() != MagickFalse)
1828 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1829 image_view=AcquireVirtualCacheView(image,exception);
1830#if defined(MAGICKCORE_OPENMP_SUPPORT)
1831 #pragma omp parallel for schedule(static) shared(hdri) \
1832 magick_number_threads(image,image,image->rows,2)
1834 for (y=0; y < (ssize_t) image->rows; y++)
1842 if (hdri != MagickFalse)
1844 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1845 if (p == (
const Quantum *) NULL)
1847 for (x=0; x < (ssize_t) image->columns; x++)
1852 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1860 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1861 if (traits == UndefinedPixelTrait)
1863 pixel=(double) p[i];
1864 if ((pixel < 0.0) || (pixel > (
double) QuantumRange) ||
1865 (pixel != (
double) ((QuantumAny) pixel)))
1871 if (hdri != MagickFalse)
1873 p+=(ptrdiff_t) GetPixelChannels(image);
1876 image_view=DestroyCacheView(image_view);
1904MagickExport MagickBooleanType IsImageObject(
const Image *image)
1909 assert(image != (
Image *) NULL);
1910 if (IsEventLogging() != MagickFalse)
1911 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1912 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1913 if (p->signature != MagickCoreSignature)
1914 return(MagickFalse);
1941MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1944 magick[MagickPathExtent],
1945 filename[MagickPathExtent];
1950 assert(image != (
Image *) NULL);
1951 assert(image->signature == MagickCoreSignature);
1952 if (IsEventLogging() != MagickFalse)
1953 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1954 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1955 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1956 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1958 if (p->taint != MagickFalse)
1960 if (LocaleCompare(p->magick,magick) != 0)
1962 if (LocaleCompare(p->filename,filename) != 0)
1965 return(MagickFalse);
1994MagickExport MagickBooleanType ModifyImage(
Image **image,
2000 assert(image != (
Image **) NULL);
2001 assert(*image != (
Image *) NULL);
2002 assert((*image)->signature == MagickCoreSignature);
2003 if (IsEventLogging() != MagickFalse)
2004 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2005 if (GetImageReferenceCount(*image) <= 1)
2007 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2008 LockSemaphoreInfo((*image)->semaphore);
2009 (*image)->reference_count--;
2010 UnlockSemaphoreInfo((*image)->semaphore);
2049 const size_t width,
const size_t height,
const PixelInfo *background,
2064 assert(image_info != (
const ImageInfo *) NULL);
2065 assert(image_info->signature == MagickCoreSignature);
2066 assert(background != (
const PixelInfo *) NULL);
2067 if (IsEventLogging() != MagickFalse)
2068 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2069 image=AcquireImage(image_info,exception);
2070 image->columns=width;
2072 image->colorspace=background->colorspace;
2073 image->alpha_trait=background->alpha_trait;
2074 image->fuzz=background->fuzz;
2075 image->depth=background->depth;
2077 image_view=AcquireAuthenticCacheView(image,exception);
2078#if defined(MAGICKCORE_OPENMP_SUPPORT)
2079 #pragma omp parallel for schedule(static) shared(status) \
2080 magick_number_threads(image,image,image->rows,2)
2082 for (y=0; y < (ssize_t) image->rows; y++)
2090 if (status == MagickFalse)
2092 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2093 if (q == (Quantum *) NULL)
2098 for (x=0; x < (ssize_t) image->columns; x++)
2100 SetPixelViaPixelInfo(image,background,q);
2101 q+=(ptrdiff_t) GetPixelChannels(image);
2103 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2106 image_view=DestroyCacheView(image_view);
2107 if (status == MagickFalse)
2108 image=DestroyImage(image);
2135MagickExport
Image *ReferenceImage(
Image *image)
2137 assert(image != (
Image *) NULL);
2138 assert(image->signature == MagickCoreSignature);
2139 if (IsEventLogging() != MagickFalse)
2140 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2141 LockSemaphoreInfo(image->semaphore);
2142 image->reference_count++;
2143 UnlockSemaphoreInfo(image->semaphore);
2171MagickExport MagickBooleanType ResetImagePage(
Image *image,
const char *page)
2179 assert(image != (
Image *) NULL);
2180 assert(image->signature == MagickCoreSignature);
2181 if (IsEventLogging() != MagickFalse)
2182 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2183 flags=ParseAbsoluteGeometry(page,&geometry);
2184 if ((flags & WidthValue) != 0)
2186 if ((flags & HeightValue) == 0)
2187 geometry.height=geometry.width;
2188 image->page.width=geometry.width;
2189 image->page.height=geometry.height;
2191 if ((flags & AspectValue) != 0)
2193 if ((flags & XValue) != 0)
2194 image->page.x+=geometry.x;
2195 if ((flags & YValue) != 0)
2196 image->page.y+=geometry.y;
2200 if ((flags & XValue) != 0)
2202 image->page.x=geometry.x;
2203 if ((image->page.width == 0) && (geometry.x > 0))
2204 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2206 if ((flags & YValue) != 0)
2208 image->page.y=geometry.y;
2209 if ((image->page.height == 0) && (geometry.y > 0))
2210 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2242MagickExport MagickBooleanType ResetImagePixels(
Image *image,
2260 assert(image != (
Image *) NULL);
2261 assert(image->signature == MagickCoreSignature);
2262 if (IsEventLogging() != MagickFalse)
2263 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2264 pixels=AcquirePixelCachePixels(image,&length,exception);
2265 if (pixels != (
void *) NULL)
2270 (void) memset(pixels,0,length);
2277 image_view=AcquireAuthenticCacheView(image,exception);
2278#if defined(MAGICKCORE_OPENMP_SUPPORT)
2279 #pragma omp parallel for schedule(static) shared(status) \
2280 magick_number_threads(image,image,image->rows,2)
2282 for (y=0; y < (ssize_t) image->rows; y++)
2290 if (status == MagickFalse)
2292 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2293 if (q == (Quantum *) NULL)
2298 for (x=0; x < (ssize_t) image->columns; x++)
2300 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2301 q+=(ptrdiff_t) GetPixelChannels(image);
2303 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2306 image_view=DestroyCacheView(image_view);
2338MagickExport MagickBooleanType SetImageAlpha(
Image *image,
const Quantum alpha,
2350 assert(image != (
Image *) NULL);
2351 assert(image->signature == MagickCoreSignature);
2352 if (IsEventLogging() != MagickFalse)
2353 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2354 image->alpha_trait=BlendPixelTrait;
2356 image_view=AcquireAuthenticCacheView(image,exception);
2357#if defined(MAGICKCORE_OPENMP_SUPPORT)
2358 #pragma omp parallel for schedule(static) shared(status) \
2359 magick_number_threads(image,image,image->rows,2)
2361 for (y=0; y < (ssize_t) image->rows; y++)
2369 if (status == MagickFalse)
2371 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2372 if (q == (Quantum *) NULL)
2377 for (x=0; x < (ssize_t) image->columns; x++)
2379 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2380 SetPixelAlpha(image,alpha,q);
2381 q+=(ptrdiff_t) GetPixelChannels(image);
2383 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2386 image_view=DestroyCacheView(image_view);
2417MagickExport MagickBooleanType SetImageBackgroundColor(
Image *image,
2432 assert(image != (
Image *) NULL);
2433 assert(image->signature == MagickCoreSignature);
2434 if (IsEventLogging() != MagickFalse)
2435 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2436 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2437 return(MagickFalse);
2438 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2439 ((image->alpha_trait & BlendPixelTrait) == 0))
2440 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2441 ConformPixelInfo(image,&image->background_color,&background,exception);
2446 image_view=AcquireAuthenticCacheView(image,exception);
2447#if defined(MAGICKCORE_OPENMP_SUPPORT)
2448 #pragma omp parallel for schedule(static) shared(status) \
2449 magick_number_threads(image,image,image->rows,2)
2451 for (y=0; y < (ssize_t) image->rows; y++)
2459 if (status == MagickFalse)
2461 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2462 if (q == (Quantum *) NULL)
2467 for (x=0; x < (ssize_t) image->columns; x++)
2469 SetPixelViaPixelInfo(image,&background,q);
2470 q+=(ptrdiff_t) GetPixelChannels(image);
2472 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2475 image_view=DestroyCacheView(image_view);
2505MagickExport ChannelType SetImageChannelMask(
Image *image,
2506 const ChannelType channel_mask)
2508 return(SetPixelChannelMask(image,channel_mask));
2538MagickExport MagickBooleanType SetImageColor(
Image *image,
2550 assert(image != (
Image *) NULL);
2551 assert(image->signature == MagickCoreSignature);
2552 assert(color != (
const PixelInfo *) NULL);
2553 if (IsEventLogging() != MagickFalse)
2554 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2555 image->colorspace=color->colorspace;
2556 image->alpha_trait=color->alpha_trait;
2557 image->fuzz=color->fuzz;
2558 image->depth=color->depth;
2560 image_view=AcquireAuthenticCacheView(image,exception);
2561#if defined(MAGICKCORE_OPENMP_SUPPORT)
2562 #pragma omp parallel for schedule(static) shared(status) \
2563 magick_number_threads(image,image,image->rows,2)
2565 for (y=0; y < (ssize_t) image->rows; y++)
2573 if (status == MagickFalse)
2575 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2576 if (q == (Quantum *) NULL)
2581 for (x=0; x < (ssize_t) image->columns; x++)
2583 SetPixelViaPixelInfo(image,color,q);
2584 q+=(ptrdiff_t) GetPixelChannels(image);
2586 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2589 image_view=DestroyCacheView(image_view);
2621MagickExport MagickBooleanType SetImageStorageClass(
Image *image,
2624 assert(image != (
Image *) NULL);
2625 assert(image->signature == MagickCoreSignature);
2627 assert(exception->signature == MagickCoreSignature);
2628 if (IsEventLogging() != MagickFalse)
2629 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2630 image->storage_class=storage_class;
2631 return(SyncImagePixelCache(image,exception));
2663MagickExport MagickBooleanType SetImageExtent(
Image *image,
const size_t columns,
2666 if ((columns == 0) || (rows == 0))
2667 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2668 image->columns=columns;
2670 if (image->depth == 0)
2673 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2674 "ImageDepthNotSupported",
"`%s'",image->filename);
2676 if (image->depth > (8*
sizeof(MagickSizeType)))
2678 image->depth=8*
sizeof(MagickSizeType);
2679 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2680 "ImageDepthNotSupported",
"`%s'",image->filename);
2682 return(SyncImagePixelCache(image,exception));
2733 *format_type_formats[] =
2757 (void) CopyMagickString(magic,component,MagickPathExtent);
2762 format_type=UndefinedFormatType;
2763 magick_info=GetMagickInfo(magic,exception);
2764 if ((magick_info != (
const MagickInfo *) NULL) &&
2765 (magick_info->format_type != UndefinedFormatType))
2766 format_type=magick_info->format_type;
2768 while ((format_type == UndefinedFormatType) &&
2769 (format_type_formats[i] != (
char *) NULL))
2771 if ((*magic == *format_type_formats[i]) &&
2772 (LocaleCompare(magic,format_type_formats[i]) == 0))
2773 format_type=ExplicitFormatType;
2776 if (format_type == UndefinedFormatType)
2777 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2779 if (format_type == ExplicitFormatType)
2781 image_info->affirm=MagickTrue;
2782 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2784 if (LocaleCompare(magic,
"RGB") == 0)
2785 image_info->affirm=MagickFalse;
2786 return(magick_info);
2789MagickExport MagickBooleanType SetImageInfo(
ImageInfo *image_info,
2793 component[MagickPathExtent],
2794 magic[MagickPathExtent],
2795 path[MagickPathExtent],
2822 assert(image_info != (
ImageInfo *) NULL);
2823 assert(image_info->signature == MagickCoreSignature);
2824 if (IsEventLogging() != MagickFalse)
2825 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2826 image_info->filename);
2828 GetPathComponent(image_info->filename,SubimagePath,component);
2829 if (*component !=
'\0')
2834 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2836 if (IsGeometry(component) != MagickFalse)
2837 (void) CloneString(&image_info->extract,component);
2845 (void) CloneString(&image_info->scenes,component);
2846 image_info->scene=StringToUnsignedLong(image_info->scenes);
2847 image_info->number_scenes=image_info->scene;
2848 p=image_info->scenes;
2849 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2851 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2853 first=(size_t) strtol(p,&q,10);
2855 while (isspace((
int) ((
unsigned char) *q)) != 0)
2858 last=(size_t) strtol(q+1,&q,10);
2861 if (first < image_info->scene)
2862 image_info->scene=first;
2863 if (last > image_info->number_scenes)
2864 image_info->number_scenes=last;
2867 image_info->number_scenes-=image_info->scene-1;
2871 if (*image_info->magick ==
'\0')
2872 GetPathComponent(image_info->filename,ExtensionPath,component);
2873 if (*component !=
'\0')
2878 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2879 GetPathComponent(path,ExtensionPath,component);
2881 image_info->affirm=MagickFalse;
2882 sans_exception=AcquireExceptionInfo();
2883 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2884 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2890 GetPathComponent(image_info->filename,MagickPath,magic);
2893 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2894 magick_info=GetMagickInfo(magic,sans_exception);
2895 if ((magick_info != (
const MagickInfo *) NULL) &&
2896 (magick_info->format_type == ExplicitFormatType))
2897 image_info->affirm=MagickTrue;
2899 GetPathComponent(image_info->filename,CanonicalPath,component);
2901 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2902 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2913 magick_info=GetMagickInfo(magic,sans_exception);
2915 if (magick_info == (
const MagickInfo *) NULL)
2917 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2919 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2921 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2926 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2930 if (((magick_info != (
const MagickInfo *) NULL) ||
2932 (IsMagickConflict(magic) == MagickFalse))
2934 image_info->affirm=MagickTrue;
2935 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2936 GetPathComponent(image_info->filename,CanonicalPath,component);
2937 (void) CopyMagickString(image_info->filename,component,
2941 sans_exception=DestroyExceptionInfo(sans_exception);
2942 if ((magick_info == (
const MagickInfo *) NULL) ||
2943 (GetMagickEndianSupport(magick_info) == MagickFalse))
2944 image_info->endian=UndefinedEndian;
2945 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2950 (void) InterpretImageFilename(image_info,(
Image *) NULL,
2951 image_info->filename,(
int) image_info->scene,component,exception);
2952 if ((LocaleCompare(component,image_info->filename) != 0) &&
2953 (strchr(component,
'%') == (
char *) NULL))
2954 image_info->adjoin=MagickFalse;
2956 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2961 magick_info=GetMagickInfo(magic,exception);
2962 if (magick_info != (
const MagickInfo *) NULL)
2963 if (GetMagickAdjoin(magick_info) == MagickFalse)
2964 image_info->adjoin=MagickFalse;
2966 if (image_info->affirm != MagickFalse)
2979 magick_size=GetMagicPatternExtent(exception);
2980 if (magick_size == 0)
2981 return(MagickFalse);
2982 image=AcquireImage(image_info,exception);
2983 (void) CopyMagickString(image->filename,image_info->filename,
2985 sans_exception=AcquireExceptionInfo();
2986 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
2987 sans_exception=DestroyExceptionInfo(sans_exception);
2988 if (status == MagickFalse)
2990 image=DestroyImage(image);
2991 return(MagickFalse);
2993 if ((IsBlobSeekable(image) == MagickFalse) ||
2994 (IsBlobExempt(image) != MagickFalse))
3000 status=ImageToFile(image,component,exception);
3001 if (CloseBlob(image) == MagickFalse)
3003 if (status == MagickFalse)
3005 (void) RelinquishUniqueFileResource(component);
3006 image=DestroyImage(image);
3007 return(MagickFalse);
3009 SetImageInfoFile(image_info,(FILE *) NULL);
3010 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3011 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3012 if (status == MagickFalse)
3014 (void) RelinquishUniqueFileResource(component);
3015 image=DestroyImage(image);
3016 return(MagickFalse);
3018 (void) CopyMagickString(image_info->filename,component,
3020 image_info->temporary=MagickTrue;
3022 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3023 if (magick == (
unsigned char *) NULL)
3025 (void) CloseBlob(image);
3026 image=DestroyImage(image);
3027 return(MagickFalse);
3029 (void) memset(magick,0,magick_size);
3030 count=ReadBlob(image,magick_size,magick);
3031 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3032 (void) CloseBlob(image);
3033 image=DestroyImage(image);
3037 sans_exception=AcquireExceptionInfo();
3038 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3039 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3040 if ((magic_info != (
const MagicInfo *) NULL) &&
3041 (GetMagicName(magic_info) != (
char *) NULL))
3046 if ((magick_info != (
const MagickInfo *) NULL) &&
3047 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3048 (LocaleCompare(magick_info->magick_module,GetMagicName(
3050 (void) CopyMagickString(image_info->magick,magick_info->name,
3054 (void) CopyMagickString(image_info->magick,GetMagicName(
3055 magic_info),MagickPathExtent);
3056 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3058 if ((magick_info == (
const MagickInfo *) NULL) ||
3059 (GetMagickEndianSupport(magick_info) == MagickFalse))
3060 image_info->endian=UndefinedEndian;
3061 sans_exception=DestroyExceptionInfo(sans_exception);
3064 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3065 if ((magick_info == (
const MagickInfo *) NULL) ||
3066 (GetMagickEndianSupport(magick_info) == MagickFalse))
3067 image_info->endian=UndefinedEndian;
3068 sans_exception=DestroyExceptionInfo(sans_exception);
3100MagickExport
void SetImageInfoBlob(
ImageInfo *image_info,
const void *blob,
3101 const size_t length)
3103 assert(image_info != (
ImageInfo *) NULL);
3104 assert(image_info->signature == MagickCoreSignature);
3105 if (IsEventLogging() != MagickFalse)
3106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3107 image_info->filename);
3108 image_info->blob=(
void *) blob;
3109 image_info->length=length;
3137MagickExport
void SetImageInfoCustomStream(
ImageInfo *image_info,
3140 assert(image_info != (
ImageInfo *) NULL);
3141 assert(image_info->signature == MagickCoreSignature);
3142 if (IsEventLogging() != MagickFalse)
3143 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3144 image_info->filename);
3172MagickExport
void SetImageInfoFile(
ImageInfo *image_info,FILE *file)
3174 assert(image_info != (
ImageInfo *) NULL);
3175 assert(image_info->signature == MagickCoreSignature);
3176 if (IsEventLogging() != MagickFalse)
3177 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3178 image_info->filename);
3179 image_info->file=file;
3212MagickExport MagickBooleanType SetImageMask(
Image *image,
const PixelMask type,
3228 assert(image != (
Image *) NULL);
3229 if (IsEventLogging() != MagickFalse)
3230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3231 assert(image->signature == MagickCoreSignature);
3232 if (mask == (
const Image *) NULL)
3238 image->channels=(ChannelType) ((
unsigned int) image->channels &
3239 (
unsigned int) ~ReadMaskChannel);
3242 case WritePixelMask:
3244 image->channels=(ChannelType) ((
unsigned int) image->channels &
3245 (
unsigned int) ~WriteMaskChannel);
3250 image->channels=(ChannelType) ((
unsigned int) image->channels &
3251 (
unsigned int) ~CompositeMaskChannel);
3255 return(SyncImagePixelCache(image,exception));
3261 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3264 case WritePixelMask:
3266 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3271 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3275 if (SyncImagePixelCache(image,exception) == MagickFalse)
3276 return(MagickFalse);
3278 image->mask_trait=UpdatePixelTrait;
3279 mask_view=AcquireVirtualCacheView(mask,exception);
3280 image_view=AcquireAuthenticCacheView(image,exception);
3281#if defined(MAGICKCORE_OPENMP_SUPPORT)
3282 #pragma omp parallel for schedule(static) shared(status) \
3283 magick_number_threads(mask,image,image->rows,2)
3285 for (y=0; y < (ssize_t) image->rows; y++)
3296 if (status == MagickFalse)
3298 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3299 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3300 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3305 for (x=0; x < (ssize_t) image->columns; x++)
3311 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3312 intensity=GetPixelIntensity(mask,p);
3317 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3320 case WritePixelMask:
3322 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3327 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3331 p+=(ptrdiff_t) GetPixelChannels(mask);
3332 q+=(ptrdiff_t) GetPixelChannels(image);
3334 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3337 image->mask_trait=UndefinedPixelTrait;
3338 mask_view=DestroyCacheView(mask_view);
3339 image_view=DestroyCacheView(image_view);
3373MagickExport MagickBooleanType SetImageRegionMask(
Image *image,
3388 assert(image != (
Image *) NULL);
3389 assert(image->signature == MagickCoreSignature);
3390 if (IsEventLogging() != MagickFalse)
3391 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3398 image->channels=(ChannelType) ((
unsigned int) image->channels &
3399 (
unsigned int) ~ReadMaskChannel);
3402 case WritePixelMask:
3404 image->channels=(ChannelType) ((
unsigned int) image->channels &
3405 (
unsigned int) ~WriteMaskChannel);
3410 image->channels=(ChannelType) ((
unsigned int) image->channels &
3411 (
unsigned int) ~CompositeMaskChannel);
3415 return(SyncImagePixelCache(image,exception));
3421 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3424 case WritePixelMask:
3426 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3431 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3435 if (SyncImagePixelCache(image,exception) == MagickFalse)
3436 return(MagickFalse);
3438 image->mask_trait=UpdatePixelTrait;
3439 image_view=AcquireAuthenticCacheView(image,exception);
3440#if defined(MAGICKCORE_OPENMP_SUPPORT)
3441 #pragma omp parallel for schedule(static) shared(status) \
3442 magick_number_threads(image,image,image->rows,2)
3444 for (y=0; y < (ssize_t) image->rows; y++)
3452 if (status == MagickFalse)
3454 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3455 if (q == (Quantum *) NULL)
3460 for (x=0; x < (ssize_t) image->columns; x++)
3466 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3467 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3473 SetPixelReadMask(image,pixel,q);
3476 case WritePixelMask:
3478 SetPixelWriteMask(image,pixel,q);
3483 SetPixelCompositeMask(image,pixel,q);
3487 q+=(ptrdiff_t) GetPixelChannels(image);
3489 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3492 image->mask_trait=UndefinedPixelTrait;
3493 image_view=DestroyCacheView(image_view);
3526MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(
Image *image,
3527 const VirtualPixelMethod virtual_pixel_method,
ExceptionInfo *exception)
3529 assert(image != (
const Image *) NULL);
3530 assert(image->signature == MagickCoreSignature);
3531 if (IsEventLogging() != MagickFalse)
3532 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3533 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3571static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3599 if (images->previous == (
Image *) NULL)
3602 SetGeometry(smush_image,&right_geometry);
3603 GravityAdjustGeometry(right_image->columns,right_image->rows,
3604 right_image->gravity,&right_geometry);
3605 left_image=images->previous;
3606 SetGeometry(smush_image,&left_geometry);
3607 GravityAdjustGeometry(left_image->columns,left_image->rows,
3608 left_image->gravity,&left_geometry);
3609 gap=right_image->columns;
3610 left_view=AcquireVirtualCacheView(left_image,exception);
3611 right_view=AcquireVirtualCacheView(right_image,exception);
3612 for (y=0; y < (ssize_t) smush_image->rows; y++)
3614 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3616 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3617 if ((p == (
const Quantum *) NULL) ||
3618 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3619 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3622 i=(ssize_t) left_image->columns-x-1;
3623 for (x=0; x < (ssize_t) right_image->columns; x++)
3625 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3627 if ((p == (
const Quantum *) NULL) ||
3628 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3629 ((x+i) >= (ssize_t) gap))
3632 if ((x+i) < (ssize_t) gap)
3635 right_view=DestroyCacheView(right_view);
3636 left_view=DestroyCacheView(left_view);
3637 if (y < (ssize_t) smush_image->rows)
3639 return((ssize_t) gap-offset);
3642static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3670 if (images->previous == (
Image *) NULL)
3672 bottom_image=images;
3673 SetGeometry(smush_image,&bottom_geometry);
3674 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3675 bottom_image->gravity,&bottom_geometry);
3676 top_image=images->previous;
3677 SetGeometry(smush_image,&top_geometry);
3678 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3680 gap=bottom_image->rows;
3681 top_view=AcquireVirtualCacheView(top_image,exception);
3682 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3683 for (x=0; x < (ssize_t) smush_image->columns; x++)
3685 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3687 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3688 if ((p == (
const Quantum *) NULL) ||
3689 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3690 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3693 i=(ssize_t) top_image->rows-y-1;
3694 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3696 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3698 if ((p == (
const Quantum *) NULL) ||
3699 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3700 ((y+i) >= (ssize_t) gap))
3703 if ((y+i) < (ssize_t) gap)
3706 bottom_view=DestroyCacheView(bottom_view);
3707 top_view=DestroyCacheView(top_view);
3708 if (x < (ssize_t) smush_image->columns)
3710 return((ssize_t) gap-offset);
3713MagickExport
Image *SmushImages(
const Image *images,
3714 const MagickBooleanType stack,
const ssize_t offset,
ExceptionInfo *exception)
3716#define SmushImageTag "Smush/Image"
3752 assert(images != (
Image *) NULL);
3753 assert(images->signature == MagickCoreSignature);
3755 assert(exception->signature == MagickCoreSignature);
3756 if (IsEventLogging() != MagickFalse)
3757 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3759 alpha_trait=image->alpha_trait;
3761 width=image->columns;
3763 next=GetNextImageInList(image);
3764 for ( ; next != (
Image *) NULL; next=GetNextImageInList(next))
3766 if (next->alpha_trait != UndefinedPixelTrait)
3767 alpha_trait=BlendPixelTrait;
3769 if (stack != MagickFalse)
3771 if (next->columns > width)
3772 width=next->columns;
3774 if (next->previous != (
Image *) NULL)
3775 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3778 width+=next->columns;
3779 if (next->previous != (
Image *) NULL)
3780 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3781 if (next->rows > height)
3787 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3788 if (smush_image == (
Image *) NULL)
3789 return((
Image *) NULL);
3790 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3792 smush_image=DestroyImage(smush_image);
3793 return((
Image *) NULL);
3795 smush_image->alpha_trait=alpha_trait;
3796 (void) SetImageBackgroundColor(smush_image,exception);
3800 for (n=0; n < (MagickOffsetType) number_images; n++)
3802 SetGeometry(smush_image,&geometry);
3803 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3804 if (stack != MagickFalse)
3806 x_offset-=geometry.x;
3807 y_offset-=SmushYGap(smush_image,image,offset,exception);
3811 x_offset-=SmushXGap(smush_image,image,offset,exception);
3812 y_offset-=geometry.y;
3814 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3815 y_offset,exception);
3816 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3817 if (proceed == MagickFalse)
3819 if (stack == MagickFalse)
3821 x_offset+=(ssize_t) image->columns;
3827 y_offset+=(ssize_t) image->rows;
3829 image=GetNextImageInList(image);
3831 if (stack == MagickFalse)
3832 smush_image->columns=(size_t) x_offset;
3834 smush_image->rows=(size_t) y_offset;
3835 if (status == MagickFalse)
3836 smush_image=DestroyImage(smush_image);
3837 return(smush_image);
3864MagickExport MagickBooleanType StripImage(
Image *image,
3870 magick_unreferenced(exception);
3871 assert(image != (
Image *) NULL);
3872 if (IsEventLogging() != MagickFalse)
3873 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3874 DestroyImageProfiles(image);
3875 (void) DeleteImageProperty(image,
"comment");
3876 (void) DeleteImageProperty(image,
"date:create");
3877 (void) DeleteImageProperty(image,
"date:modify");
3878 (void) DeleteImageProperty(image,
"date:timestamp");
3879 status=SetImageArtifact(image,
"png:exclude-chunk",
3880 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3910static inline Quantum PushColormapIndex(
Image *image,
const Quantum index,
3911 MagickBooleanType *range_exception)
3913 if ((
size_t) index < image->colors)
3915 *range_exception=MagickTrue;
3916 return((Quantum) 0);
3932 assert(image != (
Image *) NULL);
3933 assert(image->signature == MagickCoreSignature);
3934 if (IsEventLogging() != MagickFalse)
3935 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3936 if (image->ping != MagickFalse)
3938 if (image->storage_class != PseudoClass)
3939 return(MagickFalse);
3940 assert(image->colormap != (
PixelInfo *) NULL);
3941 range_exception=MagickFalse;
3944 image_view=AcquireAuthenticCacheView(image,exception);
3945#if defined(MAGICKCORE_OPENMP_SUPPORT)
3946 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3947 magick_number_threads(image,image,image->rows,2)
3949 for (y=0; y < (ssize_t) image->rows; y++)
3960 if (status == MagickFalse)
3962 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3963 if (q == (Quantum *) NULL)
3968 for (x=0; x < (ssize_t) image->columns; x++)
3970 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3971 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3972 q+=(ptrdiff_t) GetPixelChannels(image);
3974 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3977 image_view=DestroyCacheView(image_view);
3979 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3980 (void) ThrowMagickException(exception,GetMagickModule(),
3981 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4022MagickExport MagickBooleanType SyncImagesSettings(
ImageInfo *image_info,
4028 assert(image_info != (
const ImageInfo *) NULL);
4029 assert(image_info->signature == MagickCoreSignature);
4030 assert(images != (
Image *) NULL);
4031 assert(images->signature == MagickCoreSignature);
4032 if (IsEventLogging() != MagickFalse)
4033 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4035 for ( ; image != (
Image *) NULL; image=GetNextImageInList(image))
4036 (
void) SyncImageSettings(image_info,image,exception);
4037 (void) DeleteImageOption(image_info,
"page");
4041MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4059 assert(image_info != (
const ImageInfo *) NULL);
4060 assert(image_info->signature == MagickCoreSignature);
4061 assert(image != (
Image *) NULL);
4062 assert(image->signature == MagickCoreSignature);
4063 if (IsEventLogging() != MagickFalse)
4064 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4065 option=GetImageOption(image_info,
"background");
4066 if (option != (
const char *) NULL)
4067 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4069 option=GetImageOption(image_info,
"black-point-compensation");
4070 if (option != (
const char *) NULL)
4071 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4072 MagickBooleanOptions,MagickFalse,option);
4073 option=GetImageOption(image_info,
"blue-primary");
4074 if (option != (
const char *) NULL)
4076 flags=ParseGeometry(option,&geometry_info);
4077 if ((flags & RhoValue) != 0)
4078 image->chromaticity.blue_primary.x=geometry_info.rho;
4079 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4080 if ((flags & SigmaValue) != 0)
4081 image->chromaticity.blue_primary.y=geometry_info.sigma;
4083 option=GetImageOption(image_info,
"bordercolor");
4084 if (option != (
const char *) NULL)
4085 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4088 option=GetImageOption(image_info,
"compose");
4089 if (option != (
const char *) NULL)
4090 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4091 MagickFalse,option);
4093 option=GetImageOption(image_info,
"compress");
4094 if (option != (
const char *) NULL)
4095 image->compression=(CompressionType) ParseCommandOption(
4096 MagickCompressOptions,MagickFalse,option);
4097 option=GetImageOption(image_info,
"debug");
4098 if (option != (
const char *) NULL)
4099 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4100 MagickFalse,option);
4101 option=GetImageOption(image_info,
"density");
4102 if (option != (
const char *) NULL)
4104 flags=ParseGeometry(option,&geometry_info);
4105 if ((flags & RhoValue) != 0)
4106 image->resolution.x=geometry_info.rho;
4107 image->resolution.y=image->resolution.x;
4108 if ((flags & SigmaValue) != 0)
4109 image->resolution.y=geometry_info.sigma;
4111 option=GetImageOption(image_info,
"depth");
4112 if (option != (
const char *) NULL)
4113 image->depth=StringToUnsignedLong(option);
4114 option=GetImageOption(image_info,
"endian");
4115 if (option != (
const char *) NULL)
4116 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4117 MagickFalse,option);
4118 option=GetImageOption(image_info,
"filter");
4119 if (option != (
const char *) NULL)
4120 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4121 MagickFalse,option);
4122 option=GetImageOption(image_info,
"fuzz");
4123 if (option != (
const char *) NULL)
4124 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4125 option=GetImageOption(image_info,
"gravity");
4126 if (option != (
const char *) NULL)
4127 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4128 MagickFalse,option);
4129 option=GetImageOption(image_info,
"green-primary");
4130 if (option != (
const char *) NULL)
4132 flags=ParseGeometry(option,&geometry_info);
4133 if ((flags & RhoValue) != 0)
4134 image->chromaticity.green_primary.x=geometry_info.rho;
4135 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4136 if ((flags & SigmaValue) != 0)
4137 image->chromaticity.green_primary.y=geometry_info.sigma;
4139 option=GetImageOption(image_info,
"intent");
4140 if (option != (
const char *) NULL)
4141 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4142 MagickIntentOptions,MagickFalse,option);
4143 option=GetImageOption(image_info,
"intensity");
4144 if (option != (
const char *) NULL)
4145 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4146 MagickPixelIntensityOptions,MagickFalse,option);
4147 option=GetImageOption(image_info,
"interlace");
4148 if (option != (
const char *) NULL)
4149 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4150 MagickFalse,option);
4151 option=GetImageOption(image_info,
"interpolate");
4152 if (option != (
const char *) NULL)
4153 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4154 MagickInterpolateOptions,MagickFalse,option);
4155 option=GetImageOption(image_info,
"loop");
4156 if (option != (
const char *) NULL)
4157 image->iterations=StringToUnsignedLong(option);
4158 option=GetImageOption(image_info,
"mattecolor");
4159 if (option != (
const char *) NULL)
4160 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4162 option=GetImageOption(image_info,
"orient");
4163 if (option != (
const char *) NULL)
4164 image->orientation=(OrientationType) ParseCommandOption(
4165 MagickOrientationOptions,MagickFalse,option);
4166 option=GetImageOption(image_info,
"page");
4167 if (option != (
const char *) NULL)
4172 geometry=GetPageGeometry(option);
4173 flags=ParseAbsoluteGeometry(geometry,&image->page);
4174 geometry=DestroyString(geometry);
4176 option=GetImageOption(image_info,
"quality");
4177 if (option != (
const char *) NULL)
4178 image->quality=StringToUnsignedLong(option);
4179 option=GetImageOption(image_info,
"red-primary");
4180 if (option != (
const char *) NULL)
4182 flags=ParseGeometry(option,&geometry_info);
4183 if ((flags & RhoValue) != 0)
4184 image->chromaticity.red_primary.x=geometry_info.rho;
4185 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4186 if ((flags & SigmaValue) != 0)
4187 image->chromaticity.red_primary.y=geometry_info.sigma;
4189 if (image_info->quality != UndefinedCompressionQuality)
4190 image->quality=image_info->quality;
4191 option=GetImageOption(image_info,
"scene");
4192 if (option != (
const char *) NULL)
4193 image->scene=StringToUnsignedLong(option);
4194 option=GetImageOption(image_info,
"taint");
4195 if (option != (
const char *) NULL)
4196 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4197 MagickFalse,option);
4198 option=GetImageOption(image_info,
"tile-offset");
4199 if (option != (
const char *) NULL)
4204 geometry=GetPageGeometry(option);
4205 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4206 geometry=DestroyString(geometry);
4208 option=GetImageOption(image_info,
"transparent-color");
4209 if (option != (
const char *) NULL)
4210 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4212 option=GetImageOption(image_info,
"type");
4213 if (option != (
const char *) NULL)
4214 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4216 option=GetImageOption(image_info,
"units");
4217 units=image_info->units;
4218 if (option != (
const char *) NULL)
4219 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4220 MagickFalse,option);
4221 if (units != UndefinedResolution)
4223 if (image->units != units)
4224 switch (image->units)
4226 case PixelsPerInchResolution:
4228 if (units == PixelsPerCentimeterResolution)
4230 image->resolution.x/=2.54;
4231 image->resolution.y/=2.54;
4235 case PixelsPerCentimeterResolution:
4237 if (units == PixelsPerInchResolution)
4239 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4240 image->resolution.x+0.5))/100.0;
4241 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4242 image->resolution.y+0.5))/100.0;
4250 option=GetImageOption(image_info,
"density");
4251 if (option != (
const char *) NULL)
4253 flags=ParseGeometry(option,&geometry_info);
4254 if ((flags & RhoValue) != 0)
4255 image->resolution.x=geometry_info.rho;
4256 image->resolution.y=image->resolution.x;
4257 if ((flags & SigmaValue) != 0)
4258 image->resolution.y=geometry_info.sigma;
4261 option=GetImageOption(image_info,
"virtual-pixel");
4262 if (option != (
const char *) NULL)
4263 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4264 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4266 option=GetImageOption(image_info,
"white-point");
4267 if (option != (
const char *) NULL)
4269 flags=ParseGeometry(option,&geometry_info);
4270 if ((flags & RhoValue) != 0)
4271 image->chromaticity.white_point.x=geometry_info.rho;
4272 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4273 if ((flags & SigmaValue) != 0)
4274 image->chromaticity.white_point.y=geometry_info.sigma;
4282 if (image->image_info != (
ImageInfo *) NULL)
4283 image->image_info=DestroyImageInfo(image->image_info);
4284 image->image_info=CloneImageInfo(image_info);