43#include "MagickCore/studio.h"
44#include "MagickCore/animate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/blob.h"
48#include "MagickCore/blob-private.h"
49#include "MagickCore/cache.h"
50#include "MagickCore/cache-private.h"
51#include "MagickCore/cache-view.h"
52#include "MagickCore/channel.h"
53#include "MagickCore/client.h"
54#include "MagickCore/color.h"
55#include "MagickCore/color-private.h"
56#include "MagickCore/colormap.h"
57#include "MagickCore/colorspace.h"
58#include "MagickCore/colorspace-private.h"
59#include "MagickCore/composite.h"
60#include "MagickCore/composite-private.h"
61#include "MagickCore/compress.h"
62#include "MagickCore/constitute.h"
63#include "MagickCore/delegate.h"
64#include "MagickCore/display.h"
65#include "MagickCore/draw.h"
66#include "MagickCore/enhance.h"
67#include "MagickCore/exception.h"
68#include "MagickCore/exception-private.h"
69#include "MagickCore/gem.h"
70#include "MagickCore/geometry.h"
71#include "MagickCore/histogram.h"
72#include "MagickCore/image-private.h"
73#include "MagickCore/list.h"
74#include "MagickCore/magic.h"
75#include "MagickCore/magick.h"
76#include "MagickCore/magick-private.h"
77#include "MagickCore/memory_.h"
78#include "MagickCore/memory-private.h"
79#include "MagickCore/module.h"
80#include "MagickCore/monitor.h"
81#include "MagickCore/monitor-private.h"
82#include "MagickCore/option.h"
83#include "MagickCore/paint.h"
84#include "MagickCore/pixel-accessor.h"
85#include "MagickCore/profile.h"
86#include "MagickCore/property.h"
87#include "MagickCore/quantize.h"
88#include "MagickCore/random_.h"
89#include "MagickCore/resource_.h"
90#include "MagickCore/segment.h"
91#include "MagickCore/semaphore.h"
92#include "MagickCore/signature-private.h"
93#include "MagickCore/statistic.h"
94#include "MagickCore/string_.h"
95#include "MagickCore/string-private.h"
96#include "MagickCore/thread-private.h"
97#include "MagickCore/threshold.h"
98#include "MagickCore/timer.h"
99#include "MagickCore/timer-private.h"
100#include "MagickCore/token.h"
101#include "MagickCore/token-private.h"
102#include "MagickCore/utility.h"
103#include "MagickCore/utility-private.h"
104#include "MagickCore/version.h"
105#include "MagickCore/xwindow-private.h"
152 if (IsEventLogging() != MagickFalse)
153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
154 image=(
Image *) AcquireCriticalMemory(
sizeof(*image));
155 (void) memset(image,0,
sizeof(*image));
159 (void) CopyMagickString(image->magick,
"MIFF",MagickPathExtent);
160 image->storage_class=DirectClass;
161 image->depth=MAGICKCORE_QUANTUM_DEPTH;
162 image->colorspace=sRGBColorspace;
163 image->rendering_intent=PerceptualIntent;
164 image->gamma=1.000/2.200;
165 image->chromaticity.red_primary.x=0.6400;
166 image->chromaticity.red_primary.y=0.3300;
167 image->chromaticity.red_primary.z=0.0300;
168 image->chromaticity.green_primary.x=0.3000;
169 image->chromaticity.green_primary.y=0.6000;
170 image->chromaticity.green_primary.z=0.1000;
171 image->chromaticity.blue_primary.x=0.1500;
172 image->chromaticity.blue_primary.y=0.0600;
173 image->chromaticity.blue_primary.z=0.7900;
174 image->chromaticity.white_point.x=0.3127;
175 image->chromaticity.white_point.y=0.3290;
176 image->chromaticity.white_point.z=0.3583;
177 image->interlace=NoInterlace;
178 image->ticks_per_second=UndefinedTicksPerSecond;
179 image->compose=OverCompositeOp;
180 GetPixelInfoRGBA(BackgroundColorRGBA,&image->background_color);
181 GetPixelInfoRGBA(BorderColorRGBA,&image->border_color);
182 GetPixelInfoRGBA(MatteColorRGBA,&image->matte_color);
183 GetPixelInfoRGBA(TransparentColorRGBA,&image->transparent_color);
184 GetTimerInfo(&image->timer);
185 image->cache=AcquirePixelCache(0);
186 image->channel_mask=AllChannels;
187 image->channel_map=AcquirePixelChannelMap();
188 image->blob=CloneBlobInfo((
BlobInfo *) NULL);
189 image->timestamp=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;
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,
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,
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,
429#define AppendImageTag "Append/Image"
441 homogeneous_colorspace,
470 assert(images != (
Image *) NULL);
471 assert(images->signature == MagickCoreSignature);
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);
689 return(ClipImagePath(image,
"#1",MagickTrue,exception));
692MagickExport MagickBooleanType ClipImagePath(
Image *image,
const char *pathname,
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);
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);
947 clone_info=AcquireImageInfo();
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,
1055#define CopyImageTag "Copy/Image"
1070 assert(image != (
Image *) NULL);
1071 assert(source_image != (
Image *) 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);
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);
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,
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));
1650static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1654 specifier = end[-1];
1662 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1663 return(MagickFalse);
1664 if ((length == 1) && (*start == specifier))
1673 if ((length >= 3) && (start[1] ==
'0'))
1674 return(MagickFalse);
1677 for ( ; i < (length-1); i++)
1678 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1679 return(MagickFalse);
1682 return(MagickFalse);
1685MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1686 Image *image,
const char *format,
int value,
char *filename,
1691 pattern[MagickPathExtent];
1696 assert(format != (
const char *) NULL);
1697 assert(filename != (
char *) NULL);
1698 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1700 (void) CopyMagickString(filename,format,MagickPathExtent);
1701 return(strlen(filename));
1703 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1721 specifier_start=cursor;
1722 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1724 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1727 *specifier_end = cursor+1;
1729 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1732 format_specifier[MagickPathExtent];
1735 length = cursor-specifier_start;
1740 (void) snprintf(format_specifier,
sizeof(format_specifier),
1741 "%%%.*s%c",(int) length,specifier_start,*cursor);
1742 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1744 if ((count <= 0) || ((p-filename+count) >= MagickPathExtent))
1746 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
1764 *end = strchr(cursor,
']'),
1765 *option = (
const char *) NULL;
1771 if (end == (
const char *) NULL)
1773 extent=(size_t) (end-cursor-1);
1774 if (extent >=
sizeof(pattern))
1776 (void) CopyMagickString(pattern,cursor+1,extent+1);
1777 pattern[extent]=
'\0';
1780 option=GetImageProperty(image,pattern,exception);
1781 if (option == (
const char *) NULL)
1782 option=GetImageArtifact(image,pattern);
1784 if ((option == (
const char *) NULL) &&
1786 option=GetImageOption(image_info,pattern);
1787 if (option == (
const char *) NULL)
1789 option_length=strlen(option);
1790 if ((p-filename+option_length) >= MagickPathExtent)
1792 (void) CopyMagickString(p,option,MagickPathExtent-(p-filename));
1801 if ((p-filename+1) >= MagickPathExtent)
1806 return(strlen(filename));
1836MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1839#if !defined(MAGICKCORE_HDRI_SUPPORT)
1842 return(MagickFalse);
1853 assert(image != (
Image *) NULL);
1854 assert(image->signature == MagickCoreSignature);
1855 if (IsEventLogging() != MagickFalse)
1856 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1857 image_view=AcquireVirtualCacheView(image,exception);
1858#if defined(MAGICKCORE_OPENMP_SUPPORT)
1859 #pragma omp parallel for schedule(static) shared(hdri) \
1860 magick_number_threads(image,image,image->rows,2)
1862 for (y=0; y < (ssize_t) image->rows; y++)
1870 if (hdri != MagickFalse)
1872 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1873 if (p == (
const Quantum *) NULL)
1875 for (x=0; x < (ssize_t) image->columns; x++)
1880 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1888 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1889 if (traits == UndefinedPixelTrait)
1891 pixel=(double) p[i];
1892 if ((pixel < 0.0) || (pixel > (double) QuantumRange) ||
1893 (pixel != (double) ((QuantumAny) pixel)))
1899 if (hdri != MagickFalse)
1901 p+=(ptrdiff_t) GetPixelChannels(image);
1904 image_view=DestroyCacheView(image_view);
1932MagickExport MagickBooleanType IsImageObject(
const Image *image)
1937 assert(image != (
Image *) NULL);
1938 if (IsEventLogging() != MagickFalse)
1939 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1940 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1941 if (p->signature != MagickCoreSignature)
1942 return(MagickFalse);
1969MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1972 magick[MagickPathExtent],
1973 filename[MagickPathExtent];
1978 assert(image != (
Image *) NULL);
1979 assert(image->signature == MagickCoreSignature);
1980 if (IsEventLogging() != MagickFalse)
1981 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1982 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1983 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1984 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1986 if (p->taint != MagickFalse)
1988 if (LocaleCompare(p->magick,magick) != 0)
1990 if (LocaleCompare(p->filename,filename) != 0)
1993 return(MagickFalse);
2022MagickExport MagickBooleanType ModifyImage(
Image **image,
2028 assert(image != (
Image **) NULL);
2029 assert(*image != (
Image *) NULL);
2030 assert((*image)->signature == MagickCoreSignature);
2031 if (IsEventLogging() != MagickFalse)
2032 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2033 if (GetImageReferenceCount(*image) <= 1)
2035 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2036 LockSemaphoreInfo((*image)->semaphore);
2037 (*image)->reference_count--;
2038 UnlockSemaphoreInfo((*image)->semaphore);
2077 const size_t width,
const size_t height,
const PixelInfo *background,
2092 assert(image_info != (
const ImageInfo *) NULL);
2093 assert(image_info->signature == MagickCoreSignature);
2094 assert(background != (
const PixelInfo *) NULL);
2095 if (IsEventLogging() != MagickFalse)
2096 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2097 image=AcquireImage(image_info,exception);
2098 image->columns=width;
2100 image->colorspace=background->colorspace;
2101 image->alpha_trait=background->alpha_trait;
2102 image->fuzz=background->fuzz;
2103 image->depth=background->depth;
2105 image_view=AcquireAuthenticCacheView(image,exception);
2106#if defined(MAGICKCORE_OPENMP_SUPPORT)
2107 #pragma omp parallel for schedule(static) shared(status) \
2108 magick_number_threads(image,image,image->rows,2)
2110 for (y=0; y < (ssize_t) image->rows; y++)
2118 if (status == MagickFalse)
2120 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2121 if (q == (Quantum *) NULL)
2126 for (x=0; x < (ssize_t) image->columns; x++)
2128 SetPixelViaPixelInfo(image,background,q);
2129 q+=(ptrdiff_t) GetPixelChannels(image);
2131 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2134 image_view=DestroyCacheView(image_view);
2135 if (status == MagickFalse)
2136 image=DestroyImage(image);
2163MagickExport
Image *ReferenceImage(
Image *image)
2165 assert(image != (
Image *) NULL);
2166 assert(image->signature == MagickCoreSignature);
2167 if (IsEventLogging() != MagickFalse)
2168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2169 LockSemaphoreInfo(image->semaphore);
2170 image->reference_count++;
2171 UnlockSemaphoreInfo(image->semaphore);
2199MagickExport MagickBooleanType ResetImagePage(
Image *image,
const char *page)
2207 assert(image != (
Image *) NULL);
2208 assert(image->signature == MagickCoreSignature);
2209 if (IsEventLogging() != MagickFalse)
2210 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2211 flags=ParseAbsoluteGeometry(page,&geometry);
2212 if ((flags & WidthValue) != 0)
2214 if ((flags & HeightValue) == 0)
2215 geometry.height=geometry.width;
2216 image->page.width=geometry.width;
2217 image->page.height=geometry.height;
2219 if ((flags & AspectValue) != 0)
2221 if ((flags & XValue) != 0)
2222 image->page.x+=geometry.x;
2223 if ((flags & YValue) != 0)
2224 image->page.y+=geometry.y;
2228 if ((flags & XValue) != 0)
2230 image->page.x=geometry.x;
2231 if ((image->page.width == 0) && (geometry.x > 0))
2232 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2234 if ((flags & YValue) != 0)
2236 image->page.y=geometry.y;
2237 if ((image->page.height == 0) && (geometry.y > 0))
2238 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2270MagickExport MagickBooleanType ResetImagePixels(
Image *image,
2288 assert(image != (
Image *) NULL);
2289 assert(image->signature == MagickCoreSignature);
2290 if (IsEventLogging() != MagickFalse)
2291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2292 pixels=AcquirePixelCachePixels(image,&length,exception);
2293 if (pixels != (
void *) NULL)
2298 (void) memset(pixels,0,length);
2305 image_view=AcquireAuthenticCacheView(image,exception);
2306#if defined(MAGICKCORE_OPENMP_SUPPORT)
2307 #pragma omp parallel for schedule(static) shared(status) \
2308 magick_number_threads(image,image,image->rows,2)
2310 for (y=0; y < (ssize_t) image->rows; y++)
2318 if (status == MagickFalse)
2320 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2321 if (q == (Quantum *) NULL)
2326 for (x=0; x < (ssize_t) image->columns; x++)
2328 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2329 q+=(ptrdiff_t) GetPixelChannels(image);
2331 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2334 image_view=DestroyCacheView(image_view);
2366MagickExport MagickBooleanType SetImageAlpha(
Image *image,
const Quantum alpha,
2378 assert(image != (
Image *) NULL);
2379 assert(image->signature == MagickCoreSignature);
2380 if (IsEventLogging() != MagickFalse)
2381 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2382 image->alpha_trait=BlendPixelTrait;
2384 image_view=AcquireAuthenticCacheView(image,exception);
2385#if defined(MAGICKCORE_OPENMP_SUPPORT)
2386 #pragma omp parallel for schedule(static) shared(status) \
2387 magick_number_threads(image,image,image->rows,2)
2389 for (y=0; y < (ssize_t) image->rows; y++)
2397 if (status == MagickFalse)
2399 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2400 if (q == (Quantum *) NULL)
2405 for (x=0; x < (ssize_t) image->columns; x++)
2407 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2408 SetPixelAlpha(image,alpha,q);
2409 q+=(ptrdiff_t) GetPixelChannels(image);
2411 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2414 image_view=DestroyCacheView(image_view);
2445MagickExport MagickBooleanType SetImageBackgroundColor(
Image *image,
2460 assert(image != (
Image *) NULL);
2461 assert(image->signature == MagickCoreSignature);
2462 if (IsEventLogging() != MagickFalse)
2463 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2464 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2465 return(MagickFalse);
2466 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2467 ((image->alpha_trait & BlendPixelTrait) == 0))
2468 (
void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2469 ConformPixelInfo(image,&image->background_color,&background,exception);
2474 image_view=AcquireAuthenticCacheView(image,exception);
2475#if defined(MAGICKCORE_OPENMP_SUPPORT)
2476 #pragma omp parallel for schedule(static) shared(status) \
2477 magick_number_threads(image,image,image->rows,2)
2479 for (y=0; y < (ssize_t) image->rows; y++)
2487 if (status == MagickFalse)
2489 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2490 if (q == (Quantum *) NULL)
2495 for (x=0; x < (ssize_t) image->columns; x++)
2497 SetPixelViaPixelInfo(image,&background,q);
2498 q+=(ptrdiff_t) GetPixelChannels(image);
2500 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2503 image_view=DestroyCacheView(image_view);
2533MagickExport ChannelType SetImageChannelMask(
Image *image,
2534 const ChannelType channel_mask)
2536 return(SetPixelChannelMask(image,channel_mask));
2566MagickExport MagickBooleanType SetImageColor(
Image *image,
2578 assert(image != (
Image *) NULL);
2579 assert(image->signature == MagickCoreSignature);
2580 assert(color != (
const PixelInfo *) NULL);
2581 if (IsEventLogging() != MagickFalse)
2582 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2583 image->colorspace=color->colorspace;
2584 image->alpha_trait=color->alpha_trait;
2585 image->fuzz=color->fuzz;
2586 image->depth=color->depth;
2588 image_view=AcquireAuthenticCacheView(image,exception);
2589#if defined(MAGICKCORE_OPENMP_SUPPORT)
2590 #pragma omp parallel for schedule(static) shared(status) \
2591 magick_number_threads(image,image,image->rows,2)
2593 for (y=0; y < (ssize_t) image->rows; y++)
2601 if (status == MagickFalse)
2603 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2604 if (q == (Quantum *) NULL)
2609 for (x=0; x < (ssize_t) image->columns; x++)
2611 SetPixelViaPixelInfo(image,color,q);
2612 q+=(ptrdiff_t) GetPixelChannels(image);
2614 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2617 image_view=DestroyCacheView(image_view);
2649MagickExport MagickBooleanType SetImageStorageClass(
Image *image,
2652 assert(image != (
Image *) NULL);
2653 assert(image->signature == MagickCoreSignature);
2655 assert(exception->signature == MagickCoreSignature);
2656 if (IsEventLogging() != MagickFalse)
2657 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2658 image->storage_class=storage_class;
2659 return(SyncImagePixelCache(image,exception));
2691MagickExport MagickBooleanType SetImageExtent(
Image *image,
const size_t columns,
2694 if ((columns == 0) || (rows == 0))
2695 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2696 image->columns=columns;
2698 if (image->depth == 0)
2701 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2702 "ImageDepthNotSupported",
"`%s'",image->filename);
2704 if (image->depth > (8*
sizeof(MagickSizeType)))
2706 image->depth=8*
sizeof(MagickSizeType);
2707 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2708 "ImageDepthNotSupported",
"`%s'",image->filename);
2710 return(SyncImagePixelCache(image,exception));
2761 *format_type_formats[] =
2785 (void) CopyMagickString(magic,component,MagickPathExtent);
2790 format_type=UndefinedFormatType;
2791 magick_info=GetMagickInfo(magic,exception);
2792 if ((magick_info != (
const MagickInfo *) NULL) &&
2793 (magick_info->format_type != UndefinedFormatType))
2794 format_type=magick_info->format_type;
2796 while ((format_type == UndefinedFormatType) &&
2797 (format_type_formats[i] != (
char *) NULL))
2799 if ((*magic == *format_type_formats[i]) &&
2800 (LocaleCompare(magic,format_type_formats[i]) == 0))
2801 format_type=ExplicitFormatType;
2804 if (format_type == UndefinedFormatType)
2805 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2807 if (format_type == ExplicitFormatType)
2809 image_info->affirm=MagickTrue;
2810 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2812 if (LocaleCompare(magic,
"RGB") == 0)
2813 image_info->affirm=MagickFalse;
2814 return(magick_info);
2817MagickExport MagickBooleanType SetImageInfo(
ImageInfo *image_info,
2821 component[MagickPathExtent],
2822 magic[MagickPathExtent],
2823 path[MagickPathExtent],
2850 assert(image_info != (
ImageInfo *) NULL);
2851 assert(image_info->signature == MagickCoreSignature);
2852 if (IsEventLogging() != MagickFalse)
2853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2854 image_info->filename);
2856 GetPathComponent(image_info->filename,SubimagePath,component);
2857 if (*component !=
'\0')
2862 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2864 if (IsGeometry(component) != MagickFalse)
2865 (void) CloneString(&image_info->extract,component);
2873 (void) CloneString(&image_info->scenes,component);
2874 image_info->scene=StringToUnsignedLong(image_info->scenes);
2875 image_info->number_scenes=image_info->scene;
2876 p=image_info->scenes;
2877 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2879 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2881 first=(size_t) strtol(p,&q,10);
2883 while (isspace((
int) ((
unsigned char) *q)) != 0)
2886 last=(size_t) strtol(q+1,&q,10);
2889 if (first < image_info->scene)
2890 image_info->scene=first;
2891 if (last > image_info->number_scenes)
2892 image_info->number_scenes=last;
2895 image_info->number_scenes-=image_info->scene-1;
2899 if (*image_info->magick ==
'\0')
2900 GetPathComponent(image_info->filename,ExtensionPath,component);
2901 if (*component !=
'\0')
2906 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2907 GetPathComponent(path,ExtensionPath,component);
2909 image_info->affirm=MagickFalse;
2910 sans_exception=AcquireExceptionInfo();
2911 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2912 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2918 GetPathComponent(image_info->filename,MagickPath,magic);
2921 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2922 magick_info=GetMagickInfo(magic,sans_exception);
2923 if ((magick_info != (
const MagickInfo *) NULL) &&
2924 (magick_info->format_type == ExplicitFormatType))
2925 image_info->affirm=MagickTrue;
2927 GetPathComponent(image_info->filename,CanonicalPath,component);
2929 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2930 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2941 magick_info=GetMagickInfo(magic,sans_exception);
2943 if (magick_info == (
const MagickInfo *) NULL)
2945 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2947 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2949 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2954 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2958 if (((magick_info != (
const MagickInfo *) NULL) ||
2960 (IsMagickConflict(magic) == MagickFalse))
2962 image_info->affirm=MagickTrue;
2963 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2964 GetPathComponent(image_info->filename,CanonicalPath,component);
2965 (void) CopyMagickString(image_info->filename,component,
2969 sans_exception=DestroyExceptionInfo(sans_exception);
2970 if ((magick_info == (
const MagickInfo *) NULL) ||
2971 (GetMagickEndianSupport(magick_info) == MagickFalse))
2972 image_info->endian=UndefinedEndian;
2973 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2978 (void) InterpretImageFilename(image_info,(
Image *) NULL,
2979 image_info->filename,(int) image_info->scene,component,exception);
2980 if ((LocaleCompare(component,image_info->filename) != 0) &&
2981 (strchr(component,
'%') == (
char *) NULL))
2982 image_info->adjoin=MagickFalse;
2984 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2989 magick_info=GetMagickInfo(magic,exception);
2990 if (magick_info != (
const MagickInfo *) NULL)
2991 if (GetMagickAdjoin(magick_info) == MagickFalse)
2992 image_info->adjoin=MagickFalse;
2994 if (image_info->affirm != MagickFalse)
3007 magick_size=GetMagicPatternExtent(exception);
3008 if (magick_size == 0)
3009 return(MagickFalse);
3010 image=AcquireImage(image_info,exception);
3011 (void) CopyMagickString(image->filename,image_info->filename,
3013 sans_exception=AcquireExceptionInfo();
3014 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3015 sans_exception=DestroyExceptionInfo(sans_exception);
3016 if (status == MagickFalse)
3018 image=DestroyImage(image);
3019 return(MagickFalse);
3021 if ((IsBlobSeekable(image) == MagickFalse) ||
3022 (IsBlobExempt(image) != MagickFalse))
3028 status=ImageToFile(image,component,exception);
3029 if (CloseBlob(image) == MagickFalse)
3031 if (status == MagickFalse)
3033 (void) RelinquishUniqueFileResource(component);
3034 image=DestroyImage(image);
3035 return(MagickFalse);
3037 SetImageInfoFile(image_info,(FILE *) NULL);
3038 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3039 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3040 if (status == MagickFalse)
3042 (void) RelinquishUniqueFileResource(component);
3043 image=DestroyImage(image);
3044 return(MagickFalse);
3046 (void) CopyMagickString(image_info->filename,component,
3048 image_info->temporary=MagickTrue;
3050 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3051 if (magick == (
unsigned char *) NULL)
3053 (void) CloseBlob(image);
3054 image=DestroyImage(image);
3055 return(MagickFalse);
3057 (void) memset(magick,0,magick_size);
3058 count=ReadBlob(image,magick_size,magick);
3059 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3060 (void) CloseBlob(image);
3061 image=DestroyImage(image);
3065 sans_exception=AcquireExceptionInfo();
3066 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3067 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3068 if ((magic_info != (
const MagicInfo *) NULL) &&
3069 (GetMagicName(magic_info) != (
char *) NULL))
3074 if ((magick_info != (
const MagickInfo *) NULL) &&
3075 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3076 (LocaleCompare(magick_info->magick_module,GetMagicName(
3078 (
void) CopyMagickString(image_info->magick,magick_info->name,
3082 (void) CopyMagickString(image_info->magick,GetMagicName(
3083 magic_info),MagickPathExtent);
3084 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3086 if ((magick_info == (
const MagickInfo *) NULL) ||
3087 (GetMagickEndianSupport(magick_info) == MagickFalse))
3088 image_info->endian=UndefinedEndian;
3089 sans_exception=DestroyExceptionInfo(sans_exception);
3092 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3093 if ((magick_info == (
const MagickInfo *) NULL) ||
3094 (GetMagickEndianSupport(magick_info) == MagickFalse))
3095 image_info->endian=UndefinedEndian;
3096 sans_exception=DestroyExceptionInfo(sans_exception);
3128MagickExport
void SetImageInfoBlob(
ImageInfo *image_info,
const void *blob,
3129 const size_t length)
3131 assert(image_info != (
ImageInfo *) NULL);
3132 assert(image_info->signature == MagickCoreSignature);
3133 if (IsEventLogging() != MagickFalse)
3134 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3135 image_info->filename);
3136 image_info->blob=(
void *) blob;
3137 image_info->length=length;
3165MagickExport
void SetImageInfoCustomStream(
ImageInfo *image_info,
3168 assert(image_info != (
ImageInfo *) NULL);
3169 assert(image_info->signature == MagickCoreSignature);
3170 if (IsEventLogging() != MagickFalse)
3171 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3172 image_info->filename);
3200MagickExport
void SetImageInfoFile(
ImageInfo *image_info,FILE *file)
3202 assert(image_info != (
ImageInfo *) NULL);
3203 assert(image_info->signature == MagickCoreSignature);
3204 if (IsEventLogging() != MagickFalse)
3205 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3206 image_info->filename);
3207 image_info->file=file;
3240MagickExport MagickBooleanType SetImageMask(
Image *image,
const PixelMask type,
3256 assert(image != (
Image *) NULL);
3257 if (IsEventLogging() != MagickFalse)
3258 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3259 assert(image->signature == MagickCoreSignature);
3260 if (mask == (
const Image *) NULL)
3266 image->channels=(ChannelType) ((
unsigned int) image->channels &
3267 (
unsigned int) ~ReadMaskChannel);
3270 case WritePixelMask:
3272 image->channels=(ChannelType) ((
unsigned int) image->channels &
3273 (
unsigned int) ~WriteMaskChannel);
3278 image->channels=(ChannelType) ((
unsigned int) image->channels &
3279 (
unsigned int) ~CompositeMaskChannel);
3283 return(SyncImagePixelCache(image,exception));
3289 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3292 case WritePixelMask:
3294 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3299 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3303 if (SyncImagePixelCache(image,exception) == MagickFalse)
3304 return(MagickFalse);
3306 image->mask_trait=UpdatePixelTrait;
3307 mask_view=AcquireVirtualCacheView(mask,exception);
3308 image_view=AcquireAuthenticCacheView(image,exception);
3309#if defined(MAGICKCORE_OPENMP_SUPPORT)
3310 #pragma omp parallel for schedule(static) shared(status) \
3311 magick_number_threads(mask,image,image->rows,2)
3313 for (y=0; y < (ssize_t) image->rows; y++)
3324 if (status == MagickFalse)
3326 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3327 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3328 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3333 for (x=0; x < (ssize_t) image->columns; x++)
3339 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3340 intensity=GetPixelIntensity(mask,p);
3345 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3348 case WritePixelMask:
3350 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3355 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3359 p+=(ptrdiff_t) GetPixelChannels(mask);
3360 q+=(ptrdiff_t) GetPixelChannels(image);
3362 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3365 image->mask_trait=UndefinedPixelTrait;
3366 mask_view=DestroyCacheView(mask_view);
3367 image_view=DestroyCacheView(image_view);
3401MagickExport MagickBooleanType SetImageRegionMask(
Image *image,
3416 assert(image != (
Image *) NULL);
3417 assert(image->signature == MagickCoreSignature);
3418 if (IsEventLogging() != MagickFalse)
3419 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3426 image->channels=(ChannelType) ((
unsigned int) image->channels &
3427 (
unsigned int) ~ReadMaskChannel);
3430 case WritePixelMask:
3432 image->channels=(ChannelType) ((
unsigned int) image->channels &
3433 (
unsigned int) ~WriteMaskChannel);
3438 image->channels=(ChannelType) ((
unsigned int) image->channels &
3439 (
unsigned int) ~CompositeMaskChannel);
3443 return(SyncImagePixelCache(image,exception));
3449 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3452 case WritePixelMask:
3454 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3459 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3463 if (SyncImagePixelCache(image,exception) == MagickFalse)
3464 return(MagickFalse);
3466 image->mask_trait=UpdatePixelTrait;
3467 image_view=AcquireAuthenticCacheView(image,exception);
3468#if defined(MAGICKCORE_OPENMP_SUPPORT)
3469 #pragma omp parallel for schedule(static) shared(status) \
3470 magick_number_threads(image,image,image->rows,2)
3472 for (y=0; y < (ssize_t) image->rows; y++)
3480 if (status == MagickFalse)
3482 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3483 if (q == (Quantum *) NULL)
3488 for (x=0; x < (ssize_t) image->columns; x++)
3494 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3495 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3501 SetPixelReadMask(image,pixel,q);
3504 case WritePixelMask:
3506 SetPixelWriteMask(image,pixel,q);
3511 SetPixelCompositeMask(image,pixel,q);
3515 q+=(ptrdiff_t) GetPixelChannels(image);
3517 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3520 image->mask_trait=UndefinedPixelTrait;
3521 image_view=DestroyCacheView(image_view);
3554MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(
Image *image,
3555 const VirtualPixelMethod virtual_pixel_method,
ExceptionInfo *exception)
3557 assert(image != (
const Image *) NULL);
3558 assert(image->signature == MagickCoreSignature);
3559 if (IsEventLogging() != MagickFalse)
3560 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3561 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3599static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3627 if (images->previous == (
Image *) NULL)
3630 SetGeometry(smush_image,&right_geometry);
3631 GravityAdjustGeometry(right_image->columns,right_image->rows,
3632 right_image->gravity,&right_geometry);
3633 left_image=images->previous;
3634 SetGeometry(smush_image,&left_geometry);
3635 GravityAdjustGeometry(left_image->columns,left_image->rows,
3636 left_image->gravity,&left_geometry);
3637 gap=right_image->columns;
3638 left_view=AcquireVirtualCacheView(left_image,exception);
3639 right_view=AcquireVirtualCacheView(right_image,exception);
3640 for (y=0; y < (ssize_t) smush_image->rows; y++)
3642 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3644 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3645 if ((p == (
const Quantum *) NULL) ||
3646 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3647 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3650 i=(ssize_t) left_image->columns-x-1;
3651 for (x=0; x < (ssize_t) right_image->columns; x++)
3653 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3655 if ((p == (
const Quantum *) NULL) ||
3656 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3657 ((x+i) >= (ssize_t) gap))
3660 if ((x+i) < (ssize_t) gap)
3663 right_view=DestroyCacheView(right_view);
3664 left_view=DestroyCacheView(left_view);
3665 if (y < (ssize_t) smush_image->rows)
3667 return((ssize_t) gap-offset);
3670static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3698 if (images->previous == (
Image *) NULL)
3700 bottom_image=images;
3701 SetGeometry(smush_image,&bottom_geometry);
3702 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3703 bottom_image->gravity,&bottom_geometry);
3704 top_image=images->previous;
3705 SetGeometry(smush_image,&top_geometry);
3706 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3708 gap=bottom_image->rows;
3709 top_view=AcquireVirtualCacheView(top_image,exception);
3710 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3711 for (x=0; x < (ssize_t) smush_image->columns; x++)
3713 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3715 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3716 if ((p == (
const Quantum *) NULL) ||
3717 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3718 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3721 i=(ssize_t) top_image->rows-y-1;
3722 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3724 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3726 if ((p == (
const Quantum *) NULL) ||
3727 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3728 ((y+i) >= (ssize_t) gap))
3731 if ((y+i) < (ssize_t) gap)
3734 bottom_view=DestroyCacheView(bottom_view);
3735 top_view=DestroyCacheView(top_view);
3736 if (x < (ssize_t) smush_image->columns)
3738 return((ssize_t) gap-offset);
3741MagickExport
Image *SmushImages(
const Image *images,
3742 const MagickBooleanType stack,
const ssize_t offset,
ExceptionInfo *exception)
3744#define SmushImageTag "Smush/Image"
3780 assert(images != (
Image *) NULL);
3781 assert(images->signature == MagickCoreSignature);
3783 assert(exception->signature == MagickCoreSignature);
3784 if (IsEventLogging() != MagickFalse)
3785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3787 alpha_trait=image->alpha_trait;
3789 width=image->columns;
3791 next=GetNextImageInList(image);
3792 for ( ; next != (
Image *) NULL; next=GetNextImageInList(next))
3794 if (next->alpha_trait != UndefinedPixelTrait)
3795 alpha_trait=BlendPixelTrait;
3797 if (stack != MagickFalse)
3799 if (next->columns > width)
3800 width=next->columns;
3802 if (next->previous != (
Image *) NULL)
3803 height=(
size_t) MagickMax((ssize_t) height+offset,0U);
3806 width+=next->columns;
3807 if (next->previous != (
Image *) NULL)
3808 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3809 if (next->rows > height)
3815 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3816 if (smush_image == (
Image *) NULL)
3817 return((
Image *) NULL);
3818 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3820 smush_image=DestroyImage(smush_image);
3821 return((
Image *) NULL);
3823 smush_image->alpha_trait=alpha_trait;
3824 (void) SetImageBackgroundColor(smush_image,exception);
3828 for (n=0; n < (MagickOffsetType) number_images; n++)
3830 SetGeometry(smush_image,&geometry);
3831 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3832 if (stack != MagickFalse)
3834 x_offset-=geometry.x;
3835 y_offset-=SmushYGap(smush_image,image,offset,exception);
3839 x_offset-=SmushXGap(smush_image,image,offset,exception);
3840 y_offset-=geometry.y;
3842 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3843 y_offset,exception);
3844 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3845 if (proceed == MagickFalse)
3847 if (stack == MagickFalse)
3849 x_offset+=(ssize_t) image->columns;
3855 y_offset+=(ssize_t) image->rows;
3857 image=GetNextImageInList(image);
3859 if (stack == MagickFalse)
3860 smush_image->columns=(size_t) x_offset;
3862 smush_image->rows=(size_t) y_offset;
3863 if (status == MagickFalse)
3864 smush_image=DestroyImage(smush_image);
3865 return(smush_image);
3892MagickExport MagickBooleanType StripImage(
Image *image,
3898 magick_unreferenced(exception);
3899 assert(image != (
Image *) NULL);
3900 if (IsEventLogging() != MagickFalse)
3901 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3902 DestroyImageProfiles(image);
3903 (void) DeleteImageProperty(image,
"comment");
3904 (void) DeleteImageProperty(image,
"date:create");
3905 (void) DeleteImageProperty(image,
"date:modify");
3906 (void) DeleteImageProperty(image,
"date:timestamp");
3907 status=SetImageArtifact(image,
"png:exclude-chunk",
3908 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3938static inline Quantum PushColormapIndex(
Image *image,
const Quantum index,
3939 MagickBooleanType *range_exception)
3941 if ((
size_t) index < image->colors)
3943 *range_exception=MagickTrue;
3944 return((Quantum) 0);
3960 assert(image != (
Image *) NULL);
3961 assert(image->signature == MagickCoreSignature);
3962 if (IsEventLogging() != MagickFalse)
3963 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3964 if (image->ping != MagickFalse)
3966 if (image->storage_class != PseudoClass)
3967 return(MagickFalse);
3968 assert(image->colormap != (
PixelInfo *) NULL);
3969 range_exception=MagickFalse;
3972 image_view=AcquireAuthenticCacheView(image,exception);
3973#if defined(MAGICKCORE_OPENMP_SUPPORT)
3974 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3975 magick_number_threads(image,image,image->rows,2)
3977 for (y=0; y < (ssize_t) image->rows; y++)
3988 if (status == MagickFalse)
3990 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3991 if (q == (Quantum *) NULL)
3996 for (x=0; x < (ssize_t) image->columns; x++)
3998 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3999 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4000 q+=(ptrdiff_t) GetPixelChannels(image);
4002 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4005 image_view=DestroyCacheView(image_view);
4007 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4008 (void) ThrowMagickException(exception,GetMagickModule(),
4009 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4050MagickExport MagickBooleanType SyncImagesSettings(
ImageInfo *image_info,
4056 assert(image_info != (
const ImageInfo *) NULL);
4057 assert(image_info->signature == MagickCoreSignature);
4058 assert(images != (
Image *) NULL);
4059 assert(images->signature == MagickCoreSignature);
4060 if (IsEventLogging() != MagickFalse)
4061 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4063 for ( ; image != (
Image *) NULL; image=GetNextImageInList(image))
4064 (
void) SyncImageSettings(image_info,image,exception);
4065 (void) DeleteImageOption(image_info,
"page");
4069MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4087 assert(image_info != (
const ImageInfo *) NULL);
4088 assert(image_info->signature == MagickCoreSignature);
4089 assert(image != (
Image *) NULL);
4090 assert(image->signature == MagickCoreSignature);
4091 if (IsEventLogging() != MagickFalse)
4092 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4093 option=GetImageOption(image_info,
"background");
4094 if (option != (
const char *) NULL)
4095 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4097 option=GetImageOption(image_info,
"black-point-compensation");
4098 if (option != (
const char *) NULL)
4099 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4100 MagickBooleanOptions,MagickFalse,option);
4101 option=GetImageOption(image_info,
"blue-primary");
4102 if (option != (
const char *) NULL)
4104 flags=ParseGeometry(option,&geometry_info);
4105 if ((flags & RhoValue) != 0)
4106 image->chromaticity.blue_primary.x=geometry_info.rho;
4107 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4108 if ((flags & SigmaValue) != 0)
4109 image->chromaticity.blue_primary.y=geometry_info.sigma;
4111 option=GetImageOption(image_info,
"bordercolor");
4112 if (option != (
const char *) NULL)
4113 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4116 option=GetImageOption(image_info,
"compose");
4117 if (option != (
const char *) NULL)
4118 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4119 MagickFalse,option);
4121 option=GetImageOption(image_info,
"compress");
4122 if (option != (
const char *) NULL)
4123 image->compression=(CompressionType) ParseCommandOption(
4124 MagickCompressOptions,MagickFalse,option);
4125 option=GetImageOption(image_info,
"debug");
4126 if (option != (
const char *) NULL)
4127 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4128 MagickFalse,option);
4129 option=GetImageOption(image_info,
"density");
4130 if (option != (
const char *) NULL)
4132 flags=ParseGeometry(option,&geometry_info);
4133 if ((flags & RhoValue) != 0)
4134 image->resolution.x=geometry_info.rho;
4135 image->resolution.y=image->resolution.x;
4136 if ((flags & SigmaValue) != 0)
4137 image->resolution.y=geometry_info.sigma;
4139 option=GetImageOption(image_info,
"depth");
4140 if (option != (
const char *) NULL)
4141 image->depth=StringToUnsignedLong(option);
4142 option=GetImageOption(image_info,
"endian");
4143 if (option != (
const char *) NULL)
4144 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4145 MagickFalse,option);
4146 option=GetImageOption(image_info,
"filter");
4147 if (option != (
const char *) NULL)
4148 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4149 MagickFalse,option);
4150 option=GetImageOption(image_info,
"fuzz");
4151 if (option != (
const char *) NULL)
4152 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4153 option=GetImageOption(image_info,
"gravity");
4154 if (option != (
const char *) NULL)
4155 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4156 MagickFalse,option);
4157 option=GetImageOption(image_info,
"green-primary");
4158 if (option != (
const char *) NULL)
4160 flags=ParseGeometry(option,&geometry_info);
4161 if ((flags & RhoValue) != 0)
4162 image->chromaticity.green_primary.x=geometry_info.rho;
4163 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4164 if ((flags & SigmaValue) != 0)
4165 image->chromaticity.green_primary.y=geometry_info.sigma;
4167 option=GetImageOption(image_info,
"intent");
4168 if (option != (
const char *) NULL)
4169 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4170 MagickIntentOptions,MagickFalse,option);
4171 option=GetImageOption(image_info,
"intensity");
4172 if (option != (
const char *) NULL)
4173 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4174 MagickPixelIntensityOptions,MagickFalse,option);
4175 option=GetImageOption(image_info,
"interlace");
4176 if (option != (
const char *) NULL)
4177 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4178 MagickFalse,option);
4179 option=GetImageOption(image_info,
"interpolate");
4180 if (option != (
const char *) NULL)
4181 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4182 MagickInterpolateOptions,MagickFalse,option);
4183 option=GetImageOption(image_info,
"loop");
4184 if (option != (
const char *) NULL)
4185 image->iterations=StringToUnsignedLong(option);
4186 option=GetImageOption(image_info,
"mattecolor");
4187 if (option != (
const char *) NULL)
4188 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4190 option=GetImageOption(image_info,
"orient");
4191 if (option != (
const char *) NULL)
4192 image->orientation=(OrientationType) ParseCommandOption(
4193 MagickOrientationOptions,MagickFalse,option);
4194 option=GetImageOption(image_info,
"page");
4195 if (option != (
const char *) NULL)
4200 geometry=GetPageGeometry(option);
4201 flags=ParseAbsoluteGeometry(geometry,&image->page);
4202 geometry=DestroyString(geometry);
4204 option=GetImageOption(image_info,
"quality");
4205 if (option != (
const char *) NULL)
4206 image->quality=StringToUnsignedLong(option);
4207 option=GetImageOption(image_info,
"red-primary");
4208 if (option != (
const char *) NULL)
4210 flags=ParseGeometry(option,&geometry_info);
4211 if ((flags & RhoValue) != 0)
4212 image->chromaticity.red_primary.x=geometry_info.rho;
4213 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4214 if ((flags & SigmaValue) != 0)
4215 image->chromaticity.red_primary.y=geometry_info.sigma;
4217 if (image_info->quality != UndefinedCompressionQuality)
4218 image->quality=image_info->quality;
4219 option=GetImageOption(image_info,
"scene");
4220 if (option != (
const char *) NULL)
4221 image->scene=StringToUnsignedLong(option);
4222 option=GetImageOption(image_info,
"taint");
4223 if (option != (
const char *) NULL)
4224 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4225 MagickFalse,option);
4226 option=GetImageOption(image_info,
"tile-offset");
4227 if (option != (
const char *) NULL)
4232 geometry=GetPageGeometry(option);
4233 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4234 geometry=DestroyString(geometry);
4236 option=GetImageOption(image_info,
"transparent-color");
4237 if (option != (
const char *) NULL)
4238 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4240 option=GetImageOption(image_info,
"type");
4241 if (option != (
const char *) NULL)
4242 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4244 option=GetImageOption(image_info,
"units");
4245 units=image_info->units;
4246 if (option != (
const char *) NULL)
4247 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4248 MagickFalse,option);
4249 if (units != UndefinedResolution)
4251 if (image->units != units)
4252 switch (image->units)
4254 case PixelsPerInchResolution:
4256 if (units == PixelsPerCentimeterResolution)
4258 image->resolution.x/=2.54;
4259 image->resolution.y/=2.54;
4263 case PixelsPerCentimeterResolution:
4265 if (units == PixelsPerInchResolution)
4267 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4268 image->resolution.x+0.5))/100.0;
4269 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4270 image->resolution.y+0.5))/100.0;
4278 option=GetImageOption(image_info,
"density");
4279 if (option != (
const char *) NULL)
4281 flags=ParseGeometry(option,&geometry_info);
4282 if ((flags & RhoValue) != 0)
4283 image->resolution.x=geometry_info.rho;
4284 image->resolution.y=image->resolution.x;
4285 if ((flags & SigmaValue) != 0)
4286 image->resolution.y=geometry_info.sigma;
4289 option=GetImageOption(image_info,
"virtual-pixel");
4290 if (option != (
const char *) NULL)
4291 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4292 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4294 option=GetImageOption(image_info,
"white-point");
4295 if (option != (
const char *) NULL)
4297 flags=ParseGeometry(option,&geometry_info);
4298 if ((flags & RhoValue) != 0)
4299 image->chromaticity.white_point.x=geometry_info.rho;
4300 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4301 if ((flags & SigmaValue) != 0)
4302 image->chromaticity.white_point.y=geometry_info.sigma;
4310 if (image->image_info != (
ImageInfo *) NULL)
4311 image->image_info=DestroyImageInfo(image->image_info);
4312 image->image_info=CloneImageInfo(image_info);