43#include "MagickCore/studio.h"
44#include "MagickCore/animate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/blob.h"
48#include "MagickCore/blob-private.h"
49#include "MagickCore/cache.h"
50#include "MagickCore/cache-private.h"
51#include "MagickCore/cache-view.h"
52#include "MagickCore/channel.h"
53#include "MagickCore/client.h"
54#include "MagickCore/color.h"
55#include "MagickCore/color-private.h"
56#include "MagickCore/colormap.h"
57#include "MagickCore/colorspace.h"
58#include "MagickCore/colorspace-private.h"
59#include "MagickCore/composite.h"
60#include "MagickCore/composite-private.h"
61#include "MagickCore/compress.h"
62#include "MagickCore/constitute.h"
63#include "MagickCore/delegate.h"
64#include "MagickCore/display.h"
65#include "MagickCore/draw.h"
66#include "MagickCore/enhance.h"
67#include "MagickCore/exception.h"
68#include "MagickCore/exception-private.h"
69#include "MagickCore/gem.h"
70#include "MagickCore/geometry.h"
71#include "MagickCore/histogram.h"
72#include "MagickCore/image-private.h"
73#include "MagickCore/list.h"
74#include "MagickCore/magic.h"
75#include "MagickCore/magick.h"
76#include "MagickCore/magick-private.h"
77#include "MagickCore/memory_.h"
78#include "MagickCore/memory-private.h"
79#include "MagickCore/module.h"
80#include "MagickCore/monitor.h"
81#include "MagickCore/monitor-private.h"
82#include "MagickCore/option.h"
83#include "MagickCore/paint.h"
84#include "MagickCore/pixel-accessor.h"
85#include "MagickCore/profile.h"
86#include "MagickCore/property.h"
87#include "MagickCore/quantize.h"
88#include "MagickCore/random_.h"
89#include "MagickCore/resource_.h"
90#include "MagickCore/segment.h"
91#include "MagickCore/semaphore.h"
92#include "MagickCore/signature-private.h"
93#include "MagickCore/statistic.h"
94#include "MagickCore/string_.h"
95#include "MagickCore/string-private.h"
96#include "MagickCore/thread-private.h"
97#include "MagickCore/threshold.h"
98#include "MagickCore/timer.h"
99#include "MagickCore/timer-private.h"
100#include "MagickCore/token.h"
101#include "MagickCore/token-private.h"
102#include "MagickCore/utility.h"
103#include "MagickCore/utility-private.h"
104#include "MagickCore/version.h"
105#include "MagickCore/xwindow-private.h"
134MagickExport Image *AcquireImage(
const ImageInfo *image_info,
135 ExceptionInfo *exception)
152 if (IsEventLogging() != MagickFalse)
153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
154 image=(Image *) AcquireCriticalMemory(
sizeof(*image));
155 (void) memset(image,0,
sizeof(*image));
159 (void) CopyMagickString(image->magick,
"MIFF",MagickPathExtent);
160 image->storage_class=DirectClass;
161 image->depth=MAGICKCORE_QUANTUM_DEPTH;
162 image->colorspace=sRGBColorspace;
163 image->rendering_intent=PerceptualIntent;
164 image->gamma=1.000/2.200;
165 image->chromaticity.red_primary.x=0.6400;
166 image->chromaticity.red_primary.y=0.3300;
167 image->chromaticity.red_primary.z=0.0300;
168 image->chromaticity.green_primary.x=0.3000;
169 image->chromaticity.green_primary.y=0.6000;
170 image->chromaticity.green_primary.z=0.1000;
171 image->chromaticity.blue_primary.x=0.1500;
172 image->chromaticity.blue_primary.y=0.0600;
173 image->chromaticity.blue_primary.z=0.7900;
174 image->chromaticity.white_point.x=0.3127;
175 image->chromaticity.white_point.y=0.3290;
176 image->chromaticity.white_point.z=0.3583;
177 image->interlace=NoInterlace;
178 image->ticks_per_second=UndefinedTicksPerSecond;
179 image->compose=OverCompositeOp;
180 GetPixelInfoRGBA(BackgroundColorRGBA,&image->background_color);
181 GetPixelInfoRGBA(BorderColorRGBA,&image->border_color);
182 GetPixelInfoRGBA(MatteColorRGBA,&image->matte_color);
183 GetPixelInfoRGBA(TransparentColorRGBA,&image->transparent_color);
184 GetTimerInfo(&image->timer);
185 image->cache=AcquirePixelCache(0);
186 image->channel_mask=AllChannels;
187 image->channel_map=AcquirePixelChannelMap();
188 image->blob=CloneBlobInfo((BlobInfo *) NULL);
189 image->timestamp=time((time_t *) NULL);
190 time_limit=GetMagickResourceLimit(TimeResource);
191 if (time_limit != MagickResourceInfinity)
192 image->ttl=image->timestamp+(time_t) 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;
198 if (image_info == (ImageInfo *) NULL)
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) CastDoubleToSsizeT(floor(geometry_info.rho+
293 if ((flags & LessValue) != 0)
295 if ((
double) image->delay < floor(geometry_info.rho+0.5))
296 image->ticks_per_second=CastDoubleToSsizeT(floor(
297 geometry_info.sigma+0.5));
300 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+
302 if ((flags & SigmaValue) != 0)
303 image->ticks_per_second=CastDoubleToSsizeT(floor(geometry_info.sigma+
306 option=GetImageOption(image_info,
"dispose");
307 if (option != (
const char *) NULL)
308 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
331MagickExport ImageInfo *AcquireImageInfo(
void)
336 image_info=(ImageInfo *) AcquireCriticalMemory(
sizeof(*image_info));
337 GetImageInfo(image_info);
372MagickExport
void AcquireNextImage(
const ImageInfo *image_info,Image *image,
373 ExceptionInfo *exception)
378 assert(image != (Image *) NULL);
379 assert(image->signature == MagickCoreSignature);
380 if (IsEventLogging() != MagickFalse)
381 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
382 image->next=AcquireImage(image_info,exception);
383 if (GetNextImageInList(image) == (Image *) NULL)
385 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
387 if (image_info != (ImageInfo *) NULL)
388 (void) CopyMagickString(GetNextImageInList(image)->filename,
389 image_info->filename,MagickPathExtent);
390 DestroyBlob(GetNextImageInList(image));
391 image->next->blob=ReferenceBlob(image->blob);
392 image->next->endian=image->endian;
393 image->next->scene=image->scene+1;
394 image->next->previous=image;
429MagickExport Image *AppendImages(
const Image *images,
430 const MagickBooleanType stack,ExceptionInfo *exception)
432#define AppendImageTag "Append/Image"
444 homogeneous_colorspace,
473 assert(images != (Image *) NULL);
474 assert(images->signature == MagickCoreSignature);
475 assert(exception != (ExceptionInfo *) NULL);
476 assert(exception->signature == MagickCoreSignature);
477 if (IsEventLogging() != MagickFalse)
478 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
479 alpha_trait=images->alpha_trait;
481 width=images->columns;
484 image_type=images->type;
485 homogeneous_colorspace=MagickTrue;
486 next=GetNextImageInList(images);
487 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
489 if (next->depth > depth)
491 if (next->type != images->type)
492 image_type=UndefinedType;
493 if (next->colorspace != images->colorspace)
494 homogeneous_colorspace=MagickFalse;
495 if (next->alpha_trait != UndefinedPixelTrait)
496 alpha_trait=BlendPixelTrait;
498 if (stack != MagickFalse)
500 if (next->columns > width)
505 width+=next->columns;
506 if (next->rows > height)
512 append_image=CloneImage(images,width,height,MagickTrue,exception);
513 if (append_image == (Image *) NULL)
514 return((Image *) NULL);
515 if (image_type != BilevelType)
517 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
519 append_image=DestroyImage(append_image);
520 return((Image *) NULL);
522 if (homogeneous_colorspace == MagickFalse)
523 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
525 append_image->depth=depth;
526 append_image->alpha_trait=alpha_trait;
527 append_image->page=images->page;
528 (void) SetImageBackgroundColor(append_image,exception);
533 append_view=AcquireAuthenticCacheView(append_image,exception);
534 for (n=0; n < (MagickOffsetType) number_images; n++)
542 SetGeometry(append_image,&geometry);
543 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
544 if (stack != MagickFalse)
545 x_offset-=geometry.x;
547 y_offset-=geometry.y;
548 image_view=AcquireVirtualCacheView(next,exception);
549#if defined(MAGICKCORE_OPENMP_SUPPORT)
550 #pragma omp parallel for schedule(static) shared(status) \
551 magick_number_threads(next,next,next->rows,2)
553 for (y=0; y < (ssize_t) next->rows; y++)
570 if (status == MagickFalse)
572 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
573 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
574 next->columns,1,exception);
575 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
580 GetPixelInfo(next,&pixel);
581 for (x=0; x < (ssize_t) next->columns; x++)
583 GetPixelInfoPixel(next,p,&pixel);
584 SetPixelViaPixelInfo(append_image,&pixel,q);
585 p+=(ptrdiff_t) GetPixelChannels(next);
586 q+=(ptrdiff_t) GetPixelChannels(append_image);
588 sync=SyncCacheViewAuthenticPixels(append_view,exception);
589 if (sync == MagickFalse)
592 image_view=DestroyCacheView(image_view);
593 if (stack == MagickFalse)
595 x_offset+=(ssize_t) next->columns;
601 y_offset+=(ssize_t) next->rows;
603 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
604 if (proceed == MagickFalse)
606 next=GetNextImageInList(next);
608 append_view=DestroyCacheView(append_view);
609 if (status == MagickFalse)
610 append_image=DestroyImage(append_image);
611 return(append_image);
638MagickExport ExceptionType CatchImageException(Image *image)
646 assert(image != (
const Image *) NULL);
647 assert(image->signature == MagickCoreSignature);
648 if (IsEventLogging() != MagickFalse)
649 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
650 exception=AcquireExceptionInfo();
651 CatchException(exception);
652 severity=exception->severity;
653 exception=DestroyExceptionInfo(exception);
690MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
692 return(ClipImagePath(image,
"#1",MagickTrue,exception));
695MagickExport MagickBooleanType ClipImagePath(Image *image,
const char *pathname,
696 const MagickBooleanType inside,ExceptionInfo *exception)
698#define ClipImagePathTag "ClipPath/Image"
713 assert(image != (
const Image *) NULL);
714 assert(image->signature == MagickCoreSignature);
715 assert(pathname != NULL);
716 if (IsEventLogging() != MagickFalse)
717 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
718 property=AcquireString(pathname);
719 (void) FormatLocaleString(property,MagickPathExtent,
"8BIM:1999,2998:%s",
721 value=GetImageProperty(image,property,exception);
722 property=DestroyString(property);
723 if (value == (
const char *) NULL)
725 ThrowFileException(exception,OptionError,
"NoClipPathDefined",
729 image_info=AcquireImageInfo();
730 (void) CopyMagickString(image_info->filename,image->filename,
732 (void) ConcatenateMagickString(image_info->filename,
"_",MagickPathExtent);
733 sanitized_pathname=SanitizeString(pathname);
734 (void) ConcatenateMagickString(image_info->filename,sanitized_pathname,
736 sanitized_pathname=DestroyString(sanitized_pathname);
737 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
738 image_info=DestroyImageInfo(image_info);
739 if (clip_mask == (Image *) NULL)
741 if (clip_mask->storage_class == PseudoClass)
743 (void) SyncImage(clip_mask,exception);
744 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
747 if (inside != MagickFalse)
748 (void) NegateImage(clip_mask,MagickFalse,exception);
749 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
750 "8BIM:1999,2998:%s\nPS",pathname);
751 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
752 image->mask_trait=UpdatePixelTrait;
753 clip_mask=DestroyImage(clip_mask);
796MagickExport Image *CloneImage(
const Image *image,
const size_t columns,
797 const size_t rows,
const MagickBooleanType detach,ExceptionInfo *exception)
812 assert(image != (
const Image *) NULL);
813 assert(image->signature == MagickCoreSignature);
814 assert(exception != (ExceptionInfo *) NULL);
815 assert(exception->signature == MagickCoreSignature);
816 if (IsEventLogging() != MagickFalse)
817 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
818 if ((image->columns == 0) || (image->rows == 0))
820 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
821 "NegativeOrZeroImageSize",
"`%s'",image->filename);
822 return((Image *) NULL);
824 clone_image=(Image *) AcquireCriticalMemory(
sizeof(*clone_image));
825 (void) memset(clone_image,0,
sizeof(*clone_image));
826 clone_image->signature=MagickCoreSignature;
827 clone_image->storage_class=image->storage_class;
828 clone_image->number_channels=image->number_channels;
829 clone_image->number_meta_channels=image->number_meta_channels;
830 clone_image->metacontent_extent=image->metacontent_extent;
831 clone_image->colorspace=image->colorspace;
832 clone_image->alpha_trait=image->alpha_trait;
833 clone_image->channels=image->channels;
834 clone_image->mask_trait=image->mask_trait;
835 clone_image->columns=image->columns;
836 clone_image->rows=image->rows;
837 clone_image->dither=image->dither;
838 clone_image->image_info=CloneImageInfo(image->image_info);
839 (void) CloneImageProfiles(clone_image,image);
840 (void) CloneImageProperties(clone_image,image);
841 (void) CloneImageArtifacts(clone_image,image);
842 GetTimerInfo(&clone_image->timer);
843 if (image->ascii85 != (
void *) NULL)
844 Ascii85Initialize(clone_image);
845 clone_image->extent=image->extent;
846 clone_image->magick_columns=image->magick_columns;
847 clone_image->magick_rows=image->magick_rows;
848 clone_image->type=image->type;
849 clone_image->channel_mask=image->channel_mask;
850 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
851 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
853 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
854 (void) CopyMagickString(clone_image->filename,image->filename,
856 clone_image->progress_monitor=image->progress_monitor;
857 clone_image->client_data=image->client_data;
858 clone_image->reference_count=1;
859 clone_image->next=image->next;
860 clone_image->previous=image->previous;
861 clone_image->list=NewImageList();
862 if (detach == MagickFalse)
863 clone_image->blob=ReferenceBlob(image->blob);
866 clone_image->next=NewImageList();
867 clone_image->previous=NewImageList();
868 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
870 clone_image->ping=image->ping;
871 clone_image->timestamp=image->timestamp;
872 clone_image->ttl=image->ttl;
873 clone_image->debug=image->debug;
874 clone_image->semaphore=AcquireSemaphoreInfo();
875 if (image->colormap != (PixelInfo *) NULL)
880 clone_image->colors=image->colors;
881 length=(size_t) image->colors;
882 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length+1,
883 sizeof(*clone_image->colormap));
884 if (clone_image->colormap == (PixelInfo *) NULL)
886 clone_image=DestroyImage(clone_image);
887 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
889 (void) memcpy(clone_image->colormap,image->colormap,length*
890 sizeof(*clone_image->colormap));
892 if ((columns == 0) || (rows == 0))
894 if (image->montage != (
char *) NULL)
895 (void) CloneString(&clone_image->montage,image->montage);
896 if (image->directory != (
char *) NULL)
897 (void) CloneString(&clone_image->directory,image->directory);
898 clone_image->cache=ReferencePixelCache(image->cache);
903 if (image->columns != 0)
904 scale_x=(double) columns/(
double) image->columns;
905 if (image->rows != 0)
906 scale_y=(double) rows/(
double) image->rows;
907 clone_image->page.width=(size_t) CastDoubleToSsizeT(floor(scale_x*
908 image->page.width+0.5));
909 clone_image->page.height=(size_t) CastDoubleToSsizeT(floor(scale_y*
910 image->page.height+0.5));
911 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
912 scale_x=scale_y=MagickMin(scale_x,scale_y);
913 clone_image->page.x=CastDoubleToSsizeT(ceil(scale_x*image->page.x-0.5));
914 clone_image->tile_offset.x=CastDoubleToSsizeT(ceil(scale_x*
915 image->tile_offset.x-0.5));
916 clone_image->page.y=CastDoubleToSsizeT(ceil(scale_y*image->page.y-0.5));
917 clone_image->tile_offset.y=CastDoubleToSsizeT(ceil(scale_y*
918 image->tile_offset.y-0.5));
919 clone_image->cache=ClonePixelCache(image->cache);
920 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
921 clone_image=DestroyImage(clone_image);
949MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
954 clone_info=AcquireImageInfo();
955 if (image_info == (ImageInfo *) NULL)
957 clone_info->compression=image_info->compression;
958 clone_info->temporary=image_info->temporary;
959 clone_info->adjoin=image_info->adjoin;
960 clone_info->antialias=image_info->antialias;
961 clone_info->scene=image_info->scene;
962 clone_info->number_scenes=image_info->number_scenes;
963 clone_info->depth=image_info->depth;
964 if (image_info->size != (
char *) NULL)
965 (void) CloneString(&clone_info->size,image_info->size);
966 if (image_info->extract != (
char *) NULL)
967 (void) CloneString(&clone_info->extract,image_info->extract);
968 if (image_info->scenes != (
char *) NULL)
969 (void) CloneString(&clone_info->scenes,image_info->scenes);
970 if (image_info->page != (
char *) NULL)
971 (void) CloneString(&clone_info->page,image_info->page);
972 clone_info->interlace=image_info->interlace;
973 clone_info->endian=image_info->endian;
974 clone_info->units=image_info->units;
975 clone_info->quality=image_info->quality;
976 if (image_info->sampling_factor != (
char *) NULL)
977 (void) CloneString(&clone_info->sampling_factor,
978 image_info->sampling_factor);
979 if (image_info->server_name != (
char *) NULL)
980 (void) CloneString(&clone_info->server_name,image_info->server_name);
981 if (image_info->font != (
char *) NULL)
982 (void) CloneString(&clone_info->font,image_info->font);
983 if (image_info->texture != (
char *) NULL)
984 (void) CloneString(&clone_info->texture,image_info->texture);
985 if (image_info->density != (
char *) NULL)
986 (void) CloneString(&clone_info->density,image_info->density);
987 clone_info->pointsize=image_info->pointsize;
988 clone_info->fuzz=image_info->fuzz;
989 clone_info->matte_color=image_info->matte_color;
990 clone_info->background_color=image_info->background_color;
991 clone_info->border_color=image_info->border_color;
992 clone_info->transparent_color=image_info->transparent_color;
993 clone_info->dither=image_info->dither;
994 clone_info->monochrome=image_info->monochrome;
995 clone_info->colorspace=image_info->colorspace;
996 clone_info->type=image_info->type;
997 clone_info->orientation=image_info->orientation;
998 clone_info->ping=image_info->ping;
999 clone_info->verbose=image_info->verbose;
1000 clone_info->progress_monitor=image_info->progress_monitor;
1001 clone_info->client_data=image_info->client_data;
1002 clone_info->cache=image_info->cache;
1003 if (image_info->cache != (
void *) NULL)
1004 clone_info->cache=ReferencePixelCache(image_info->cache);
1005 if (image_info->profile != (
void *) NULL)
1006 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1007 image_info->profile);
1008 SetImageInfoFile(clone_info,image_info->file);
1009 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1010 clone_info->stream=image_info->stream;
1011 clone_info->custom_stream=image_info->custom_stream;
1012 (void) CopyMagickString(clone_info->magick,image_info->magick,
1014 (void) CopyMagickString(clone_info->unique,image_info->unique,
1016 (void) CopyMagickString(clone_info->filename,image_info->filename,
1018 clone_info->channel=image_info->channel;
1019 (void) CloneImageOptions(clone_info,image_info);
1020 clone_info->debug=image_info->debug;
1021 clone_info->signature=image_info->signature;
1058MagickExport MagickBooleanType CopyImagePixels(Image *image,
1059 const Image *source_image,
const RectangleInfo *geometry,
1060 const OffsetInfo *offset,ExceptionInfo *exception)
1062#define CopyImageTag "Copy/Image"
1077 assert(image != (Image *) NULL);
1078 assert(source_image != (Image *) NULL);
1079 assert(geometry != (RectangleInfo *) NULL);
1080 assert(offset != (OffsetInfo *) NULL);
1081 if (IsEventLogging() != MagickFalse)
1082 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1083 if ((offset->x < 0) || (offset->y < 0) ||
1084 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1085 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1086 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1088 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1089 return(MagickFalse);
1095 source_view=AcquireVirtualCacheView(source_image,exception);
1096 image_view=AcquireAuthenticCacheView(image,exception);
1097#if defined(MAGICKCORE_OPENMP_SUPPORT)
1098 #pragma omp parallel for schedule(static) shared(progress,status) \
1099 magick_number_threads(image,source_image,geometry->height,2)
1101 for (y=0; y < (ssize_t) geometry->height; y++)
1115 if (status == MagickFalse)
1117 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1118 geometry->width,1,exception);
1119 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1120 geometry->width,1,exception);
1121 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1126 for (x=0; x < (ssize_t) geometry->width; x++)
1131 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1133 PixelChannel channel = GetPixelChannelChannel(image,i);
1134 PixelTrait traits = GetPixelChannelTraits(image,channel);
1135 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1136 if ((traits == UndefinedPixelTrait) ||
1137 ((traits & UpdatePixelTrait) == 0) ||
1138 (source_traits == UndefinedPixelTrait))
1140 SetPixelChannel(image,channel,p[i],q);
1142 p+=(ptrdiff_t) GetPixelChannels(source_image);
1143 q+=(ptrdiff_t) GetPixelChannels(image);
1145 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1146 if (sync == MagickFalse)
1148 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1153#if defined(MAGICKCORE_OPENMP_SUPPORT)
1157 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1158 if (proceed == MagickFalse)
1162 source_view=DestroyCacheView(source_view);
1163 image_view=DestroyCacheView(image_view);
1190MagickExport Image *DestroyImage(Image *image)
1198 assert(image != (Image *) NULL);
1199 assert(image->signature == MagickCoreSignature);
1200 if (IsEventLogging() != MagickFalse)
1201 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1202 destroy=MagickFalse;
1203 LockSemaphoreInfo(image->semaphore);
1204 image->reference_count--;
1205 if (image->reference_count == 0)
1207 UnlockSemaphoreInfo(image->semaphore);
1208 if (destroy == MagickFalse)
1209 return((Image *) NULL);
1213 DestroyImagePixels(image);
1214 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1215 if (image->montage != (
char *) NULL)
1216 image->montage=DestroyString(image->montage);
1217 if (image->directory != (
char *) NULL)
1218 image->directory=DestroyString(image->directory);
1219 if (image->colormap != (PixelInfo *) NULL)
1220 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1221 if (image->geometry != (
char *) NULL)
1222 image->geometry=DestroyString(image->geometry);
1223 DestroyImageProfiles(image);
1224 DestroyImageProperties(image);
1225 DestroyImageArtifacts(image);
1226 if (image->ascii85 != (Ascii85Info *) NULL)
1227 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1228 if (image->image_info != (ImageInfo *) NULL)
1229 image->image_info=DestroyImageInfo(image->image_info);
1232 RelinquishSemaphoreInfo(&image->semaphore);
1233 image->signature=(~MagickCoreSignature);
1234 image=(Image *) RelinquishMagickMemory(image);
1261MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1263 assert(image_info != (ImageInfo *) NULL);
1264 assert(image_info->signature == MagickCoreSignature);
1265 if (IsEventLogging() != MagickFalse)
1266 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1267 image_info->filename);
1268 if (image_info->size != (
char *) NULL)
1269 image_info->size=DestroyString(image_info->size);
1270 if (image_info->extract != (
char *) NULL)
1271 image_info->extract=DestroyString(image_info->extract);
1272 if (image_info->scenes != (
char *) NULL)
1273 image_info->scenes=DestroyString(image_info->scenes);
1274 if (image_info->page != (
char *) NULL)
1275 image_info->page=DestroyString(image_info->page);
1276 if (image_info->sampling_factor != (
char *) NULL)
1277 image_info->sampling_factor=DestroyString(
1278 image_info->sampling_factor);
1279 if (image_info->server_name != (
char *) NULL)
1280 image_info->server_name=DestroyString(
1281 image_info->server_name);
1282 if (image_info->font != (
char *) NULL)
1283 image_info->font=DestroyString(image_info->font);
1284 if (image_info->texture != (
char *) NULL)
1285 image_info->texture=DestroyString(image_info->texture);
1286 if (image_info->density != (
char *) NULL)
1287 image_info->density=DestroyString(image_info->density);
1288 if (image_info->cache != (
void *) NULL)
1289 image_info->cache=DestroyPixelCache(image_info->cache);
1290 if (image_info->profile != (StringInfo *) NULL)
1291 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1292 image_info->profile);
1293 DestroyImageOptions(image_info);
1294 image_info->signature=(~MagickCoreSignature);
1295 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1323MagickExport
void DisassociateImageStream(Image *image)
1325 assert(image != (Image *) NULL);
1326 assert(image->signature == MagickCoreSignature);
1327 if (IsEventLogging() != MagickFalse)
1328 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1329 DisassociateBlob(image);
1354MagickExport
void GetImageInfo(ImageInfo *image_info)
1362 assert(image_info != (ImageInfo *) NULL);
1363 if (IsEventLogging() != MagickFalse)
1364 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1365 (void) memset(image_info,0,
sizeof(*image_info));
1366 image_info->adjoin=MagickTrue;
1367 image_info->interlace=NoInterlace;
1368 image_info->channel=AllChannels;
1369 image_info->quality=UndefinedCompressionQuality;
1370 image_info->antialias=MagickTrue;
1371 image_info->dither=MagickTrue;
1372 image_info->depth=0;
1373 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1374 if (synchronize != (
const char *) NULL)
1376 image_info->synchronize=IsStringTrue(synchronize);
1377 synchronize=DestroyString(synchronize);
1379 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1380 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1381 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1382 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1383 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1385 image_info->signature=MagickCoreSignature;
1410MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1412 return(image_info->file);
1440MagickExport Image *GetImageMask(
const Image *image,
const PixelMask type,
1441 ExceptionInfo *exception)
1459 assert(image != (Image *) NULL);
1460 assert(image->signature == MagickCoreSignature);
1461 if (IsEventLogging() != MagickFalse)
1462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1467 if ((image->channels & ReadMaskChannel) == 0)
1468 return((Image *) NULL);
1471 case WritePixelMask:
1473 if ((image->channels & WriteMaskChannel) == 0)
1474 return((Image *) NULL);
1479 if ((image->channels & CompositeMaskChannel) == 0)
1480 return((Image *) NULL);
1484 mask_image=AcquireImage((ImageInfo *) NULL,exception);
1485 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1486 if (status == MagickFalse)
1487 return(DestroyImage(mask_image));
1489 mask_image->alpha_trait=UndefinedPixelTrait;
1490 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1491 image_view=AcquireVirtualCacheView(image,exception);
1492 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1493#if defined(MAGICKCORE_OPENMP_SUPPORT)
1494 #pragma omp parallel for schedule(static) shared(status) \
1495 magick_number_threads(image,image,image->rows,2)
1497 for (y=0; y < (ssize_t) image->rows; y++)
1508 if (status == MagickFalse)
1510 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1511 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1513 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1518 for (x=0; x < (ssize_t) image->columns; x++)
1524 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1527 case WritePixelMask:
1529 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1534 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1538 p+=(ptrdiff_t) GetPixelChannels(image);
1539 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1541 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1544 mask_view=DestroyCacheView(mask_view);
1545 image_view=DestroyCacheView(image_view);
1546 if (status == MagickFalse)
1547 mask_image=DestroyImage(mask_image);
1573MagickExport ssize_t GetImageReferenceCount(Image *image)
1578 assert(image != (Image *) NULL);
1579 assert(image->signature == MagickCoreSignature);
1580 if (IsEventLogging() != MagickFalse)
1581 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1582 LockSemaphoreInfo(image->semaphore);
1583 reference_count=image->reference_count;
1584 UnlockSemaphoreInfo(image->semaphore);
1585 return(reference_count);
1612MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1614 assert(image != (Image *) NULL);
1615 assert(image->signature == MagickCoreSignature);
1616 if (IsEventLogging() != MagickFalse)
1617 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1618 return(GetPixelCacheVirtualMethod(image));
1657static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1661 specifier = end[-1];
1669 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1670 return(MagickFalse);
1671 if ((length == 1) && (*start == specifier))
1680 if ((length >= 3) && (start[1] ==
'0'))
1681 return(MagickFalse);
1684 for ( ; i < (length-1); i++)
1685 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1686 return(MagickFalse);
1689 return(MagickFalse);
1692MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1693 Image *image,
const char *format,
int value,
char *filename,
1694 ExceptionInfo *exception)
1698 pattern[MagickPathExtent];
1703 assert(format != (
const char *) NULL);
1704 assert(filename != (
char *) NULL);
1705 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1707 (void) CopyMagickString(filename,format,MagickPathExtent);
1708 return(strlen(filename));
1710 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1728 specifier_start=cursor;
1729 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1731 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1734 *specifier_end = cursor+1;
1736 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1739 format_specifier[MagickPathExtent];
1742 length = cursor-specifier_start,
1748 (void) snprintf(format_specifier,
sizeof(format_specifier),
1749 "%%%.*s%c",(
int) length,specifier_start,*cursor);
1750 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1752 pattern_length=strlen(pattern);
1753 if ((count <= 0) || ((
size_t) count != pattern_length))
1755 if ((p-filename+pattern_length) >= MagickPathExtent)
1757 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
1775 *end = strchr(cursor,
']'),
1776 *option = (
const char *) NULL;
1782 if (end == (
const char *) NULL)
1784 extent=(size_t) (end-cursor-1);
1785 if (extent >=
sizeof(pattern))
1787 (void) CopyMagickString(pattern,cursor+1,extent+1);
1788 pattern[extent]=
'\0';
1791 option=GetImageProperty(image,pattern,exception);
1792 if (option == (
const char *) NULL)
1793 option=GetImageArtifact(image,pattern);
1795 if ((option == (
const char *) NULL) &&
1796 (image_info != (ImageInfo *) NULL))
1797 option=GetImageOption(image_info,pattern);
1798 if (option == (
const char *) NULL)
1800 option_length=strlen(option);
1801 if ((p-filename+option_length) >= MagickPathExtent)
1803 (void) CopyMagickString(p,option,MagickPathExtent-(p-filename));
1812 if ((p-filename+1) >= MagickPathExtent)
1817 return(strlen(filename));
1847MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1848 ExceptionInfo *exception)
1850#if !defined(MAGICKCORE_HDRI_SUPPORT)
1853 return(MagickFalse);
1864 assert(image != (Image *) NULL);
1865 assert(image->signature == MagickCoreSignature);
1866 if (IsEventLogging() != MagickFalse)
1867 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1868 image_view=AcquireVirtualCacheView(image,exception);
1869#if defined(MAGICKCORE_OPENMP_SUPPORT)
1870 #pragma omp parallel for schedule(static) shared(hdri) \
1871 magick_number_threads(image,image,image->rows,2)
1873 for (y=0; y < (ssize_t) image->rows; y++)
1881 if (hdri != MagickFalse)
1883 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1884 if (p == (
const Quantum *) NULL)
1886 for (x=0; x < (ssize_t) image->columns; x++)
1891 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1899 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1900 if (traits == UndefinedPixelTrait)
1902 pixel=(double) p[i];
1903 if ((pixel < 0.0) || (pixel > (
double) QuantumRange) ||
1904 (pixel != (
double) ((QuantumAny) pixel)))
1910 if (hdri != MagickFalse)
1912 p+=(ptrdiff_t) GetPixelChannels(image);
1915 image_view=DestroyCacheView(image_view);
1943MagickExport MagickBooleanType IsImageObject(
const Image *image)
1948 assert(image != (Image *) NULL);
1949 if (IsEventLogging() != MagickFalse)
1950 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1951 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1952 if (p->signature != MagickCoreSignature)
1953 return(MagickFalse);
1980MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1983 magick[MagickPathExtent],
1984 filename[MagickPathExtent];
1989 assert(image != (Image *) NULL);
1990 assert(image->signature == MagickCoreSignature);
1991 if (IsEventLogging() != MagickFalse)
1992 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1993 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1994 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1995 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1997 if (p->taint != MagickFalse)
1999 if (LocaleCompare(p->magick,magick) != 0)
2001 if (LocaleCompare(p->filename,filename) != 0)
2004 return(MagickFalse);
2033MagickExport MagickBooleanType ModifyImage(Image **image,
2034 ExceptionInfo *exception)
2039 assert(image != (Image **) NULL);
2040 assert(*image != (Image *) NULL);
2041 assert((*image)->signature == MagickCoreSignature);
2042 if (IsEventLogging() != MagickFalse)
2043 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2044 if (GetImageReferenceCount(*image) <= 1)
2046 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2047 LockSemaphoreInfo((*image)->semaphore);
2048 (*image)->reference_count--;
2049 UnlockSemaphoreInfo((*image)->semaphore);
2087MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2088 const size_t width,
const size_t height,
const PixelInfo *background,
2089 ExceptionInfo *exception)
2103 assert(image_info != (
const ImageInfo *) NULL);
2104 assert(image_info->signature == MagickCoreSignature);
2105 assert(background != (
const PixelInfo *) NULL);
2106 if (IsEventLogging() != MagickFalse)
2107 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2108 image=AcquireImage(image_info,exception);
2109 image->columns=width;
2111 image->colorspace=background->colorspace;
2112 image->alpha_trait=background->alpha_trait;
2113 image->fuzz=background->fuzz;
2114 image->depth=background->depth;
2116 image_view=AcquireAuthenticCacheView(image,exception);
2117#if defined(MAGICKCORE_OPENMP_SUPPORT)
2118 #pragma omp parallel for schedule(static) shared(status) \
2119 magick_number_threads(image,image,image->rows,2)
2121 for (y=0; y < (ssize_t) image->rows; y++)
2129 if (status == MagickFalse)
2131 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2132 if (q == (Quantum *) NULL)
2137 for (x=0; x < (ssize_t) image->columns; x++)
2139 SetPixelViaPixelInfo(image,background,q);
2140 q+=(ptrdiff_t) GetPixelChannels(image);
2142 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2145 image_view=DestroyCacheView(image_view);
2146 if (status == MagickFalse)
2147 image=DestroyImage(image);
2174MagickExport Image *ReferenceImage(Image *image)
2176 assert(image != (Image *) NULL);
2177 assert(image->signature == MagickCoreSignature);
2178 if (IsEventLogging() != MagickFalse)
2179 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2180 LockSemaphoreInfo(image->semaphore);
2181 image->reference_count++;
2182 UnlockSemaphoreInfo(image->semaphore);
2210MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2218 assert(image != (Image *) NULL);
2219 assert(image->signature == MagickCoreSignature);
2220 if (IsEventLogging() != MagickFalse)
2221 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2222 flags=ParseAbsoluteGeometry(page,&geometry);
2223 if ((flags & WidthValue) != 0)
2225 if ((flags & HeightValue) == 0)
2226 geometry.height=geometry.width;
2227 image->page.width=geometry.width;
2228 image->page.height=geometry.height;
2230 if ((flags & AspectValue) != 0)
2232 if ((flags & XValue) != 0)
2233 image->page.x+=geometry.x;
2234 if ((flags & YValue) != 0)
2235 image->page.y+=geometry.y;
2239 if ((flags & XValue) != 0)
2241 image->page.x=geometry.x;
2242 if ((image->page.width == 0) && (geometry.x > 0))
2243 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2245 if ((flags & YValue) != 0)
2247 image->page.y=geometry.y;
2248 if ((image->page.height == 0) && (geometry.y > 0))
2249 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2281MagickExport MagickBooleanType ResetImagePixels(Image *image,
2282 ExceptionInfo *exception)
2299 assert(image != (Image *) NULL);
2300 assert(image->signature == MagickCoreSignature);
2301 if (IsEventLogging() != MagickFalse)
2302 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2303 pixels=AcquirePixelCachePixels(image,&length,exception);
2304 if (pixels != (
void *) NULL)
2309 (void) memset(pixels,0,length);
2316 image_view=AcquireAuthenticCacheView(image,exception);
2317#if defined(MAGICKCORE_OPENMP_SUPPORT)
2318 #pragma omp parallel for schedule(static) shared(status) \
2319 magick_number_threads(image,image,image->rows,2)
2321 for (y=0; y < (ssize_t) image->rows; y++)
2329 if (status == MagickFalse)
2331 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2332 if (q == (Quantum *) NULL)
2337 for (x=0; x < (ssize_t) image->columns; x++)
2339 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2340 q+=(ptrdiff_t) GetPixelChannels(image);
2342 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2345 image_view=DestroyCacheView(image_view);
2377MagickExport MagickBooleanType SetImageAlpha(Image *image,
const Quantum alpha,
2378 ExceptionInfo *exception)
2389 assert(image != (Image *) NULL);
2390 assert(image->signature == MagickCoreSignature);
2391 if (IsEventLogging() != MagickFalse)
2392 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2393 image->alpha_trait=BlendPixelTrait;
2395 image_view=AcquireAuthenticCacheView(image,exception);
2396#if defined(MAGICKCORE_OPENMP_SUPPORT)
2397 #pragma omp parallel for schedule(static) shared(status) \
2398 magick_number_threads(image,image,image->rows,2)
2400 for (y=0; y < (ssize_t) image->rows; y++)
2408 if (status == MagickFalse)
2410 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2411 if (q == (Quantum *) NULL)
2416 for (x=0; x < (ssize_t) image->columns; x++)
2418 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2419 SetPixelAlpha(image,alpha,q);
2420 q+=(ptrdiff_t) GetPixelChannels(image);
2422 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2425 image_view=DestroyCacheView(image_view);
2456MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2457 ExceptionInfo *exception)
2471 assert(image != (Image *) NULL);
2472 assert(image->signature == MagickCoreSignature);
2473 if (IsEventLogging() != MagickFalse)
2474 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2475 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2476 return(MagickFalse);
2477 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2478 ((image->alpha_trait & BlendPixelTrait) == 0))
2479 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2480 ConformPixelInfo(image,&image->background_color,&background,exception);
2485 image_view=AcquireAuthenticCacheView(image,exception);
2486#if defined(MAGICKCORE_OPENMP_SUPPORT)
2487 #pragma omp parallel for schedule(static) shared(status) \
2488 magick_number_threads(image,image,image->rows,2)
2490 for (y=0; y < (ssize_t) image->rows; y++)
2498 if (status == MagickFalse)
2500 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2501 if (q == (Quantum *) NULL)
2506 for (x=0; x < (ssize_t) image->columns; x++)
2508 SetPixelViaPixelInfo(image,&background,q);
2509 q+=(ptrdiff_t) GetPixelChannels(image);
2511 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2514 image_view=DestroyCacheView(image_view);
2544MagickExport ChannelType SetImageChannelMask(Image *image,
2545 const ChannelType channel_mask)
2547 return(SetPixelChannelMask(image,channel_mask));
2577MagickExport MagickBooleanType SetImageColor(Image *image,
2578 const PixelInfo *color,ExceptionInfo *exception)
2589 assert(image != (Image *) NULL);
2590 assert(image->signature == MagickCoreSignature);
2591 assert(color != (
const PixelInfo *) NULL);
2592 if (IsEventLogging() != MagickFalse)
2593 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2594 image->colorspace=color->colorspace;
2595 image->alpha_trait=color->alpha_trait;
2596 image->fuzz=color->fuzz;
2597 image->depth=color->depth;
2599 image_view=AcquireAuthenticCacheView(image,exception);
2600#if defined(MAGICKCORE_OPENMP_SUPPORT)
2601 #pragma omp parallel for schedule(static) shared(status) \
2602 magick_number_threads(image,image,image->rows,2)
2604 for (y=0; y < (ssize_t) image->rows; y++)
2612 if (status == MagickFalse)
2614 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2615 if (q == (Quantum *) NULL)
2620 for (x=0; x < (ssize_t) image->columns; x++)
2622 SetPixelViaPixelInfo(image,color,q);
2623 q+=(ptrdiff_t) GetPixelChannels(image);
2625 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2628 image_view=DestroyCacheView(image_view);
2660MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2661 const ClassType storage_class,ExceptionInfo *exception)
2663 assert(image != (Image *) NULL);
2664 assert(image->signature == MagickCoreSignature);
2665 assert(exception != (ExceptionInfo *) NULL);
2666 assert(exception->signature == MagickCoreSignature);
2667 if (IsEventLogging() != MagickFalse)
2668 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2669 image->storage_class=storage_class;
2670 return(SyncImagePixelCache(image,exception));
2702MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2703 const size_t rows,ExceptionInfo *exception)
2705 if ((columns == 0) || (rows == 0))
2706 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2707 image->columns=columns;
2709 if (image->depth == 0)
2712 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2713 "ImageDepthNotSupported",
"`%s'",image->filename);
2715 if (image->depth > (8*
sizeof(MagickSizeType)))
2717 image->depth=8*
sizeof(MagickSizeType);
2718 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2719 "ImageDepthNotSupported",
"`%s'",image->filename);
2721 return(SyncImagePixelCache(image,exception));
2759static const MagickInfo *SetImageInfoFromExtension(ImageInfo *image_info,
2760 const char *component,
char *magic,ExceptionInfo *exception)
2772 *format_type_formats[] =
2796 (void) CopyMagickString(magic,component,MagickPathExtent);
2801 format_type=UndefinedFormatType;
2802 magick_info=GetMagickInfo(magic,exception);
2803 if ((magick_info != (
const MagickInfo *) NULL) &&
2804 (magick_info->format_type != UndefinedFormatType))
2805 format_type=magick_info->format_type;
2807 while ((format_type == UndefinedFormatType) &&
2808 (format_type_formats[i] != (
char *) NULL))
2810 if ((*magic == *format_type_formats[i]) &&
2811 (LocaleCompare(magic,format_type_formats[i]) == 0))
2812 format_type=ExplicitFormatType;
2815 if (format_type == UndefinedFormatType)
2816 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2818 if (format_type == ExplicitFormatType)
2820 image_info->affirm=MagickTrue;
2821 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2823 if (LocaleCompare(magic,
"RGB") == 0)
2824 image_info->affirm=MagickFalse;
2825 return(magick_info);
2828MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2829 const unsigned int frames,ExceptionInfo *exception)
2832 component[MagickPathExtent],
2833 magic[MagickPathExtent],
2834 path[MagickPathExtent],
2861 assert(image_info != (ImageInfo *) NULL);
2862 assert(image_info->signature == MagickCoreSignature);
2863 if (IsEventLogging() != MagickFalse)
2864 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2865 image_info->filename);
2867 GetPathComponent(image_info->filename,SubimagePath,component);
2868 if (*component !=
'\0')
2873 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2875 if (IsGeometry(component) != MagickFalse)
2876 (void) CloneString(&image_info->extract,component);
2884 (void) CloneString(&image_info->scenes,component);
2885 image_info->scene=StringToUnsignedLong(image_info->scenes);
2886 image_info->number_scenes=image_info->scene;
2887 p=image_info->scenes;
2888 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2890 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2892 first=(size_t) strtol(p,&q,10);
2894 while (isspace((
int) ((
unsigned char) *q)) != 0)
2897 last=(size_t) strtol(q+1,&q,10);
2900 if (first < image_info->scene)
2901 image_info->scene=first;
2902 if (last > image_info->number_scenes)
2903 image_info->number_scenes=last;
2906 image_info->number_scenes-=image_info->scene-1;
2910 if (*image_info->magick ==
'\0')
2911 GetPathComponent(image_info->filename,ExtensionPath,component);
2912 if (*component !=
'\0')
2917 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2918 GetPathComponent(path,ExtensionPath,component);
2920 image_info->affirm=MagickFalse;
2921 sans_exception=AcquireExceptionInfo();
2922 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2923 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2929 GetPathComponent(image_info->filename,MagickPath,magic);
2932 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2933 magick_info=GetMagickInfo(magic,sans_exception);
2934 if ((magick_info != (
const MagickInfo *) NULL) &&
2935 (magick_info->format_type == ExplicitFormatType))
2936 image_info->affirm=MagickTrue;
2938 GetPathComponent(image_info->filename,CanonicalPath,component);
2940 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2941 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2952 magick_info=GetMagickInfo(magic,sans_exception);
2953 delegate_info=(
const DelegateInfo *) NULL;
2954 if (magick_info == (
const MagickInfo *) NULL)
2956 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2957 if (delegate_info == (
const DelegateInfo *) NULL)
2958 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2959 if ((delegate_info == (
const DelegateInfo *) NULL) &&
2960 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2965 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2969 if (((magick_info != (
const MagickInfo *) NULL) ||
2970 (delegate_info != (
const DelegateInfo *) NULL)) &&
2971 (IsMagickConflict(magic) == MagickFalse))
2973 image_info->affirm=MagickTrue;
2974 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2975 GetPathComponent(image_info->filename,CanonicalPath,component);
2976 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
2977 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2978 (void) CopyMagickString(image_info->filename,component,
2982 sans_exception=DestroyExceptionInfo(sans_exception);
2983 if ((magick_info == (
const MagickInfo *) NULL) ||
2984 (GetMagickEndianSupport(magick_info) == MagickFalse))
2985 image_info->endian=UndefinedEndian;
2986 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2991 (void) InterpretImageFilename(image_info,(Image *) NULL,
2992 image_info->filename,(
int) image_info->scene,component,exception);
2993 if ((LocaleCompare(component,image_info->filename) != 0) &&
2994 (strchr(component,
'%') == (
char *) NULL))
2995 image_info->adjoin=MagickFalse;
2997 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3002 magick_info=GetMagickInfo(magic,exception);
3003 if (magick_info != (
const MagickInfo *) NULL)
3004 if (GetMagickAdjoin(magick_info) == MagickFalse)
3005 image_info->adjoin=MagickFalse;
3007 if (image_info->affirm != MagickFalse)
3020 magick_size=GetMagicPatternExtent(exception);
3021 if (magick_size == 0)
3022 return(MagickFalse);
3023 image=AcquireImage(image_info,exception);
3024 (void) CopyMagickString(image->filename,image_info->filename,
3026 sans_exception=AcquireExceptionInfo();
3027 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3028 sans_exception=DestroyExceptionInfo(sans_exception);
3029 if (status == MagickFalse)
3031 image=DestroyImage(image);
3032 return(MagickFalse);
3034 if ((IsBlobSeekable(image) == MagickFalse) ||
3035 (IsBlobExempt(image) != MagickFalse))
3041 status=ImageToFile(image,component,exception);
3042 if (CloseBlob(image) == MagickFalse)
3044 if (status == MagickFalse)
3046 (void) RelinquishUniqueFileResource(component);
3047 image=DestroyImage(image);
3048 return(MagickFalse);
3050 SetImageInfoFile(image_info,(FILE *) NULL);
3051 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3052 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3053 if (status == MagickFalse)
3055 (void) RelinquishUniqueFileResource(component);
3056 image=DestroyImage(image);
3057 return(MagickFalse);
3059 (void) CopyMagickString(image_info->filename,component,
3061 image_info->temporary=MagickTrue;
3063 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3064 if (magick == (
unsigned char *) NULL)
3066 (void) CloseBlob(image);
3067 image=DestroyImage(image);
3068 return(MagickFalse);
3070 (void) memset(magick,0,magick_size);
3071 count=ReadBlob(image,magick_size,magick);
3072 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3073 (void) CloseBlob(image);
3074 image=DestroyImage(image);
3078 sans_exception=AcquireExceptionInfo();
3079 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3080 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3081 if ((magic_info != (
const MagicInfo *) NULL) &&
3082 (GetMagicName(magic_info) != (
char *) NULL))
3087 if ((magick_info != (
const MagickInfo *) NULL) &&
3088 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3089 (LocaleCompare(magick_info->magick_module,GetMagicName(
3091 (void) CopyMagickString(image_info->magick,magick_info->name,
3095 (void) CopyMagickString(image_info->magick,GetMagicName(
3096 magic_info),MagickPathExtent);
3097 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3099 if ((magick_info == (
const MagickInfo *) NULL) ||
3100 (GetMagickEndianSupport(magick_info) == MagickFalse))
3101 image_info->endian=UndefinedEndian;
3102 sans_exception=DestroyExceptionInfo(sans_exception);
3105 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3106 if ((magick_info == (
const MagickInfo *) NULL) ||
3107 (GetMagickEndianSupport(magick_info) == MagickFalse))
3108 image_info->endian=UndefinedEndian;
3109 sans_exception=DestroyExceptionInfo(sans_exception);
3141MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3142 const size_t length)
3144 assert(image_info != (ImageInfo *) NULL);
3145 assert(image_info->signature == MagickCoreSignature);
3146 if (IsEventLogging() != MagickFalse)
3147 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3148 image_info->filename);
3149 image_info->blob=(
void *) blob;
3150 image_info->length=length;
3178MagickExport
void SetImageInfoCustomStream(ImageInfo *image_info,
3179 CustomStreamInfo *custom_stream)
3181 assert(image_info != (ImageInfo *) NULL);
3182 assert(image_info->signature == MagickCoreSignature);
3183 if (IsEventLogging() != MagickFalse)
3184 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3185 image_info->filename);
3186 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3213MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3215 assert(image_info != (ImageInfo *) NULL);
3216 assert(image_info->signature == MagickCoreSignature);
3217 if (IsEventLogging() != MagickFalse)
3218 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3219 image_info->filename);
3220 image_info->file=file;
3253MagickExport MagickBooleanType SetImageMask(Image *image,
const PixelMask type,
3254 const Image *mask,ExceptionInfo *exception)
3269 assert(image != (Image *) NULL);
3270 if (IsEventLogging() != MagickFalse)
3271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3272 assert(image->signature == MagickCoreSignature);
3273 if (mask == (
const Image *) NULL)
3279 image->channels=(ChannelType) ((
unsigned int) image->channels &
3280 (
unsigned int) ~ReadMaskChannel);
3283 case WritePixelMask:
3285 image->channels=(ChannelType) ((
unsigned int) image->channels &
3286 (
unsigned int) ~WriteMaskChannel);
3291 image->channels=(ChannelType) ((
unsigned int) image->channels &
3292 (
unsigned int) ~CompositeMaskChannel);
3296 return(SyncImagePixelCache(image,exception));
3302 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3305 case WritePixelMask:
3307 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3312 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3316 if (SyncImagePixelCache(image,exception) == MagickFalse)
3317 return(MagickFalse);
3319 image->mask_trait=UpdatePixelTrait;
3320 mask_view=AcquireVirtualCacheView(mask,exception);
3321 image_view=AcquireAuthenticCacheView(image,exception);
3322#if defined(MAGICKCORE_OPENMP_SUPPORT)
3323 #pragma omp parallel for schedule(static) shared(status) \
3324 magick_number_threads(mask,image,image->rows,2)
3326 for (y=0; y < (ssize_t) image->rows; y++)
3337 if (status == MagickFalse)
3339 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3340 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3341 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3346 for (x=0; x < (ssize_t) image->columns; x++)
3352 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3353 intensity=GetPixelIntensity(mask,p);
3358 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3361 case WritePixelMask:
3363 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3368 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3372 p+=(ptrdiff_t) GetPixelChannels(mask);
3373 q+=(ptrdiff_t) GetPixelChannels(image);
3375 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3378 image->mask_trait=UndefinedPixelTrait;
3379 mask_view=DestroyCacheView(mask_view);
3380 image_view=DestroyCacheView(image_view);
3414MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3415 const PixelMask type,
const RectangleInfo *region,ExceptionInfo *exception)
3429 assert(image != (Image *) NULL);
3430 assert(image->signature == MagickCoreSignature);
3431 if (IsEventLogging() != MagickFalse)
3432 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3433 if (region == (
const RectangleInfo *) NULL)
3439 image->channels=(ChannelType) ((
unsigned int) image->channels &
3440 (
unsigned int) ~ReadMaskChannel);
3443 case WritePixelMask:
3445 image->channels=(ChannelType) ((
unsigned int) image->channels &
3446 (
unsigned int) ~WriteMaskChannel);
3451 image->channels=(ChannelType) ((
unsigned int) image->channels &
3452 (
unsigned int) ~CompositeMaskChannel);
3456 return(SyncImagePixelCache(image,exception));
3462 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3465 case WritePixelMask:
3467 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3472 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3476 if (SyncImagePixelCache(image,exception) == MagickFalse)
3477 return(MagickFalse);
3479 image->mask_trait=UpdatePixelTrait;
3480 image_view=AcquireAuthenticCacheView(image,exception);
3481#if defined(MAGICKCORE_OPENMP_SUPPORT)
3482 #pragma omp parallel for schedule(static) shared(status) \
3483 magick_number_threads(image,image,image->rows,2)
3485 for (y=0; y < (ssize_t) image->rows; y++)
3493 if (status == MagickFalse)
3495 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3496 if (q == (Quantum *) NULL)
3501 for (x=0; x < (ssize_t) image->columns; x++)
3507 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3508 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3514 SetPixelReadMask(image,pixel,q);
3517 case WritePixelMask:
3519 SetPixelWriteMask(image,pixel,q);
3524 SetPixelCompositeMask(image,pixel,q);
3528 q+=(ptrdiff_t) GetPixelChannels(image);
3530 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3533 image->mask_trait=UndefinedPixelTrait;
3534 image_view=DestroyCacheView(image_view);
3567MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3568 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3570 assert(image != (
const Image *) NULL);
3571 assert(image->signature == MagickCoreSignature);
3572 if (IsEventLogging() != MagickFalse)
3573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3574 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3612static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3613 const ssize_t offset,ExceptionInfo *exception)
3640 if (images->previous == (Image *) NULL)
3643 SetGeometry(smush_image,&right_geometry);
3644 GravityAdjustGeometry(right_image->columns,right_image->rows,
3645 right_image->gravity,&right_geometry);
3646 left_image=images->previous;
3647 SetGeometry(smush_image,&left_geometry);
3648 GravityAdjustGeometry(left_image->columns,left_image->rows,
3649 left_image->gravity,&left_geometry);
3650 gap=right_image->columns;
3651 left_view=AcquireVirtualCacheView(left_image,exception);
3652 right_view=AcquireVirtualCacheView(right_image,exception);
3653 for (y=0; y < (ssize_t) smush_image->rows; y++)
3655 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3657 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3658 if ((p == (
const Quantum *) NULL) ||
3659 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3660 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3663 i=(ssize_t) left_image->columns-x-1;
3664 for (x=0; x < (ssize_t) right_image->columns; x++)
3666 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3668 if ((p == (
const Quantum *) NULL) ||
3669 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3670 ((x+i) >= (ssize_t) gap))
3673 if ((x+i) < (ssize_t) gap)
3676 right_view=DestroyCacheView(right_view);
3677 left_view=DestroyCacheView(left_view);
3678 if (y < (ssize_t) smush_image->rows)
3680 return((ssize_t) gap-offset);
3683static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3684 const ssize_t offset,ExceptionInfo *exception)
3711 if (images->previous == (Image *) NULL)
3713 bottom_image=images;
3714 SetGeometry(smush_image,&bottom_geometry);
3715 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3716 bottom_image->gravity,&bottom_geometry);
3717 top_image=images->previous;
3718 SetGeometry(smush_image,&top_geometry);
3719 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3721 gap=bottom_image->rows;
3722 top_view=AcquireVirtualCacheView(top_image,exception);
3723 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3724 for (x=0; x < (ssize_t) smush_image->columns; x++)
3726 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3728 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3729 if ((p == (
const Quantum *) NULL) ||
3730 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3731 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3734 i=(ssize_t) top_image->rows-y-1;
3735 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3737 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3739 if ((p == (
const Quantum *) NULL) ||
3740 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3741 ((y+i) >= (ssize_t) gap))
3744 if ((y+i) < (ssize_t) gap)
3747 bottom_view=DestroyCacheView(bottom_view);
3748 top_view=DestroyCacheView(top_view);
3749 if (x < (ssize_t) smush_image->columns)
3751 return((ssize_t) gap-offset);
3754MagickExport Image *SmushImages(
const Image *images,
3755 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3757#define SmushImageTag "Smush/Image"
3793 assert(images != (Image *) NULL);
3794 assert(images->signature == MagickCoreSignature);
3795 assert(exception != (ExceptionInfo *) NULL);
3796 assert(exception->signature == MagickCoreSignature);
3797 if (IsEventLogging() != MagickFalse)
3798 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3800 alpha_trait=image->alpha_trait;
3802 width=image->columns;
3804 next=GetNextImageInList(image);
3805 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3807 if (next->alpha_trait != UndefinedPixelTrait)
3808 alpha_trait=BlendPixelTrait;
3810 if (stack != MagickFalse)
3812 if (next->columns > width)
3813 width=next->columns;
3815 if (next->previous != (Image *) NULL)
3816 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3819 width+=next->columns;
3820 if (next->previous != (Image *) NULL)
3821 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3822 if (next->rows > height)
3828 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3829 if (smush_image == (Image *) NULL)
3830 return((Image *) NULL);
3831 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3833 smush_image=DestroyImage(smush_image);
3834 return((Image *) NULL);
3836 smush_image->alpha_trait=alpha_trait;
3837 (void) SetImageBackgroundColor(smush_image,exception);
3841 for (n=0; n < (MagickOffsetType) number_images; n++)
3843 SetGeometry(smush_image,&geometry);
3844 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3845 if (stack != MagickFalse)
3847 x_offset-=geometry.x;
3848 y_offset-=SmushYGap(smush_image,image,offset,exception);
3852 x_offset-=SmushXGap(smush_image,image,offset,exception);
3853 y_offset-=geometry.y;
3855 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3856 y_offset,exception);
3857 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3858 if (proceed == MagickFalse)
3860 if (stack == MagickFalse)
3862 x_offset+=(ssize_t) image->columns;
3868 y_offset+=(ssize_t) image->rows;
3870 image=GetNextImageInList(image);
3872 if (stack == MagickFalse)
3873 smush_image->columns=(size_t) x_offset;
3875 smush_image->rows=(size_t) y_offset;
3876 if (status == MagickFalse)
3877 smush_image=DestroyImage(smush_image);
3878 return(smush_image);
3905MagickExport MagickBooleanType StripImage(Image *image,
3906 ExceptionInfo *magick_unused(exception))
3911 magick_unreferenced(exception);
3912 assert(image != (Image *) NULL);
3913 if (IsEventLogging() != MagickFalse)
3914 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3915 DestroyImageProfiles(image);
3916 (void) DeleteImageProperty(image,
"comment");
3917 (void) DeleteImageProperty(image,
"date:create");
3918 (void) DeleteImageProperty(image,
"date:modify");
3919 (void) DeleteImageProperty(image,
"date:timestamp");
3920 status=SetImageArtifact(image,
"png:exclude-chunk",
3921 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3951static inline Quantum PushColormapIndex(Image *image,
const Quantum index,
3952 MagickBooleanType *range_exception)
3954 if ((
size_t) index < image->colors)
3956 *range_exception=MagickTrue;
3957 return((Quantum) 0);
3960MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3973 assert(image != (Image *) NULL);
3974 assert(image->signature == MagickCoreSignature);
3975 if (IsEventLogging() != MagickFalse)
3976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3977 if (image->ping != MagickFalse)
3979 if (image->storage_class != PseudoClass)
3980 return(MagickFalse);
3981 assert(image->colormap != (PixelInfo *) NULL);
3982 range_exception=MagickFalse;
3985 image_view=AcquireAuthenticCacheView(image,exception);
3986#if defined(MAGICKCORE_OPENMP_SUPPORT)
3987 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3988 magick_number_threads(image,image,image->rows,2)
3990 for (y=0; y < (ssize_t) image->rows; y++)
4001 if (status == MagickFalse)
4003 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4004 if (q == (Quantum *) NULL)
4009 for (x=0; x < (ssize_t) image->columns; x++)
4011 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4012 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4013 q+=(ptrdiff_t) GetPixelChannels(image);
4015 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4018 image_view=DestroyCacheView(image_view);
4020 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4021 (void) ThrowMagickException(exception,GetMagickModule(),
4022 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4063MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4064 Image *images,ExceptionInfo *exception)
4069 assert(image_info != (
const ImageInfo *) NULL);
4070 assert(image_info->signature == MagickCoreSignature);
4071 assert(images != (Image *) NULL);
4072 assert(images->signature == MagickCoreSignature);
4073 if (IsEventLogging() != MagickFalse)
4074 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4076 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4077 (
void) SyncImageSettings(image_info,image,exception);
4078 (void) DeleteImageOption(image_info,
"page");
4082MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4083 Image *image,ExceptionInfo *exception)
4100 assert(image_info != (
const ImageInfo *) NULL);
4101 assert(image_info->signature == MagickCoreSignature);
4102 assert(image != (Image *) NULL);
4103 assert(image->signature == MagickCoreSignature);
4104 if (IsEventLogging() != MagickFalse)
4105 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4106 option=GetImageOption(image_info,
"background");
4107 if (option != (
const char *) NULL)
4108 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4110 option=GetImageOption(image_info,
"black-point-compensation");
4111 if (option != (
const char *) NULL)
4112 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4113 MagickBooleanOptions,MagickFalse,option);
4114 option=GetImageOption(image_info,
"blue-primary");
4115 if (option != (
const char *) NULL)
4117 flags=ParseGeometry(option,&geometry_info);
4118 if ((flags & RhoValue) != 0)
4119 image->chromaticity.blue_primary.x=geometry_info.rho;
4120 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4121 if ((flags & SigmaValue) != 0)
4122 image->chromaticity.blue_primary.y=geometry_info.sigma;
4124 option=GetImageOption(image_info,
"bordercolor");
4125 if (option != (
const char *) NULL)
4126 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4129 option=GetImageOption(image_info,
"compose");
4130 if (option != (
const char *) NULL)
4131 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4132 MagickFalse,option);
4134 option=GetImageOption(image_info,
"compress");
4135 if (option != (
const char *) NULL)
4136 image->compression=(CompressionType) ParseCommandOption(
4137 MagickCompressOptions,MagickFalse,option);
4138 option=GetImageOption(image_info,
"debug");
4139 if (option != (
const char *) NULL)
4140 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4141 MagickFalse,option);
4142 option=GetImageOption(image_info,
"density");
4143 if (option != (
const char *) NULL)
4145 flags=ParseGeometry(option,&geometry_info);
4146 if ((flags & RhoValue) != 0)
4147 image->resolution.x=geometry_info.rho;
4148 image->resolution.y=image->resolution.x;
4149 if ((flags & SigmaValue) != 0)
4150 image->resolution.y=geometry_info.sigma;
4152 option=GetImageOption(image_info,
"depth");
4153 if (option != (
const char *) NULL)
4154 image->depth=StringToUnsignedLong(option);
4155 option=GetImageOption(image_info,
"endian");
4156 if (option != (
const char *) NULL)
4157 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4158 MagickFalse,option);
4159 option=GetImageOption(image_info,
"filter");
4160 if (option != (
const char *) NULL)
4161 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4162 MagickFalse,option);
4163 option=GetImageOption(image_info,
"fuzz");
4164 if (option != (
const char *) NULL)
4165 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4166 option=GetImageOption(image_info,
"gravity");
4167 if (option != (
const char *) NULL)
4168 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4169 MagickFalse,option);
4170 option=GetImageOption(image_info,
"green-primary");
4171 if (option != (
const char *) NULL)
4173 flags=ParseGeometry(option,&geometry_info);
4174 if ((flags & RhoValue) != 0)
4175 image->chromaticity.green_primary.x=geometry_info.rho;
4176 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4177 if ((flags & SigmaValue) != 0)
4178 image->chromaticity.green_primary.y=geometry_info.sigma;
4180 option=GetImageOption(image_info,
"intent");
4181 if (option != (
const char *) NULL)
4182 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4183 MagickIntentOptions,MagickFalse,option);
4184 option=GetImageOption(image_info,
"intensity");
4185 if (option != (
const char *) NULL)
4186 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4187 MagickPixelIntensityOptions,MagickFalse,option);
4188 option=GetImageOption(image_info,
"interlace");
4189 if (option != (
const char *) NULL)
4190 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4191 MagickFalse,option);
4192 option=GetImageOption(image_info,
"interpolate");
4193 if (option != (
const char *) NULL)
4194 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4195 MagickInterpolateOptions,MagickFalse,option);
4196 option=GetImageOption(image_info,
"loop");
4197 if (option != (
const char *) NULL)
4198 image->iterations=StringToUnsignedLong(option);
4199 option=GetImageOption(image_info,
"mattecolor");
4200 if (option != (
const char *) NULL)
4201 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4203 option=GetImageOption(image_info,
"orient");
4204 if (option != (
const char *) NULL)
4205 image->orientation=(OrientationType) ParseCommandOption(
4206 MagickOrientationOptions,MagickFalse,option);
4207 option=GetImageOption(image_info,
"page");
4208 if (option != (
const char *) NULL)
4213 geometry=GetPageGeometry(option);
4214 flags=ParseAbsoluteGeometry(geometry,&image->page);
4215 geometry=DestroyString(geometry);
4217 option=GetImageOption(image_info,
"quality");
4218 if (option != (
const char *) NULL)
4219 image->quality=StringToUnsignedLong(option);
4220 option=GetImageOption(image_info,
"red-primary");
4221 if (option != (
const char *) NULL)
4223 flags=ParseGeometry(option,&geometry_info);
4224 if ((flags & RhoValue) != 0)
4225 image->chromaticity.red_primary.x=geometry_info.rho;
4226 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4227 if ((flags & SigmaValue) != 0)
4228 image->chromaticity.red_primary.y=geometry_info.sigma;
4230 if (image_info->quality != UndefinedCompressionQuality)
4231 image->quality=image_info->quality;
4232 option=GetImageOption(image_info,
"scene");
4233 if (option != (
const char *) NULL)
4234 image->scene=StringToUnsignedLong(option);
4235 option=GetImageOption(image_info,
"taint");
4236 if (option != (
const char *) NULL)
4237 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4238 MagickFalse,option);
4239 option=GetImageOption(image_info,
"tile-offset");
4240 if (option != (
const char *) NULL)
4245 geometry=GetPageGeometry(option);
4246 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4247 geometry=DestroyString(geometry);
4249 option=GetImageOption(image_info,
"transparent-color");
4250 if (option != (
const char *) NULL)
4251 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4253 option=GetImageOption(image_info,
"type");
4254 if (option != (
const char *) NULL)
4255 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4257 option=GetImageOption(image_info,
"units");
4258 units=image_info->units;
4259 if (option != (
const char *) NULL)
4260 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4261 MagickFalse,option);
4262 if (units != UndefinedResolution)
4264 if (image->units != units)
4265 switch (image->units)
4267 case PixelsPerInchResolution:
4269 if (units == PixelsPerCentimeterResolution)
4271 image->resolution.x/=2.54;
4272 image->resolution.y/=2.54;
4276 case PixelsPerCentimeterResolution:
4278 if (units == PixelsPerInchResolution)
4280 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4281 image->resolution.x+0.5))/100.0;
4282 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4283 image->resolution.y+0.5))/100.0;
4291 option=GetImageOption(image_info,
"density");
4292 if (option != (
const char *) NULL)
4294 flags=ParseGeometry(option,&geometry_info);
4295 if ((flags & RhoValue) != 0)
4296 image->resolution.x=geometry_info.rho;
4297 image->resolution.y=image->resolution.x;
4298 if ((flags & SigmaValue) != 0)
4299 image->resolution.y=geometry_info.sigma;
4302 option=GetImageOption(image_info,
"virtual-pixel");
4303 if (option != (
const char *) NULL)
4304 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4305 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4307 option=GetImageOption(image_info,
"white-point");
4308 if (option != (
const char *) NULL)
4310 flags=ParseGeometry(option,&geometry_info);
4311 if ((flags & RhoValue) != 0)
4312 image->chromaticity.white_point.x=geometry_info.rho;
4313 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4314 if ((flags & SigmaValue) != 0)
4315 image->chromaticity.white_point.y=geometry_info.sigma;
4323 if (image->image_info != (ImageInfo *) NULL)
4324 image->image_info=DestroyImageInfo(image->image_info);
4325 image->image_info=CloneImageInfo(image_info);