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=GetMagickTime();
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+0.5));
292 if ((flags & LessValue) != 0)
294 if ((
double) image->delay < floor(geometry_info.rho+0.5))
295 image->ticks_per_second=CastDoubleToSsizeT(floor(
296 geometry_info.sigma+0.5));
299 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+0.5));
300 if ((flags & SigmaValue) != 0)
301 image->ticks_per_second=CastDoubleToSsizeT(floor(geometry_info.sigma+0.5));
303 option=GetImageOption(image_info,
"dispose");
304 if (option != (
const char *) NULL)
305 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
328MagickExport ImageInfo *AcquireImageInfo(
void)
333 image_info=(ImageInfo *) AcquireCriticalMemory(
sizeof(*image_info));
334 GetImageInfo(image_info);
369MagickExport
void AcquireNextImage(
const ImageInfo *image_info,Image *image,
370 ExceptionInfo *exception)
375 assert(image != (Image *) NULL);
376 assert(image->signature == MagickCoreSignature);
377 if (IsEventLogging() != MagickFalse)
378 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
379 image->next=AcquireImage(image_info,exception);
380 if (GetNextImageInList(image) == (Image *) NULL)
382 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
384 if (image_info != (ImageInfo *) NULL)
385 (void) CopyMagickString(GetNextImageInList(image)->filename,
386 image_info->filename,MagickPathExtent);
387 DestroyBlob(GetNextImageInList(image));
388 image->next->blob=ReferenceBlob(image->blob);
389 image->next->endian=image->endian;
390 image->next->scene=image->scene+1;
391 image->next->previous=image;
426MagickExport Image *AppendImages(
const Image *images,
427 const MagickBooleanType stack,ExceptionInfo *exception)
429#define AppendImageTag "Append/Image"
441 homogeneous_colorspace,
470 assert(images != (Image *) NULL);
471 assert(images->signature == MagickCoreSignature);
472 assert(exception != (ExceptionInfo *) NULL);
473 assert(exception->signature == MagickCoreSignature);
474 if (IsEventLogging() != MagickFalse)
475 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
476 alpha_trait=images->alpha_trait;
478 width=images->columns;
481 image_type=images->type;
482 homogeneous_colorspace=MagickTrue;
483 next=GetNextImageInList(images);
484 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
486 if (next->depth > depth)
488 if (next->type != images->type)
489 image_type=UndefinedType;
490 if (next->colorspace != images->colorspace)
491 homogeneous_colorspace=MagickFalse;
492 if (next->alpha_trait != UndefinedPixelTrait)
493 alpha_trait=BlendPixelTrait;
495 if (stack != MagickFalse)
497 if (next->columns > width)
502 width+=next->columns;
503 if (next->rows > height)
509 append_image=CloneImage(images,width,height,MagickTrue,exception);
510 if (append_image == (Image *) NULL)
511 return((Image *) NULL);
512 if (image_type != BilevelType)
514 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
516 append_image=DestroyImage(append_image);
517 return((Image *) NULL);
519 if (homogeneous_colorspace == MagickFalse)
520 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
522 append_image->depth=depth;
523 append_image->alpha_trait=alpha_trait;
524 append_image->page=images->page;
525 (void) SetImageBackgroundColor(append_image,exception);
530 append_view=AcquireAuthenticCacheView(append_image,exception);
531 for (n=0; n < (MagickOffsetType) number_images; n++)
539 SetGeometry(append_image,&geometry);
540 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
541 if (stack != MagickFalse)
542 x_offset-=geometry.x;
544 y_offset-=geometry.y;
545 image_view=AcquireVirtualCacheView(next,exception);
546#if defined(MAGICKCORE_OPENMP_SUPPORT)
547 #pragma omp parallel for schedule(static) shared(status) \
548 magick_number_threads(next,next,next->rows,2)
550 for (y=0; y < (ssize_t) next->rows; y++)
567 if (status == MagickFalse)
569 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
570 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
571 next->columns,1,exception);
572 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
577 GetPixelInfo(next,&pixel);
578 for (x=0; x < (ssize_t) next->columns; x++)
580 GetPixelInfoPixel(next,p,&pixel);
581 SetPixelViaPixelInfo(append_image,&pixel,q);
582 p+=(ptrdiff_t) GetPixelChannels(next);
583 q+=(ptrdiff_t) GetPixelChannels(append_image);
585 sync=SyncCacheViewAuthenticPixels(append_view,exception);
586 if (sync == MagickFalse)
589 image_view=DestroyCacheView(image_view);
590 if (stack == MagickFalse)
592 x_offset+=(ssize_t) next->columns;
598 y_offset+=(ssize_t) next->rows;
600 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
601 if (proceed == MagickFalse)
603 next=GetNextImageInList(next);
605 append_view=DestroyCacheView(append_view);
606 if (status == MagickFalse)
607 append_image=DestroyImage(append_image);
608 return(append_image);
635MagickExport ExceptionType CatchImageException(Image *image)
643 assert(image != (
const Image *) NULL);
644 assert(image->signature == MagickCoreSignature);
645 if (IsEventLogging() != MagickFalse)
646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
647 exception=AcquireExceptionInfo();
648 CatchException(exception);
649 severity=exception->severity;
650 exception=DestroyExceptionInfo(exception);
687MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
689 return(ClipImagePath(image,
"#1",MagickTrue,exception));
692MagickExport MagickBooleanType ClipImagePath(Image *image,
const char *pathname,
693 const MagickBooleanType inside,ExceptionInfo *exception)
695#define ClipImagePathTag "ClipPath/Image"
709 assert(image != (
const Image *) NULL);
710 assert(image->signature == MagickCoreSignature);
711 assert(pathname != NULL);
712 if (IsEventLogging() != MagickFalse)
713 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
714 property=AcquireString(pathname);
715 (void) FormatLocaleString(property,MagickPathExtent,
"8BIM:1999,2998:%s",
717 value=GetImageProperty(image,property,exception);
718 property=DestroyString(property);
719 if (value == (
const char *) NULL)
721 ThrowFileException(exception,OptionError,
"NoClipPathDefined",
725 image_info=AcquireImageInfo();
726 (void) CopyMagickString(image_info->filename,image->filename,
728 (void) ConcatenateMagickString(image_info->filename,pathname,
730 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
731 image_info=DestroyImageInfo(image_info);
732 if (clip_mask == (Image *) NULL)
734 if (clip_mask->storage_class == PseudoClass)
736 (void) SyncImage(clip_mask,exception);
737 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
740 if (inside != MagickFalse)
741 (void) NegateImage(clip_mask,MagickFalse,exception);
742 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
743 "8BIM:1999,2998:%s\nPS",pathname);
744 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
745 image->mask_trait=UpdatePixelTrait;
746 clip_mask=DestroyImage(clip_mask);
789MagickExport Image *CloneImage(
const Image *image,
const size_t columns,
790 const size_t rows,
const MagickBooleanType detach,ExceptionInfo *exception)
805 assert(image != (
const Image *) NULL);
806 assert(image->signature == MagickCoreSignature);
807 assert(exception != (ExceptionInfo *) NULL);
808 assert(exception->signature == MagickCoreSignature);
809 if (IsEventLogging() != MagickFalse)
810 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
811 if ((image->columns == 0) || (image->rows == 0))
813 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
814 "NegativeOrZeroImageSize",
"`%s'",image->filename);
815 return((Image *) NULL);
817 clone_image=(Image *) AcquireCriticalMemory(
sizeof(*clone_image));
818 (void) memset(clone_image,0,
sizeof(*clone_image));
819 clone_image->signature=MagickCoreSignature;
820 clone_image->storage_class=image->storage_class;
821 clone_image->number_channels=image->number_channels;
822 clone_image->number_meta_channels=image->number_meta_channels;
823 clone_image->metacontent_extent=image->metacontent_extent;
824 clone_image->colorspace=image->colorspace;
825 clone_image->alpha_trait=image->alpha_trait;
826 clone_image->channels=image->channels;
827 clone_image->mask_trait=image->mask_trait;
828 clone_image->columns=image->columns;
829 clone_image->rows=image->rows;
830 clone_image->dither=image->dither;
831 clone_image->image_info=CloneImageInfo(image->image_info);
832 (void) CloneImageProfiles(clone_image,image);
833 (void) CloneImageProperties(clone_image,image);
834 (void) CloneImageArtifacts(clone_image,image);
835 GetTimerInfo(&clone_image->timer);
836 if (image->ascii85 != (
void *) NULL)
837 Ascii85Initialize(clone_image);
838 clone_image->extent=image->extent;
839 clone_image->magick_columns=image->magick_columns;
840 clone_image->magick_rows=image->magick_rows;
841 clone_image->type=image->type;
842 clone_image->channel_mask=image->channel_mask;
843 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
844 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
846 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
847 (void) CopyMagickString(clone_image->filename,image->filename,
849 clone_image->progress_monitor=image->progress_monitor;
850 clone_image->client_data=image->client_data;
851 clone_image->reference_count=1;
852 clone_image->next=image->next;
853 clone_image->previous=image->previous;
854 clone_image->list=NewImageList();
855 if (detach == MagickFalse)
856 clone_image->blob=ReferenceBlob(image->blob);
859 clone_image->next=NewImageList();
860 clone_image->previous=NewImageList();
861 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
863 clone_image->ping=image->ping;
864 clone_image->timestamp=image->timestamp;
865 clone_image->ttl=image->ttl;
866 clone_image->debug=image->debug;
867 clone_image->semaphore=AcquireSemaphoreInfo();
868 if (image->colormap != (PixelInfo *) NULL)
873 clone_image->colors=image->colors;
874 length=(size_t) image->colors;
875 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length+1,
876 sizeof(*clone_image->colormap));
877 if (clone_image->colormap == (PixelInfo *) NULL)
879 clone_image=DestroyImage(clone_image);
880 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
882 (void) memcpy(clone_image->colormap,image->colormap,length*
883 sizeof(*clone_image->colormap));
885 if ((columns == 0) || (rows == 0))
887 if (image->montage != (
char *) NULL)
888 (void) CloneString(&clone_image->montage,image->montage);
889 if (image->directory != (
char *) NULL)
890 (void) CloneString(&clone_image->directory,image->directory);
891 clone_image->cache=ReferencePixelCache(image->cache);
896 if (image->columns != 0)
897 scale_x=(double) columns/(
double) image->columns;
898 if (image->rows != 0)
899 scale_y=(double) rows/(
double) image->rows;
900 clone_image->page.width=(size_t) CastDoubleToSsizeT(floor(scale_x*
901 image->page.width+0.5));
902 clone_image->page.height=(size_t) CastDoubleToSsizeT(floor(scale_y*
903 image->page.height+0.5));
904 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
905 scale_x=scale_y=MagickMin(scale_x,scale_y);
906 clone_image->page.x=CastDoubleToSsizeT(ceil(scale_x*image->page.x-0.5));
907 clone_image->tile_offset.x=CastDoubleToSsizeT(ceil(scale_x*
908 image->tile_offset.x-0.5));
909 clone_image->page.y=CastDoubleToSsizeT(ceil(scale_y*image->page.y-0.5));
910 clone_image->tile_offset.y=CastDoubleToSsizeT(ceil(scale_y*
911 image->tile_offset.y-0.5));
912 clone_image->cache=ClonePixelCache(image->cache);
913 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
914 clone_image=DestroyImage(clone_image);
942MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
947 clone_info=AcquireImageInfo();
948 if (image_info == (ImageInfo *) NULL)
950 clone_info->compression=image_info->compression;
951 clone_info->temporary=image_info->temporary;
952 clone_info->adjoin=image_info->adjoin;
953 clone_info->antialias=image_info->antialias;
954 clone_info->scene=image_info->scene;
955 clone_info->number_scenes=image_info->number_scenes;
956 clone_info->depth=image_info->depth;
957 if (image_info->size != (
char *) NULL)
958 (void) CloneString(&clone_info->size,image_info->size);
959 if (image_info->extract != (
char *) NULL)
960 (void) CloneString(&clone_info->extract,image_info->extract);
961 if (image_info->scenes != (
char *) NULL)
962 (void) CloneString(&clone_info->scenes,image_info->scenes);
963 if (image_info->page != (
char *) NULL)
964 (void) CloneString(&clone_info->page,image_info->page);
965 clone_info->interlace=image_info->interlace;
966 clone_info->endian=image_info->endian;
967 clone_info->units=image_info->units;
968 clone_info->quality=image_info->quality;
969 if (image_info->sampling_factor != (
char *) NULL)
970 (void) CloneString(&clone_info->sampling_factor,
971 image_info->sampling_factor);
972 if (image_info->server_name != (
char *) NULL)
973 (void) CloneString(&clone_info->server_name,image_info->server_name);
974 if (image_info->font != (
char *) NULL)
975 (void) CloneString(&clone_info->font,image_info->font);
976 if (image_info->texture != (
char *) NULL)
977 (void) CloneString(&clone_info->texture,image_info->texture);
978 if (image_info->density != (
char *) NULL)
979 (void) CloneString(&clone_info->density,image_info->density);
980 clone_info->pointsize=image_info->pointsize;
981 clone_info->fuzz=image_info->fuzz;
982 clone_info->matte_color=image_info->matte_color;
983 clone_info->background_color=image_info->background_color;
984 clone_info->border_color=image_info->border_color;
985 clone_info->transparent_color=image_info->transparent_color;
986 clone_info->dither=image_info->dither;
987 clone_info->monochrome=image_info->monochrome;
988 clone_info->colorspace=image_info->colorspace;
989 clone_info->type=image_info->type;
990 clone_info->orientation=image_info->orientation;
991 clone_info->ping=image_info->ping;
992 clone_info->verbose=image_info->verbose;
993 clone_info->progress_monitor=image_info->progress_monitor;
994 clone_info->client_data=image_info->client_data;
995 clone_info->cache=image_info->cache;
996 if (image_info->cache != (
void *) NULL)
997 clone_info->cache=ReferencePixelCache(image_info->cache);
998 if (image_info->profile != (
void *) NULL)
999 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1000 image_info->profile);
1001 SetImageInfoFile(clone_info,image_info->file);
1002 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1003 clone_info->stream=image_info->stream;
1004 clone_info->custom_stream=image_info->custom_stream;
1005 (void) CopyMagickString(clone_info->magick,image_info->magick,
1007 (void) CopyMagickString(clone_info->unique,image_info->unique,
1009 (void) CopyMagickString(clone_info->filename,image_info->filename,
1011 clone_info->channel=image_info->channel;
1012 (void) CloneImageOptions(clone_info,image_info);
1013 clone_info->debug=image_info->debug;
1014 clone_info->signature=image_info->signature;
1051MagickExport MagickBooleanType CopyImagePixels(Image *image,
1052 const Image *source_image,
const RectangleInfo *geometry,
1053 const OffsetInfo *offset,ExceptionInfo *exception)
1055#define CopyImageTag "Copy/Image"
1070 assert(image != (Image *) NULL);
1071 assert(source_image != (Image *) NULL);
1072 assert(geometry != (RectangleInfo *) NULL);
1073 assert(offset != (OffsetInfo *) NULL);
1074 if (IsEventLogging() != MagickFalse)
1075 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1076 if ((offset->x < 0) || (offset->y < 0) ||
1077 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1078 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1079 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1081 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1082 return(MagickFalse);
1088 source_view=AcquireVirtualCacheView(source_image,exception);
1089 image_view=AcquireAuthenticCacheView(image,exception);
1090#if defined(MAGICKCORE_OPENMP_SUPPORT)
1091 #pragma omp parallel for schedule(static) shared(progress,status) \
1092 magick_number_threads(image,source_image,geometry->height,2)
1094 for (y=0; y < (ssize_t) geometry->height; y++)
1108 if (status == MagickFalse)
1110 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1111 geometry->width,1,exception);
1112 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1113 geometry->width,1,exception);
1114 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1119 for (x=0; x < (ssize_t) geometry->width; x++)
1124 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1126 PixelChannel channel = GetPixelChannelChannel(image,i);
1127 PixelTrait traits = GetPixelChannelTraits(image,channel);
1128 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1129 if ((traits == UndefinedPixelTrait) ||
1130 ((traits & UpdatePixelTrait) == 0) ||
1131 (source_traits == UndefinedPixelTrait))
1133 SetPixelChannel(image,channel,p[i],q);
1135 p+=(ptrdiff_t) GetPixelChannels(source_image);
1136 q+=(ptrdiff_t) GetPixelChannels(image);
1138 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1139 if (sync == MagickFalse)
1141 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1146#if defined(MAGICKCORE_OPENMP_SUPPORT)
1150 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1151 if (proceed == MagickFalse)
1155 source_view=DestroyCacheView(source_view);
1156 image_view=DestroyCacheView(image_view);
1183MagickExport Image *DestroyImage(Image *image)
1191 assert(image != (Image *) NULL);
1192 assert(image->signature == MagickCoreSignature);
1193 if (IsEventLogging() != MagickFalse)
1194 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1195 destroy=MagickFalse;
1196 LockSemaphoreInfo(image->semaphore);
1197 image->reference_count--;
1198 if (image->reference_count == 0)
1200 UnlockSemaphoreInfo(image->semaphore);
1201 if (destroy == MagickFalse)
1202 return((Image *) NULL);
1206 DestroyImagePixels(image);
1207 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1208 if (image->montage != (
char *) NULL)
1209 image->montage=DestroyString(image->montage);
1210 if (image->directory != (
char *) NULL)
1211 image->directory=DestroyString(image->directory);
1212 if (image->colormap != (PixelInfo *) NULL)
1213 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1214 if (image->geometry != (
char *) NULL)
1215 image->geometry=DestroyString(image->geometry);
1216 DestroyImageProfiles(image);
1217 DestroyImageProperties(image);
1218 DestroyImageArtifacts(image);
1219 if (image->ascii85 != (Ascii85Info *) NULL)
1220 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1221 if (image->image_info != (ImageInfo *) NULL)
1222 image->image_info=DestroyImageInfo(image->image_info);
1225 RelinquishSemaphoreInfo(&image->semaphore);
1226 image->signature=(~MagickCoreSignature);
1227 image=(Image *) RelinquishMagickMemory(image);
1254MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1256 assert(image_info != (ImageInfo *) NULL);
1257 assert(image_info->signature == MagickCoreSignature);
1258 if (IsEventLogging() != MagickFalse)
1259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1260 image_info->filename);
1261 if (image_info->size != (
char *) NULL)
1262 image_info->size=DestroyString(image_info->size);
1263 if (image_info->extract != (
char *) NULL)
1264 image_info->extract=DestroyString(image_info->extract);
1265 if (image_info->scenes != (
char *) NULL)
1266 image_info->scenes=DestroyString(image_info->scenes);
1267 if (image_info->page != (
char *) NULL)
1268 image_info->page=DestroyString(image_info->page);
1269 if (image_info->sampling_factor != (
char *) NULL)
1270 image_info->sampling_factor=DestroyString(
1271 image_info->sampling_factor);
1272 if (image_info->server_name != (
char *) NULL)
1273 image_info->server_name=DestroyString(
1274 image_info->server_name);
1275 if (image_info->font != (
char *) NULL)
1276 image_info->font=DestroyString(image_info->font);
1277 if (image_info->texture != (
char *) NULL)
1278 image_info->texture=DestroyString(image_info->texture);
1279 if (image_info->density != (
char *) NULL)
1280 image_info->density=DestroyString(image_info->density);
1281 if (image_info->cache != (
void *) NULL)
1282 image_info->cache=DestroyPixelCache(image_info->cache);
1283 if (image_info->profile != (StringInfo *) NULL)
1284 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1285 image_info->profile);
1286 DestroyImageOptions(image_info);
1287 image_info->signature=(~MagickCoreSignature);
1288 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1316MagickExport
void DisassociateImageStream(Image *image)
1318 assert(image != (Image *) NULL);
1319 assert(image->signature == MagickCoreSignature);
1320 if (IsEventLogging() != MagickFalse)
1321 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1322 DisassociateBlob(image);
1347MagickExport
void GetImageInfo(ImageInfo *image_info)
1355 assert(image_info != (ImageInfo *) NULL);
1356 if (IsEventLogging() != MagickFalse)
1357 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1358 (void) memset(image_info,0,
sizeof(*image_info));
1359 image_info->adjoin=MagickTrue;
1360 image_info->interlace=NoInterlace;
1361 image_info->channel=AllChannels;
1362 image_info->quality=UndefinedCompressionQuality;
1363 image_info->antialias=MagickTrue;
1364 image_info->dither=MagickTrue;
1365 image_info->depth=0;
1366 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1367 if (synchronize != (
const char *) NULL)
1369 image_info->synchronize=IsStringTrue(synchronize);
1370 synchronize=DestroyString(synchronize);
1372 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1373 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1374 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1375 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1376 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1378 image_info->signature=MagickCoreSignature;
1403MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1405 return(image_info->file);
1433MagickExport Image *GetImageMask(
const Image *image,
const PixelMask type,
1434 ExceptionInfo *exception)
1452 assert(image != (Image *) NULL);
1453 assert(image->signature == MagickCoreSignature);
1454 if (IsEventLogging() != MagickFalse)
1455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1460 if ((image->channels & ReadMaskChannel) == 0)
1461 return((Image *) NULL);
1464 case WritePixelMask:
1466 if ((image->channels & WriteMaskChannel) == 0)
1467 return((Image *) NULL);
1472 if ((image->channels & CompositeMaskChannel) == 0)
1473 return((Image *) NULL);
1477 mask_image=AcquireImage((ImageInfo *) NULL,exception);
1478 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1479 if (status == MagickFalse)
1480 return(DestroyImage(mask_image));
1482 mask_image->alpha_trait=UndefinedPixelTrait;
1483 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1484 image_view=AcquireVirtualCacheView(image,exception);
1485 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1486#if defined(MAGICKCORE_OPENMP_SUPPORT)
1487 #pragma omp parallel for schedule(static) shared(status) \
1488 magick_number_threads(image,image,image->rows,2)
1490 for (y=0; y < (ssize_t) image->rows; y++)
1501 if (status == MagickFalse)
1503 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1504 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1506 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1511 for (x=0; x < (ssize_t) image->columns; x++)
1517 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1520 case WritePixelMask:
1522 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1527 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1531 p+=(ptrdiff_t) GetPixelChannels(image);
1532 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1534 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1537 mask_view=DestroyCacheView(mask_view);
1538 image_view=DestroyCacheView(image_view);
1539 if (status == MagickFalse)
1540 mask_image=DestroyImage(mask_image);
1566MagickExport ssize_t GetImageReferenceCount(Image *image)
1571 assert(image != (Image *) NULL);
1572 assert(image->signature == MagickCoreSignature);
1573 if (IsEventLogging() != MagickFalse)
1574 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1575 LockSemaphoreInfo(image->semaphore);
1576 reference_count=image->reference_count;
1577 UnlockSemaphoreInfo(image->semaphore);
1578 return(reference_count);
1605MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1607 assert(image != (Image *) NULL);
1608 assert(image->signature == MagickCoreSignature);
1609 if (IsEventLogging() != MagickFalse)
1610 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1611 return(GetPixelCacheVirtualMethod(image));
1649MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1650 Image *image,
const char *format,
int value,
char *filename,
1651 ExceptionInfo *exception)
1655 pattern[MagickPathExtent];
1663 assert(format != (
const char *) NULL);
1664 assert(filename != (
char *) NULL);
1665 (void) CopyMagickString(filename,format,MagickPathExtent);
1666 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1667 return(strlen(filename));
1668 while ((cursor=strchr(cursor,
'%')) != (
const char *) NULL)
1674 offset = (ssize_t) (cursor-format);
1688 if (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1689 (void) strtol(cursor,(
char **) &cursor,10);
1699 count=FormatLocaleString(pattern,
sizeof(pattern),q,value);
1700 if ((count <= 0) || (count >= MagickPathExtent) ||
1701 ((offset+count) >= MagickPathExtent))
1703 (void) CopyMagickString(p+offset,pattern,(
size_t) (MagickPathExtent-
1711 *end = strchr(cursor,
']'),
1712 *option = (
const char *) NULL;
1715 extent = (size_t) (end-cursor-1),
1722 if (end == (
const char *) NULL)
1724 if (extent >=
sizeof(pattern))
1726 (void) CopyMagickString(pattern,cursor+1,extent+1);
1727 pattern[extent]=
'\0';
1728 if (image != (Image *) NULL)
1730 option=GetImageProperty(image,pattern,exception);
1731 if (option == (
const char *) NULL)
1732 option=GetImageArtifact(image,pattern);
1734 if ((option == (
const char *) NULL) &&
1735 (image_info != (ImageInfo *) NULL))
1736 option=GetImageOption(image_info,pattern);
1737 if (option == (
const char *) NULL)
1739 option_length=strlen(option);
1740 tail_length=strlen(end+1);
1741 if ((offset+option_length+tail_length+1) > MagickPathExtent)
1743 (void) CopyMagickString(p+offset,option,(
size_t) (MagickPathExtent-
1745 (void) ConcatenateMagickString(p+offset+option_length,end+1,(
size_t) (
1746 MagickPathExtent-offset-option_length-tail_length-1));
1754 for (p=filename; *p !=
'\0'; )
1759 if ((*p ==
'%') && (*(p+1) ==
'%'))
1760 (void) memmove(p,p+1,strlen(p+1)+1);
1764 return(strlen(filename));
1794MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1795 ExceptionInfo *exception)
1797#if !defined(MAGICKCORE_HDRI_SUPPORT)
1800 return(MagickFalse);
1811 assert(image != (Image *) NULL);
1812 assert(image->signature == MagickCoreSignature);
1813 if (IsEventLogging() != MagickFalse)
1814 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1815 image_view=AcquireVirtualCacheView(image,exception);
1816#if defined(MAGICKCORE_OPENMP_SUPPORT)
1817 #pragma omp parallel for schedule(static) shared(hdri) \
1818 magick_number_threads(image,image,image->rows,2)
1820 for (y=0; y < (ssize_t) image->rows; y++)
1828 if (hdri != MagickFalse)
1830 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1831 if (p == (
const Quantum *) NULL)
1833 for (x=0; x < (ssize_t) image->columns; x++)
1838 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1846 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1847 if (traits == UndefinedPixelTrait)
1849 pixel=(double) p[i];
1850 if ((pixel < 0.0) || (pixel > (
double) QuantumRange) ||
1851 (pixel != (
double) ((QuantumAny) pixel)))
1857 if (hdri != MagickFalse)
1859 p+=(ptrdiff_t) GetPixelChannels(image);
1862 image_view=DestroyCacheView(image_view);
1890MagickExport MagickBooleanType IsImageObject(
const Image *image)
1895 assert(image != (Image *) NULL);
1896 if (IsEventLogging() != MagickFalse)
1897 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1898 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1899 if (p->signature != MagickCoreSignature)
1900 return(MagickFalse);
1927MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1930 magick[MagickPathExtent],
1931 filename[MagickPathExtent];
1936 assert(image != (Image *) NULL);
1937 assert(image->signature == MagickCoreSignature);
1938 if (IsEventLogging() != MagickFalse)
1939 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1940 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1941 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1942 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1944 if (p->taint != MagickFalse)
1946 if (LocaleCompare(p->magick,magick) != 0)
1948 if (LocaleCompare(p->filename,filename) != 0)
1951 return(MagickFalse);
1980MagickExport MagickBooleanType ModifyImage(Image **image,
1981 ExceptionInfo *exception)
1986 assert(image != (Image **) NULL);
1987 assert(*image != (Image *) NULL);
1988 assert((*image)->signature == MagickCoreSignature);
1989 if (IsEventLogging() != MagickFalse)
1990 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
1991 if (GetImageReferenceCount(*image) <= 1)
1993 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1994 LockSemaphoreInfo((*image)->semaphore);
1995 (*image)->reference_count--;
1996 UnlockSemaphoreInfo((*image)->semaphore);
2034MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2035 const size_t width,
const size_t height,
const PixelInfo *background,
2036 ExceptionInfo *exception)
2050 assert(image_info != (
const ImageInfo *) NULL);
2051 assert(image_info->signature == MagickCoreSignature);
2052 assert(background != (
const PixelInfo *) NULL);
2053 if (IsEventLogging() != MagickFalse)
2054 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2055 image=AcquireImage(image_info,exception);
2056 image->columns=width;
2058 image->colorspace=background->colorspace;
2059 image->alpha_trait=background->alpha_trait;
2060 image->fuzz=background->fuzz;
2061 image->depth=background->depth;
2063 image_view=AcquireAuthenticCacheView(image,exception);
2064#if defined(MAGICKCORE_OPENMP_SUPPORT)
2065 #pragma omp parallel for schedule(static) shared(status) \
2066 magick_number_threads(image,image,image->rows,2)
2068 for (y=0; y < (ssize_t) image->rows; y++)
2076 if (status == MagickFalse)
2078 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2079 if (q == (Quantum *) NULL)
2084 for (x=0; x < (ssize_t) image->columns; x++)
2086 SetPixelViaPixelInfo(image,background,q);
2087 q+=(ptrdiff_t) GetPixelChannels(image);
2089 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2092 image_view=DestroyCacheView(image_view);
2093 if (status == MagickFalse)
2094 image=DestroyImage(image);
2121MagickExport Image *ReferenceImage(Image *image)
2123 assert(image != (Image *) NULL);
2124 assert(image->signature == MagickCoreSignature);
2125 if (IsEventLogging() != MagickFalse)
2126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2127 LockSemaphoreInfo(image->semaphore);
2128 image->reference_count++;
2129 UnlockSemaphoreInfo(image->semaphore);
2157MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2165 assert(image != (Image *) NULL);
2166 assert(image->signature == MagickCoreSignature);
2167 if (IsEventLogging() != MagickFalse)
2168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2169 flags=ParseAbsoluteGeometry(page,&geometry);
2170 if ((flags & WidthValue) != 0)
2172 if ((flags & HeightValue) == 0)
2173 geometry.height=geometry.width;
2174 image->page.width=geometry.width;
2175 image->page.height=geometry.height;
2177 if ((flags & AspectValue) != 0)
2179 if ((flags & XValue) != 0)
2180 image->page.x+=geometry.x;
2181 if ((flags & YValue) != 0)
2182 image->page.y+=geometry.y;
2186 if ((flags & XValue) != 0)
2188 image->page.x=geometry.x;
2189 if ((image->page.width == 0) && (geometry.x > 0))
2190 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2192 if ((flags & YValue) != 0)
2194 image->page.y=geometry.y;
2195 if ((image->page.height == 0) && (geometry.y > 0))
2196 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2228MagickExport MagickBooleanType ResetImagePixels(Image *image,
2229 ExceptionInfo *exception)
2246 assert(image != (Image *) NULL);
2247 assert(image->signature == MagickCoreSignature);
2248 if (IsEventLogging() != MagickFalse)
2249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2250 pixels=AcquirePixelCachePixels(image,&length,exception);
2251 if (pixels != (
void *) NULL)
2256 (void) memset(pixels,0,length);
2263 image_view=AcquireAuthenticCacheView(image,exception);
2264#if defined(MAGICKCORE_OPENMP_SUPPORT)
2265 #pragma omp parallel for schedule(static) shared(status) \
2266 magick_number_threads(image,image,image->rows,2)
2268 for (y=0; y < (ssize_t) image->rows; y++)
2276 if (status == MagickFalse)
2278 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2279 if (q == (Quantum *) NULL)
2284 for (x=0; x < (ssize_t) image->columns; x++)
2286 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2287 q+=(ptrdiff_t) GetPixelChannels(image);
2289 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2292 image_view=DestroyCacheView(image_view);
2324MagickExport MagickBooleanType SetImageAlpha(Image *image,
const Quantum alpha,
2325 ExceptionInfo *exception)
2336 assert(image != (Image *) NULL);
2337 assert(image->signature == MagickCoreSignature);
2338 if (IsEventLogging() != MagickFalse)
2339 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2340 image->alpha_trait=BlendPixelTrait;
2342 image_view=AcquireAuthenticCacheView(image,exception);
2343#if defined(MAGICKCORE_OPENMP_SUPPORT)
2344 #pragma omp parallel for schedule(static) shared(status) \
2345 magick_number_threads(image,image,image->rows,2)
2347 for (y=0; y < (ssize_t) image->rows; y++)
2355 if (status == MagickFalse)
2357 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2358 if (q == (Quantum *) NULL)
2363 for (x=0; x < (ssize_t) image->columns; x++)
2365 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2366 SetPixelAlpha(image,alpha,q);
2367 q+=(ptrdiff_t) GetPixelChannels(image);
2369 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2372 image_view=DestroyCacheView(image_view);
2403MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2404 ExceptionInfo *exception)
2418 assert(image != (Image *) NULL);
2419 assert(image->signature == MagickCoreSignature);
2420 if (IsEventLogging() != MagickFalse)
2421 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2422 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2423 return(MagickFalse);
2424 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2425 ((image->alpha_trait & BlendPixelTrait) == 0))
2426 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2427 ConformPixelInfo(image,&image->background_color,&background,exception);
2432 image_view=AcquireAuthenticCacheView(image,exception);
2433#if defined(MAGICKCORE_OPENMP_SUPPORT)
2434 #pragma omp parallel for schedule(static) shared(status) \
2435 magick_number_threads(image,image,image->rows,2)
2437 for (y=0; y < (ssize_t) image->rows; y++)
2445 if (status == MagickFalse)
2447 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2448 if (q == (Quantum *) NULL)
2453 for (x=0; x < (ssize_t) image->columns; x++)
2455 SetPixelViaPixelInfo(image,&background,q);
2456 q+=(ptrdiff_t) GetPixelChannels(image);
2458 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2461 image_view=DestroyCacheView(image_view);
2491MagickExport ChannelType SetImageChannelMask(Image *image,
2492 const ChannelType channel_mask)
2494 return(SetPixelChannelMask(image,channel_mask));
2524MagickExport MagickBooleanType SetImageColor(Image *image,
2525 const PixelInfo *color,ExceptionInfo *exception)
2536 assert(image != (Image *) NULL);
2537 assert(image->signature == MagickCoreSignature);
2538 assert(color != (
const PixelInfo *) NULL);
2539 if (IsEventLogging() != MagickFalse)
2540 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2541 image->colorspace=color->colorspace;
2542 image->alpha_trait=color->alpha_trait;
2543 image->fuzz=color->fuzz;
2544 image->depth=color->depth;
2546 image_view=AcquireAuthenticCacheView(image,exception);
2547#if defined(MAGICKCORE_OPENMP_SUPPORT)
2548 #pragma omp parallel for schedule(static) shared(status) \
2549 magick_number_threads(image,image,image->rows,2)
2551 for (y=0; y < (ssize_t) image->rows; y++)
2559 if (status == MagickFalse)
2561 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2562 if (q == (Quantum *) NULL)
2567 for (x=0; x < (ssize_t) image->columns; x++)
2569 SetPixelViaPixelInfo(image,color,q);
2570 q+=(ptrdiff_t) GetPixelChannels(image);
2572 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2575 image_view=DestroyCacheView(image_view);
2607MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2608 const ClassType storage_class,ExceptionInfo *exception)
2610 assert(image != (Image *) NULL);
2611 assert(image->signature == MagickCoreSignature);
2612 assert(exception != (ExceptionInfo *) NULL);
2613 assert(exception->signature == MagickCoreSignature);
2614 if (IsEventLogging() != MagickFalse)
2615 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2616 image->storage_class=storage_class;
2617 return(SyncImagePixelCache(image,exception));
2649MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2650 const size_t rows,ExceptionInfo *exception)
2652 if ((columns == 0) || (rows == 0))
2653 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2654 image->columns=columns;
2656 if (image->depth == 0)
2659 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2660 "ImageDepthNotSupported",
"`%s'",image->filename);
2662 if (image->depth > (8*
sizeof(MagickSizeType)))
2664 image->depth=8*
sizeof(MagickSizeType);
2665 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2666 "ImageDepthNotSupported",
"`%s'",image->filename);
2668 return(SyncImagePixelCache(image,exception));
2706static const MagickInfo *SetImageInfoFromExtension(ImageInfo *image_info,
2707 const char *component,
char *magic,ExceptionInfo *exception)
2719 *format_type_formats[] =
2743 (void) CopyMagickString(magic,component,MagickPathExtent);
2748 format_type=UndefinedFormatType;
2749 magick_info=GetMagickInfo(magic,exception);
2750 if ((magick_info != (
const MagickInfo *) NULL) &&
2751 (magick_info->format_type != UndefinedFormatType))
2752 format_type=magick_info->format_type;
2754 while ((format_type == UndefinedFormatType) &&
2755 (format_type_formats[i] != (
char *) NULL))
2757 if ((*magic == *format_type_formats[i]) &&
2758 (LocaleCompare(magic,format_type_formats[i]) == 0))
2759 format_type=ExplicitFormatType;
2762 if (format_type == UndefinedFormatType)
2763 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2765 if (format_type == ExplicitFormatType)
2767 image_info->affirm=MagickTrue;
2768 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2770 if (LocaleCompare(magic,
"RGB") == 0)
2771 image_info->affirm=MagickFalse;
2772 return(magick_info);
2775MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2776 const unsigned int frames,ExceptionInfo *exception)
2779 component[MagickPathExtent],
2780 magic[MagickPathExtent],
2781 path[MagickPathExtent],
2808 assert(image_info != (ImageInfo *) NULL);
2809 assert(image_info->signature == MagickCoreSignature);
2810 if (IsEventLogging() != MagickFalse)
2811 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2812 image_info->filename);
2814 GetPathComponent(image_info->filename,SubimagePath,component);
2815 if (*component !=
'\0')
2820 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2822 if (IsGeometry(component) != MagickFalse)
2823 (void) CloneString(&image_info->extract,component);
2831 (void) CloneString(&image_info->scenes,component);
2832 image_info->scene=StringToUnsignedLong(image_info->scenes);
2833 image_info->number_scenes=image_info->scene;
2834 p=image_info->scenes;
2835 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2837 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2839 first=(size_t) strtol(p,&q,10);
2841 while (isspace((
int) ((
unsigned char) *q)) != 0)
2844 last=(size_t) strtol(q+1,&q,10);
2847 if (first < image_info->scene)
2848 image_info->scene=first;
2849 if (last > image_info->number_scenes)
2850 image_info->number_scenes=last;
2853 image_info->number_scenes-=image_info->scene-1;
2857 if (*image_info->magick ==
'\0')
2858 GetPathComponent(image_info->filename,ExtensionPath,component);
2859 if (*component !=
'\0')
2864 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2865 GetPathComponent(path,ExtensionPath,component);
2867 image_info->affirm=MagickFalse;
2868 sans_exception=AcquireExceptionInfo();
2869 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2870 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2876 GetPathComponent(image_info->filename,MagickPath,magic);
2879 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2880 magick_info=GetMagickInfo(magic,sans_exception);
2881 if ((magick_info != (
const MagickInfo *) NULL) &&
2882 (magick_info->format_type == ExplicitFormatType))
2883 image_info->affirm=MagickTrue;
2885 GetPathComponent(image_info->filename,CanonicalPath,component);
2887 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2888 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2899 magick_info=GetMagickInfo(magic,sans_exception);
2900 delegate_info=(
const DelegateInfo *) NULL;
2901 if (magick_info == (
const MagickInfo *) NULL)
2903 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2904 if (delegate_info == (
const DelegateInfo *) NULL)
2905 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2906 if ((delegate_info == (
const DelegateInfo *) NULL) &&
2907 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2912 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2916 if (((magick_info != (
const MagickInfo *) NULL) ||
2917 (delegate_info != (
const DelegateInfo *) NULL)) &&
2918 (IsMagickConflict(magic) == MagickFalse))
2920 image_info->affirm=MagickTrue;
2921 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2922 GetPathComponent(image_info->filename,CanonicalPath,component);
2923 (void) CopyMagickString(image_info->filename,component,
2927 sans_exception=DestroyExceptionInfo(sans_exception);
2928 if ((magick_info == (
const MagickInfo *) NULL) ||
2929 (GetMagickEndianSupport(magick_info) == MagickFalse))
2930 image_info->endian=UndefinedEndian;
2931 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2936 (void) InterpretImageFilename(image_info,(Image *) NULL,
2937 image_info->filename,(
int) image_info->scene,component,exception);
2938 if ((LocaleCompare(component,image_info->filename) != 0) &&
2939 (strchr(component,
'%') == (
char *) NULL))
2940 image_info->adjoin=MagickFalse;
2942 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2947 magick_info=GetMagickInfo(magic,exception);
2948 if (magick_info != (
const MagickInfo *) NULL)
2949 if (GetMagickAdjoin(magick_info) == MagickFalse)
2950 image_info->adjoin=MagickFalse;
2952 if (image_info->affirm != MagickFalse)
2965 magick_size=GetMagicPatternExtent(exception);
2966 if (magick_size == 0)
2967 return(MagickFalse);
2968 image=AcquireImage(image_info,exception);
2969 (void) CopyMagickString(image->filename,image_info->filename,
2971 sans_exception=AcquireExceptionInfo();
2972 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
2973 sans_exception=DestroyExceptionInfo(sans_exception);
2974 if (status == MagickFalse)
2976 image=DestroyImage(image);
2977 return(MagickFalse);
2979 if ((IsBlobSeekable(image) == MagickFalse) ||
2980 (IsBlobExempt(image) != MagickFalse))
2986 status=ImageToFile(image,component,exception);
2987 if (CloseBlob(image) == MagickFalse)
2989 if (status == MagickFalse)
2991 (void) RelinquishUniqueFileResource(component);
2992 image=DestroyImage(image);
2993 return(MagickFalse);
2995 SetImageInfoFile(image_info,(FILE *) NULL);
2996 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2997 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2998 if (status == MagickFalse)
3000 (void) RelinquishUniqueFileResource(component);
3001 image=DestroyImage(image);
3002 return(MagickFalse);
3004 (void) CopyMagickString(image_info->filename,component,
3006 image_info->temporary=MagickTrue;
3008 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3009 if (magick == (
unsigned char *) NULL)
3011 (void) CloseBlob(image);
3012 image=DestroyImage(image);
3013 return(MagickFalse);
3015 (void) memset(magick,0,magick_size);
3016 count=ReadBlob(image,magick_size,magick);
3017 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3018 (void) CloseBlob(image);
3019 image=DestroyImage(image);
3023 sans_exception=AcquireExceptionInfo();
3024 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3025 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3026 if ((magic_info != (
const MagicInfo *) NULL) &&
3027 (GetMagicName(magic_info) != (
char *) NULL))
3032 if ((magick_info != (
const MagickInfo *) NULL) &&
3033 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3034 (LocaleCompare(magick_info->magick_module,GetMagicName(
3036 (void) CopyMagickString(image_info->magick,magick_info->name,
3040 (void) CopyMagickString(image_info->magick,GetMagicName(
3041 magic_info),MagickPathExtent);
3042 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3044 if ((magick_info == (
const MagickInfo *) NULL) ||
3045 (GetMagickEndianSupport(magick_info) == MagickFalse))
3046 image_info->endian=UndefinedEndian;
3047 sans_exception=DestroyExceptionInfo(sans_exception);
3050 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3051 if ((magick_info == (
const MagickInfo *) NULL) ||
3052 (GetMagickEndianSupport(magick_info) == MagickFalse))
3053 image_info->endian=UndefinedEndian;
3054 sans_exception=DestroyExceptionInfo(sans_exception);
3086MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3087 const size_t length)
3089 assert(image_info != (ImageInfo *) NULL);
3090 assert(image_info->signature == MagickCoreSignature);
3091 if (IsEventLogging() != MagickFalse)
3092 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3093 image_info->filename);
3094 image_info->blob=(
void *) blob;
3095 image_info->length=length;
3123MagickExport
void SetImageInfoCustomStream(ImageInfo *image_info,
3124 CustomStreamInfo *custom_stream)
3126 assert(image_info != (ImageInfo *) NULL);
3127 assert(image_info->signature == MagickCoreSignature);
3128 if (IsEventLogging() != MagickFalse)
3129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3130 image_info->filename);
3131 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3158MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3160 assert(image_info != (ImageInfo *) NULL);
3161 assert(image_info->signature == MagickCoreSignature);
3162 if (IsEventLogging() != MagickFalse)
3163 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3164 image_info->filename);
3165 image_info->file=file;
3198MagickExport MagickBooleanType SetImageMask(Image *image,
const PixelMask type,
3199 const Image *mask,ExceptionInfo *exception)
3214 assert(image != (Image *) NULL);
3215 if (IsEventLogging() != MagickFalse)
3216 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3217 assert(image->signature == MagickCoreSignature);
3218 if (mask == (
const Image *) NULL)
3224 image->channels=(ChannelType) ((
unsigned int) image->channels &
3225 (
unsigned int) ~ReadMaskChannel);
3228 case WritePixelMask:
3230 image->channels=(ChannelType) ((
unsigned int) image->channels &
3231 (
unsigned int) ~WriteMaskChannel);
3236 image->channels=(ChannelType) ((
unsigned int) image->channels &
3237 (
unsigned int) ~CompositeMaskChannel);
3241 return(SyncImagePixelCache(image,exception));
3247 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3250 case WritePixelMask:
3252 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3257 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3261 if (SyncImagePixelCache(image,exception) == MagickFalse)
3262 return(MagickFalse);
3264 image->mask_trait=UpdatePixelTrait;
3265 mask_view=AcquireVirtualCacheView(mask,exception);
3266 image_view=AcquireAuthenticCacheView(image,exception);
3267#if defined(MAGICKCORE_OPENMP_SUPPORT)
3268 #pragma omp parallel for schedule(static) shared(status) \
3269 magick_number_threads(mask,image,image->rows,2)
3271 for (y=0; y < (ssize_t) image->rows; y++)
3282 if (status == MagickFalse)
3284 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3285 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3286 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3291 for (x=0; x < (ssize_t) image->columns; x++)
3297 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3298 intensity=GetPixelIntensity(mask,p);
3303 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3306 case WritePixelMask:
3308 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3313 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3317 p+=(ptrdiff_t) GetPixelChannels(mask);
3318 q+=(ptrdiff_t) GetPixelChannels(image);
3320 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3323 image->mask_trait=UndefinedPixelTrait;
3324 mask_view=DestroyCacheView(mask_view);
3325 image_view=DestroyCacheView(image_view);
3359MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3360 const PixelMask type,
const RectangleInfo *region,ExceptionInfo *exception)
3374 assert(image != (Image *) NULL);
3375 assert(image->signature == MagickCoreSignature);
3376 if (IsEventLogging() != MagickFalse)
3377 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3378 if (region == (
const RectangleInfo *) NULL)
3384 image->channels=(ChannelType) ((
unsigned int) image->channels &
3385 (
unsigned int) ~ReadMaskChannel);
3388 case WritePixelMask:
3390 image->channels=(ChannelType) ((
unsigned int) image->channels &
3391 (
unsigned int) ~WriteMaskChannel);
3396 image->channels=(ChannelType) ((
unsigned int) image->channels &
3397 (
unsigned int) ~CompositeMaskChannel);
3401 return(SyncImagePixelCache(image,exception));
3407 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3410 case WritePixelMask:
3412 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3417 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3421 if (SyncImagePixelCache(image,exception) == MagickFalse)
3422 return(MagickFalse);
3424 image->mask_trait=UpdatePixelTrait;
3425 image_view=AcquireAuthenticCacheView(image,exception);
3426#if defined(MAGICKCORE_OPENMP_SUPPORT)
3427 #pragma omp parallel for schedule(static) shared(status) \
3428 magick_number_threads(image,image,image->rows,2)
3430 for (y=0; y < (ssize_t) image->rows; y++)
3438 if (status == MagickFalse)
3440 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3441 if (q == (Quantum *) NULL)
3446 for (x=0; x < (ssize_t) image->columns; x++)
3452 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3453 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3459 SetPixelReadMask(image,pixel,q);
3462 case WritePixelMask:
3464 SetPixelWriteMask(image,pixel,q);
3469 SetPixelCompositeMask(image,pixel,q);
3473 q+=(ptrdiff_t) GetPixelChannels(image);
3475 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3478 image->mask_trait=UndefinedPixelTrait;
3479 image_view=DestroyCacheView(image_view);
3512MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3513 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3515 assert(image != (
const Image *) NULL);
3516 assert(image->signature == MagickCoreSignature);
3517 if (IsEventLogging() != MagickFalse)
3518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3519 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3557static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3558 const ssize_t offset,ExceptionInfo *exception)
3585 if (images->previous == (Image *) NULL)
3588 SetGeometry(smush_image,&right_geometry);
3589 GravityAdjustGeometry(right_image->columns,right_image->rows,
3590 right_image->gravity,&right_geometry);
3591 left_image=images->previous;
3592 SetGeometry(smush_image,&left_geometry);
3593 GravityAdjustGeometry(left_image->columns,left_image->rows,
3594 left_image->gravity,&left_geometry);
3595 gap=right_image->columns;
3596 left_view=AcquireVirtualCacheView(left_image,exception);
3597 right_view=AcquireVirtualCacheView(right_image,exception);
3598 for (y=0; y < (ssize_t) smush_image->rows; y++)
3600 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3602 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3603 if ((p == (
const Quantum *) NULL) ||
3604 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3605 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3608 i=(ssize_t) left_image->columns-x-1;
3609 for (x=0; x < (ssize_t) right_image->columns; x++)
3611 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3613 if ((p == (
const Quantum *) NULL) ||
3614 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3615 ((x+i) >= (ssize_t) gap))
3618 if ((x+i) < (ssize_t) gap)
3621 right_view=DestroyCacheView(right_view);
3622 left_view=DestroyCacheView(left_view);
3623 if (y < (ssize_t) smush_image->rows)
3625 return((ssize_t) gap-offset);
3628static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3629 const ssize_t offset,ExceptionInfo *exception)
3656 if (images->previous == (Image *) NULL)
3658 bottom_image=images;
3659 SetGeometry(smush_image,&bottom_geometry);
3660 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3661 bottom_image->gravity,&bottom_geometry);
3662 top_image=images->previous;
3663 SetGeometry(smush_image,&top_geometry);
3664 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3666 gap=bottom_image->rows;
3667 top_view=AcquireVirtualCacheView(top_image,exception);
3668 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3669 for (x=0; x < (ssize_t) smush_image->columns; x++)
3671 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3673 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3674 if ((p == (
const Quantum *) NULL) ||
3675 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3676 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3679 i=(ssize_t) top_image->rows-y-1;
3680 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3682 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3684 if ((p == (
const Quantum *) NULL) ||
3685 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3686 ((y+i) >= (ssize_t) gap))
3689 if ((y+i) < (ssize_t) gap)
3692 bottom_view=DestroyCacheView(bottom_view);
3693 top_view=DestroyCacheView(top_view);
3694 if (x < (ssize_t) smush_image->columns)
3696 return((ssize_t) gap-offset);
3699MagickExport Image *SmushImages(
const Image *images,
3700 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3702#define SmushImageTag "Smush/Image"
3738 assert(images != (Image *) NULL);
3739 assert(images->signature == MagickCoreSignature);
3740 assert(exception != (ExceptionInfo *) NULL);
3741 assert(exception->signature == MagickCoreSignature);
3742 if (IsEventLogging() != MagickFalse)
3743 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3745 alpha_trait=image->alpha_trait;
3747 width=image->columns;
3749 next=GetNextImageInList(image);
3750 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3752 if (next->alpha_trait != UndefinedPixelTrait)
3753 alpha_trait=BlendPixelTrait;
3755 if (stack != MagickFalse)
3757 if (next->columns > width)
3758 width=next->columns;
3760 if (next->previous != (Image *) NULL)
3761 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3764 width+=next->columns;
3765 if (next->previous != (Image *) NULL)
3766 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3767 if (next->rows > height)
3773 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3774 if (smush_image == (Image *) NULL)
3775 return((Image *) NULL);
3776 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3778 smush_image=DestroyImage(smush_image);
3779 return((Image *) NULL);
3781 smush_image->alpha_trait=alpha_trait;
3782 (void) SetImageBackgroundColor(smush_image,exception);
3786 for (n=0; n < (MagickOffsetType) number_images; n++)
3788 SetGeometry(smush_image,&geometry);
3789 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3790 if (stack != MagickFalse)
3792 x_offset-=geometry.x;
3793 y_offset-=SmushYGap(smush_image,image,offset,exception);
3797 x_offset-=SmushXGap(smush_image,image,offset,exception);
3798 y_offset-=geometry.y;
3800 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3801 y_offset,exception);
3802 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3803 if (proceed == MagickFalse)
3805 if (stack == MagickFalse)
3807 x_offset+=(ssize_t) image->columns;
3813 y_offset+=(ssize_t) image->rows;
3815 image=GetNextImageInList(image);
3817 if (stack == MagickFalse)
3818 smush_image->columns=(size_t) x_offset;
3820 smush_image->rows=(size_t) y_offset;
3821 if (status == MagickFalse)
3822 smush_image=DestroyImage(smush_image);
3823 return(smush_image);
3850MagickExport MagickBooleanType StripImage(Image *image,
3851 ExceptionInfo *magick_unused(exception))
3856 magick_unreferenced(exception);
3857 assert(image != (Image *) NULL);
3858 if (IsEventLogging() != MagickFalse)
3859 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3860 DestroyImageProfiles(image);
3861 (void) DeleteImageProperty(image,
"comment");
3862 (void) DeleteImageProperty(image,
"date:create");
3863 (void) DeleteImageProperty(image,
"date:modify");
3864 (void) DeleteImageProperty(image,
"date:timestamp");
3865 status=SetImageArtifact(image,
"png:exclude-chunk",
3866 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3896static inline Quantum PushColormapIndex(Image *image,
const Quantum index,
3897 MagickBooleanType *range_exception)
3899 if ((
size_t) index < image->colors)
3901 *range_exception=MagickTrue;
3902 return((Quantum) 0);
3905MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3918 assert(image != (Image *) NULL);
3919 assert(image->signature == MagickCoreSignature);
3920 if (IsEventLogging() != MagickFalse)
3921 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3922 if (image->ping != MagickFalse)
3924 if (image->storage_class != PseudoClass)
3925 return(MagickFalse);
3926 assert(image->colormap != (PixelInfo *) NULL);
3927 range_exception=MagickFalse;
3930 image_view=AcquireAuthenticCacheView(image,exception);
3931#if defined(MAGICKCORE_OPENMP_SUPPORT)
3932 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3933 magick_number_threads(image,image,image->rows,2)
3935 for (y=0; y < (ssize_t) image->rows; y++)
3946 if (status == MagickFalse)
3948 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3949 if (q == (Quantum *) NULL)
3954 for (x=0; x < (ssize_t) image->columns; x++)
3956 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3957 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3958 q+=(ptrdiff_t) GetPixelChannels(image);
3960 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3963 image_view=DestroyCacheView(image_view);
3965 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3966 (void) ThrowMagickException(exception,GetMagickModule(),
3967 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4008MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4009 Image *images,ExceptionInfo *exception)
4014 assert(image_info != (
const ImageInfo *) NULL);
4015 assert(image_info->signature == MagickCoreSignature);
4016 assert(images != (Image *) NULL);
4017 assert(images->signature == MagickCoreSignature);
4018 if (IsEventLogging() != MagickFalse)
4019 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4021 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4022 (
void) SyncImageSettings(image_info,image,exception);
4023 (void) DeleteImageOption(image_info,
"page");
4027MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4028 Image *image,ExceptionInfo *exception)
4045 assert(image_info != (
const ImageInfo *) NULL);
4046 assert(image_info->signature == MagickCoreSignature);
4047 assert(image != (Image *) NULL);
4048 assert(image->signature == MagickCoreSignature);
4049 if (IsEventLogging() != MagickFalse)
4050 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4051 option=GetImageOption(image_info,
"background");
4052 if (option != (
const char *) NULL)
4053 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4055 option=GetImageOption(image_info,
"black-point-compensation");
4056 if (option != (
const char *) NULL)
4057 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4058 MagickBooleanOptions,MagickFalse,option);
4059 option=GetImageOption(image_info,
"blue-primary");
4060 if (option != (
const char *) NULL)
4062 flags=ParseGeometry(option,&geometry_info);
4063 if ((flags & RhoValue) != 0)
4064 image->chromaticity.blue_primary.x=geometry_info.rho;
4065 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4066 if ((flags & SigmaValue) != 0)
4067 image->chromaticity.blue_primary.y=geometry_info.sigma;
4069 option=GetImageOption(image_info,
"bordercolor");
4070 if (option != (
const char *) NULL)
4071 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4074 option=GetImageOption(image_info,
"compose");
4075 if (option != (
const char *) NULL)
4076 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4077 MagickFalse,option);
4079 option=GetImageOption(image_info,
"compress");
4080 if (option != (
const char *) NULL)
4081 image->compression=(CompressionType) ParseCommandOption(
4082 MagickCompressOptions,MagickFalse,option);
4083 option=GetImageOption(image_info,
"debug");
4084 if (option != (
const char *) NULL)
4085 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4086 MagickFalse,option);
4087 option=GetImageOption(image_info,
"density");
4088 if (option != (
const char *) NULL)
4090 flags=ParseGeometry(option,&geometry_info);
4091 if ((flags & RhoValue) != 0)
4092 image->resolution.x=geometry_info.rho;
4093 image->resolution.y=image->resolution.x;
4094 if ((flags & SigmaValue) != 0)
4095 image->resolution.y=geometry_info.sigma;
4097 option=GetImageOption(image_info,
"depth");
4098 if (option != (
const char *) NULL)
4099 image->depth=StringToUnsignedLong(option);
4100 option=GetImageOption(image_info,
"endian");
4101 if (option != (
const char *) NULL)
4102 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4103 MagickFalse,option);
4104 option=GetImageOption(image_info,
"filter");
4105 if (option != (
const char *) NULL)
4106 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4107 MagickFalse,option);
4108 option=GetImageOption(image_info,
"fuzz");
4109 if (option != (
const char *) NULL)
4110 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4111 option=GetImageOption(image_info,
"gravity");
4112 if (option != (
const char *) NULL)
4113 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4114 MagickFalse,option);
4115 option=GetImageOption(image_info,
"green-primary");
4116 if (option != (
const char *) NULL)
4118 flags=ParseGeometry(option,&geometry_info);
4119 if ((flags & RhoValue) != 0)
4120 image->chromaticity.green_primary.x=geometry_info.rho;
4121 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4122 if ((flags & SigmaValue) != 0)
4123 image->chromaticity.green_primary.y=geometry_info.sigma;
4125 option=GetImageOption(image_info,
"intent");
4126 if (option != (
const char *) NULL)
4127 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4128 MagickIntentOptions,MagickFalse,option);
4129 option=GetImageOption(image_info,
"intensity");
4130 if (option != (
const char *) NULL)
4131 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4132 MagickPixelIntensityOptions,MagickFalse,option);
4133 option=GetImageOption(image_info,
"interlace");
4134 if (option != (
const char *) NULL)
4135 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4136 MagickFalse,option);
4137 option=GetImageOption(image_info,
"interpolate");
4138 if (option != (
const char *) NULL)
4139 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4140 MagickInterpolateOptions,MagickFalse,option);
4141 option=GetImageOption(image_info,
"loop");
4142 if (option != (
const char *) NULL)
4143 image->iterations=StringToUnsignedLong(option);
4144 option=GetImageOption(image_info,
"mattecolor");
4145 if (option != (
const char *) NULL)
4146 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4148 option=GetImageOption(image_info,
"orient");
4149 if (option != (
const char *) NULL)
4150 image->orientation=(OrientationType) ParseCommandOption(
4151 MagickOrientationOptions,MagickFalse,option);
4152 option=GetImageOption(image_info,
"page");
4153 if (option != (
const char *) NULL)
4158 geometry=GetPageGeometry(option);
4159 flags=ParseAbsoluteGeometry(geometry,&image->page);
4160 geometry=DestroyString(geometry);
4162 option=GetImageOption(image_info,
"quality");
4163 if (option != (
const char *) NULL)
4164 image->quality=StringToUnsignedLong(option);
4165 option=GetImageOption(image_info,
"red-primary");
4166 if (option != (
const char *) NULL)
4168 flags=ParseGeometry(option,&geometry_info);
4169 if ((flags & RhoValue) != 0)
4170 image->chromaticity.red_primary.x=geometry_info.rho;
4171 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4172 if ((flags & SigmaValue) != 0)
4173 image->chromaticity.red_primary.y=geometry_info.sigma;
4175 if (image_info->quality != UndefinedCompressionQuality)
4176 image->quality=image_info->quality;
4177 option=GetImageOption(image_info,
"scene");
4178 if (option != (
const char *) NULL)
4179 image->scene=StringToUnsignedLong(option);
4180 option=GetImageOption(image_info,
"taint");
4181 if (option != (
const char *) NULL)
4182 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4183 MagickFalse,option);
4184 option=GetImageOption(image_info,
"tile-offset");
4185 if (option != (
const char *) NULL)
4190 geometry=GetPageGeometry(option);
4191 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4192 geometry=DestroyString(geometry);
4194 option=GetImageOption(image_info,
"transparent-color");
4195 if (option != (
const char *) NULL)
4196 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4198 option=GetImageOption(image_info,
"type");
4199 if (option != (
const char *) NULL)
4200 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4202 option=GetImageOption(image_info,
"units");
4203 units=image_info->units;
4204 if (option != (
const char *) NULL)
4205 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4206 MagickFalse,option);
4207 if (units != UndefinedResolution)
4209 if (image->units != units)
4210 switch (image->units)
4212 case PixelsPerInchResolution:
4214 if (units == PixelsPerCentimeterResolution)
4216 image->resolution.x/=2.54;
4217 image->resolution.y/=2.54;
4221 case PixelsPerCentimeterResolution:
4223 if (units == PixelsPerInchResolution)
4225 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4226 image->resolution.x+0.5))/100.0;
4227 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4228 image->resolution.y+0.5))/100.0;
4236 option=GetImageOption(image_info,
"density");
4237 if (option != (
const char *) NULL)
4239 flags=ParseGeometry(option,&geometry_info);
4240 if ((flags & RhoValue) != 0)
4241 image->resolution.x=geometry_info.rho;
4242 image->resolution.y=image->resolution.x;
4243 if ((flags & SigmaValue) != 0)
4244 image->resolution.y=geometry_info.sigma;
4247 option=GetImageOption(image_info,
"virtual-pixel");
4248 if (option != (
const char *) NULL)
4249 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4250 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4252 option=GetImageOption(image_info,
"white-point");
4253 if (option != (
const char *) NULL)
4255 flags=ParseGeometry(option,&geometry_info);
4256 if ((flags & RhoValue) != 0)
4257 image->chromaticity.white_point.x=geometry_info.rho;
4258 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4259 if ((flags & SigmaValue) != 0)
4260 image->chromaticity.white_point.y=geometry_info.sigma;
4268 if (image->image_info != (ImageInfo *) NULL)
4269 image->image_info=DestroyImageInfo(image->image_info);
4270 image->image_info=CloneImageInfo(image_info);