43#include "MagickCore/studio.h"
44#include "MagickCore/animate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/blob.h"
48#include "MagickCore/blob-private.h"
49#include "MagickCore/cache.h"
50#include "MagickCore/cache-private.h"
51#include "MagickCore/cache-view.h"
52#include "MagickCore/channel.h"
53#include "MagickCore/client.h"
54#include "MagickCore/color.h"
55#include "MagickCore/color-private.h"
56#include "MagickCore/colormap.h"
57#include "MagickCore/colorspace.h"
58#include "MagickCore/colorspace-private.h"
59#include "MagickCore/composite.h"
60#include "MagickCore/composite-private.h"
61#include "MagickCore/compress.h"
62#include "MagickCore/constitute.h"
63#include "MagickCore/delegate.h"
64#include "MagickCore/display.h"
65#include "MagickCore/draw.h"
66#include "MagickCore/enhance.h"
67#include "MagickCore/exception.h"
68#include "MagickCore/exception-private.h"
69#include "MagickCore/gem.h"
70#include "MagickCore/geometry.h"
71#include "MagickCore/histogram.h"
72#include "MagickCore/image-private.h"
73#include "MagickCore/list.h"
74#include "MagickCore/magic.h"
75#include "MagickCore/magick.h"
76#include "MagickCore/magick-private.h"
77#include "MagickCore/memory_.h"
78#include "MagickCore/memory-private.h"
79#include "MagickCore/module.h"
80#include "MagickCore/monitor.h"
81#include "MagickCore/monitor-private.h"
82#include "MagickCore/option.h"
83#include "MagickCore/paint.h"
84#include "MagickCore/pixel-accessor.h"
85#include "MagickCore/profile.h"
86#include "MagickCore/property.h"
87#include "MagickCore/quantize.h"
88#include "MagickCore/random_.h"
89#include "MagickCore/resource_.h"
90#include "MagickCore/segment.h"
91#include "MagickCore/semaphore.h"
92#include "MagickCore/signature-private.h"
93#include "MagickCore/statistic.h"
94#include "MagickCore/string_.h"
95#include "MagickCore/string-private.h"
96#include "MagickCore/thread-private.h"
97#include "MagickCore/threshold.h"
98#include "MagickCore/timer.h"
99#include "MagickCore/timer-private.h"
100#include "MagickCore/token.h"
101#include "MagickCore/token-private.h"
102#include "MagickCore/utility.h"
103#include "MagickCore/utility-private.h"
104#include "MagickCore/version.h"
105#include "MagickCore/xwindow-private.h"
152 if (IsEventLogging() != MagickFalse)
153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
154 image=(
Image *) AcquireCriticalMemory(
sizeof(*image));
155 (void) memset(image,0,
sizeof(*image));
159 (void) CopyMagickString(image->magick,
"MIFF",MagickPathExtent);
160 image->storage_class=DirectClass;
161 image->depth=MAGICKCORE_QUANTUM_DEPTH;
162 image->colorspace=sRGBColorspace;
163 image->rendering_intent=PerceptualIntent;
164 image->gamma=1.000/2.200;
165 image->chromaticity.red_primary.x=0.6400;
166 image->chromaticity.red_primary.y=0.3300;
167 image->chromaticity.red_primary.z=0.0300;
168 image->chromaticity.green_primary.x=0.3000;
169 image->chromaticity.green_primary.y=0.6000;
170 image->chromaticity.green_primary.z=0.1000;
171 image->chromaticity.blue_primary.x=0.1500;
172 image->chromaticity.blue_primary.y=0.0600;
173 image->chromaticity.blue_primary.z=0.7900;
174 image->chromaticity.white_point.x=0.3127;
175 image->chromaticity.white_point.y=0.3290;
176 image->chromaticity.white_point.z=0.3583;
177 image->interlace=NoInterlace;
178 image->ticks_per_second=UndefinedTicksPerSecond;
179 image->compose=OverCompositeOp;
180 GetPixelInfoRGBA(BackgroundColorRGBA,&image->background_color);
181 GetPixelInfoRGBA(BorderColorRGBA,&image->border_color);
182 GetPixelInfoRGBA(MatteColorRGBA,&image->matte_color);
183 GetPixelInfoRGBA(TransparentColorRGBA,&image->transparent_color);
184 GetTimerInfo(&image->timer);
185 image->cache=AcquirePixelCache(0);
186 image->channel_mask=AllChannels;
187 image->channel_map=AcquirePixelChannelMap();
188 image->blob=CloneBlobInfo((
BlobInfo *) NULL);
189 image->timestamp=GetMagickTime();
190 time_limit=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));
1649MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1650 Image *image,
const char *format,
int value,
char *filename,
1668 canonical=MagickFalse;
1670 (void) CopyMagickString(filename,format,MagickPathExtent);
1671 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1672 return(strlen(filename));
1673 for (p=strchr(format,
'%'); p != (
char *) NULL; p=strchr(p+1,
'%'))
1693 count=FormatLocaleString(filename+(p-format-offset),(
size_t)
1694 (MagickPathExtent-(p-format-offset)),p,value);
1695 if ((count <= 0) || (count > (MagickPathExtent-(p-format-offset))))
1697 offset+=(ssize_t) ((q-p)-count);
1699 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1700 canonical=MagickTrue;
1709 pattern[MagickPathExtent];
1726 if (strchr(p,
']') == (
char *) NULL)
1730 for (i=0; (i < (MagickPathExtent-1L)) && (*r !=
'\0'); i++)
1741 if (LocaleNCompare(pattern,
"filename:",9) != 0)
1743 option=(
const char *) NULL;
1744 if (image != (
Image *) NULL)
1745 option=GetImageProperty(image,pattern,exception);
1746 if ((option == (
const char *) NULL) && (image != (
Image *) NULL))
1747 option=GetImageArtifact(image,pattern);
1748 if ((option == (
const char *) NULL) &&
1750 option=GetImageOption(image_info,pattern);
1751 if (option == (
const char *) NULL)
1756 (void) CopyMagickString(filename+(p-format-offset),option,(size_t)
1757 (MagickPathExtent-(p-format-offset)));
1758 offset+=(ssize_t) strlen(pattern)-(ssize_t) strlen(option)+3;
1760 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1761 canonical=MagickTrue;
1771 if (canonical == MagickFalse)
1772 (void) CopyMagickString(filename,format,MagickPathExtent);
1774 for (q=filename; *q !=
'\0'; q++)
1775 if ((*q ==
'%') && (*(q+1) ==
'%'))
1776 (
void) CopyMagickString(q,q+1,(
size_t) (MagickPathExtent-(q-filename)));
1777 return(strlen(filename));
1807MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1810#if !defined(MAGICKCORE_HDRI_SUPPORT)
1813 return(MagickFalse);
1824 assert(image != (
Image *) NULL);
1825 assert(image->signature == MagickCoreSignature);
1826 if (IsEventLogging() != MagickFalse)
1827 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1828 image_view=AcquireVirtualCacheView(image,exception);
1829#if defined(MAGICKCORE_OPENMP_SUPPORT)
1830 #pragma omp parallel for schedule(static) shared(hdri) \
1831 magick_number_threads(image,image,image->rows,2)
1833 for (y=0; y < (ssize_t) image->rows; y++)
1841 if (hdri != MagickFalse)
1843 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1844 if (p == (
const Quantum *) NULL)
1846 for (x=0; x < (ssize_t) image->columns; x++)
1851 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1859 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1860 if (traits == UndefinedPixelTrait)
1862 pixel=(double) p[i];
1863 if ((pixel < 0.0) || (pixel > (double) QuantumRange) ||
1864 (pixel != (double) ((QuantumAny) pixel)))
1870 if (hdri != MagickFalse)
1872 p+=(ptrdiff_t) GetPixelChannels(image);
1875 image_view=DestroyCacheView(image_view);
1903MagickExport MagickBooleanType IsImageObject(
const Image *image)
1908 assert(image != (
Image *) NULL);
1909 if (IsEventLogging() != MagickFalse)
1910 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1911 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1912 if (p->signature != MagickCoreSignature)
1913 return(MagickFalse);
1940MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1943 magick[MagickPathExtent],
1944 filename[MagickPathExtent];
1949 assert(image != (
Image *) NULL);
1950 assert(image->signature == MagickCoreSignature);
1951 if (IsEventLogging() != MagickFalse)
1952 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1953 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1954 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1955 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1957 if (p->taint != MagickFalse)
1959 if (LocaleCompare(p->magick,magick) != 0)
1961 if (LocaleCompare(p->filename,filename) != 0)
1964 return(MagickFalse);
1993MagickExport MagickBooleanType ModifyImage(
Image **image,
1999 assert(image != (
Image **) NULL);
2000 assert(*image != (
Image *) NULL);
2001 assert((*image)->signature == MagickCoreSignature);
2002 if (IsEventLogging() != MagickFalse)
2003 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2004 if (GetImageReferenceCount(*image) <= 1)
2006 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2007 LockSemaphoreInfo((*image)->semaphore);
2008 (*image)->reference_count--;
2009 UnlockSemaphoreInfo((*image)->semaphore);
2048 const size_t width,
const size_t height,
const PixelInfo *background,
2063 assert(image_info != (
const ImageInfo *) NULL);
2064 assert(image_info->signature == MagickCoreSignature);
2065 assert(background != (
const PixelInfo *) NULL);
2066 if (IsEventLogging() != MagickFalse)
2067 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2068 image=AcquireImage(image_info,exception);
2069 image->columns=width;
2071 image->colorspace=background->colorspace;
2072 image->alpha_trait=background->alpha_trait;
2073 image->fuzz=background->fuzz;
2074 image->depth=background->depth;
2076 image_view=AcquireAuthenticCacheView(image,exception);
2077#if defined(MAGICKCORE_OPENMP_SUPPORT)
2078 #pragma omp parallel for schedule(static) shared(status) \
2079 magick_number_threads(image,image,image->rows,2)
2081 for (y=0; y < (ssize_t) image->rows; y++)
2089 if (status == MagickFalse)
2091 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2092 if (q == (Quantum *) NULL)
2097 for (x=0; x < (ssize_t) image->columns; x++)
2099 SetPixelViaPixelInfo(image,background,q);
2100 q+=(ptrdiff_t) GetPixelChannels(image);
2102 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2105 image_view=DestroyCacheView(image_view);
2106 if (status == MagickFalse)
2107 image=DestroyImage(image);
2134MagickExport
Image *ReferenceImage(
Image *image)
2136 assert(image != (
Image *) NULL);
2137 assert(image->signature == MagickCoreSignature);
2138 if (IsEventLogging() != MagickFalse)
2139 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2140 LockSemaphoreInfo(image->semaphore);
2141 image->reference_count++;
2142 UnlockSemaphoreInfo(image->semaphore);
2170MagickExport MagickBooleanType ResetImagePage(
Image *image,
const char *page)
2178 assert(image != (
Image *) NULL);
2179 assert(image->signature == MagickCoreSignature);
2180 if (IsEventLogging() != MagickFalse)
2181 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2182 flags=ParseAbsoluteGeometry(page,&geometry);
2183 if ((flags & WidthValue) != 0)
2185 if ((flags & HeightValue) == 0)
2186 geometry.height=geometry.width;
2187 image->page.width=geometry.width;
2188 image->page.height=geometry.height;
2190 if ((flags & AspectValue) != 0)
2192 if ((flags & XValue) != 0)
2193 image->page.x+=geometry.x;
2194 if ((flags & YValue) != 0)
2195 image->page.y+=geometry.y;
2199 if ((flags & XValue) != 0)
2201 image->page.x=geometry.x;
2202 if ((image->page.width == 0) && (geometry.x > 0))
2203 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2205 if ((flags & YValue) != 0)
2207 image->page.y=geometry.y;
2208 if ((image->page.height == 0) && (geometry.y > 0))
2209 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2241MagickExport MagickBooleanType ResetImagePixels(
Image *image,
2259 assert(image != (
Image *) NULL);
2260 assert(image->signature == MagickCoreSignature);
2261 if (IsEventLogging() != MagickFalse)
2262 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2263 pixels=AcquirePixelCachePixels(image,&length,exception);
2264 if (pixels != (
void *) NULL)
2269 (void) memset(pixels,0,length);
2276 image_view=AcquireAuthenticCacheView(image,exception);
2277#if defined(MAGICKCORE_OPENMP_SUPPORT)
2278 #pragma omp parallel for schedule(static) shared(status) \
2279 magick_number_threads(image,image,image->rows,2)
2281 for (y=0; y < (ssize_t) image->rows; y++)
2289 if (status == MagickFalse)
2291 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2292 if (q == (Quantum *) NULL)
2297 for (x=0; x < (ssize_t) image->columns; x++)
2299 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2300 q+=(ptrdiff_t) GetPixelChannels(image);
2302 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2305 image_view=DestroyCacheView(image_view);
2337MagickExport MagickBooleanType SetImageAlpha(
Image *image,
const Quantum alpha,
2349 assert(image != (
Image *) NULL);
2350 assert(image->signature == MagickCoreSignature);
2351 if (IsEventLogging() != MagickFalse)
2352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2353 image->alpha_trait=BlendPixelTrait;
2355 image_view=AcquireAuthenticCacheView(image,exception);
2356#if defined(MAGICKCORE_OPENMP_SUPPORT)
2357 #pragma omp parallel for schedule(static) shared(status) \
2358 magick_number_threads(image,image,image->rows,2)
2360 for (y=0; y < (ssize_t) image->rows; y++)
2368 if (status == MagickFalse)
2370 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2371 if (q == (Quantum *) NULL)
2376 for (x=0; x < (ssize_t) image->columns; x++)
2378 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2379 SetPixelAlpha(image,alpha,q);
2380 q+=(ptrdiff_t) GetPixelChannels(image);
2382 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2385 image_view=DestroyCacheView(image_view);
2416MagickExport MagickBooleanType SetImageBackgroundColor(
Image *image,
2431 assert(image != (
Image *) NULL);
2432 assert(image->signature == MagickCoreSignature);
2433 if (IsEventLogging() != MagickFalse)
2434 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2435 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2436 return(MagickFalse);
2437 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2438 ((image->alpha_trait & BlendPixelTrait) == 0))
2439 (
void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2440 ConformPixelInfo(image,&image->background_color,&background,exception);
2445 image_view=AcquireAuthenticCacheView(image,exception);
2446#if defined(MAGICKCORE_OPENMP_SUPPORT)
2447 #pragma omp parallel for schedule(static) shared(status) \
2448 magick_number_threads(image,image,image->rows,2)
2450 for (y=0; y < (ssize_t) image->rows; y++)
2458 if (status == MagickFalse)
2460 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2461 if (q == (Quantum *) NULL)
2466 for (x=0; x < (ssize_t) image->columns; x++)
2468 SetPixelViaPixelInfo(image,&background,q);
2469 q+=(ptrdiff_t) GetPixelChannels(image);
2471 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2474 image_view=DestroyCacheView(image_view);
2504MagickExport ChannelType SetImageChannelMask(
Image *image,
2505 const ChannelType channel_mask)
2507 return(SetPixelChannelMask(image,channel_mask));
2537MagickExport MagickBooleanType SetImageColor(
Image *image,
2549 assert(image != (
Image *) NULL);
2550 assert(image->signature == MagickCoreSignature);
2551 assert(color != (
const PixelInfo *) NULL);
2552 if (IsEventLogging() != MagickFalse)
2553 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2554 image->colorspace=color->colorspace;
2555 image->alpha_trait=color->alpha_trait;
2556 image->fuzz=color->fuzz;
2557 image->depth=color->depth;
2559 image_view=AcquireAuthenticCacheView(image,exception);
2560#if defined(MAGICKCORE_OPENMP_SUPPORT)
2561 #pragma omp parallel for schedule(static) shared(status) \
2562 magick_number_threads(image,image,image->rows,2)
2564 for (y=0; y < (ssize_t) image->rows; y++)
2572 if (status == MagickFalse)
2574 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2575 if (q == (Quantum *) NULL)
2580 for (x=0; x < (ssize_t) image->columns; x++)
2582 SetPixelViaPixelInfo(image,color,q);
2583 q+=(ptrdiff_t) GetPixelChannels(image);
2585 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2588 image_view=DestroyCacheView(image_view);
2620MagickExport MagickBooleanType SetImageStorageClass(
Image *image,
2623 assert(image != (
Image *) NULL);
2624 assert(image->signature == MagickCoreSignature);
2626 assert(exception->signature == MagickCoreSignature);
2627 if (IsEventLogging() != MagickFalse)
2628 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2629 image->storage_class=storage_class;
2630 return(SyncImagePixelCache(image,exception));
2662MagickExport MagickBooleanType SetImageExtent(
Image *image,
const size_t columns,
2665 if ((columns == 0) || (rows == 0))
2666 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2667 image->columns=columns;
2669 if (image->depth == 0)
2672 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2673 "ImageDepthNotSupported",
"`%s'",image->filename);
2675 if (image->depth > (8*
sizeof(MagickSizeType)))
2677 image->depth=8*
sizeof(MagickSizeType);
2678 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2679 "ImageDepthNotSupported",
"`%s'",image->filename);
2681 return(SyncImagePixelCache(image,exception));
2732 *format_type_formats[] =
2756 (void) CopyMagickString(magic,component,MagickPathExtent);
2761 format_type=UndefinedFormatType;
2762 magick_info=GetMagickInfo(magic,exception);
2763 if ((magick_info != (
const MagickInfo *) NULL) &&
2764 (magick_info->format_type != UndefinedFormatType))
2765 format_type=magick_info->format_type;
2767 while ((format_type == UndefinedFormatType) &&
2768 (format_type_formats[i] != (
char *) NULL))
2770 if ((*magic == *format_type_formats[i]) &&
2771 (LocaleCompare(magic,format_type_formats[i]) == 0))
2772 format_type=ExplicitFormatType;
2775 if (format_type == UndefinedFormatType)
2776 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2778 if (format_type == ExplicitFormatType)
2780 image_info->affirm=MagickTrue;
2781 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2783 if (LocaleCompare(magic,
"RGB") == 0)
2784 image_info->affirm=MagickFalse;
2785 return(magick_info);
2788MagickExport MagickBooleanType SetImageInfo(
ImageInfo *image_info,
2792 component[MagickPathExtent],
2793 magic[MagickPathExtent],
2794 path[MagickPathExtent],
2821 assert(image_info != (
ImageInfo *) NULL);
2822 assert(image_info->signature == MagickCoreSignature);
2823 if (IsEventLogging() != MagickFalse)
2824 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2825 image_info->filename);
2827 GetPathComponent(image_info->filename,SubimagePath,component);
2828 if (*component !=
'\0')
2833 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2835 if (IsGeometry(component) != MagickFalse)
2836 (void) CloneString(&image_info->extract,component);
2844 (void) CloneString(&image_info->scenes,component);
2845 image_info->scene=StringToUnsignedLong(image_info->scenes);
2846 image_info->number_scenes=image_info->scene;
2847 p=image_info->scenes;
2848 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2850 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2852 first=(size_t) strtol(p,&q,10);
2854 while (isspace((
int) ((
unsigned char) *q)) != 0)
2857 last=(size_t) strtol(q+1,&q,10);
2860 if (first < image_info->scene)
2861 image_info->scene=first;
2862 if (last > image_info->number_scenes)
2863 image_info->number_scenes=last;
2866 image_info->number_scenes-=image_info->scene-1;
2870 if (*image_info->magick ==
'\0')
2871 GetPathComponent(image_info->filename,ExtensionPath,component);
2872 if (*component !=
'\0')
2877 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2878 GetPathComponent(path,ExtensionPath,component);
2880 image_info->affirm=MagickFalse;
2881 sans_exception=AcquireExceptionInfo();
2882 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2883 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2889 GetPathComponent(image_info->filename,MagickPath,magic);
2892 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2893 magick_info=GetMagickInfo(magic,sans_exception);
2894 if ((magick_info != (
const MagickInfo *) NULL) &&
2895 (magick_info->format_type == ExplicitFormatType))
2896 image_info->affirm=MagickTrue;
2898 GetPathComponent(image_info->filename,CanonicalPath,component);
2900 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2901 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2912 magick_info=GetMagickInfo(magic,sans_exception);
2914 if (magick_info == (
const MagickInfo *) NULL)
2916 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2918 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2920 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2925 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2929 if (((magick_info != (
const MagickInfo *) NULL) ||
2931 (IsMagickConflict(magic) == MagickFalse))
2933 image_info->affirm=MagickTrue;
2934 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2935 GetPathComponent(image_info->filename,CanonicalPath,component);
2936 (void) CopyMagickString(image_info->filename,component,
2940 sans_exception=DestroyExceptionInfo(sans_exception);
2941 if ((magick_info == (
const MagickInfo *) NULL) ||
2942 (GetMagickEndianSupport(magick_info) == MagickFalse))
2943 image_info->endian=UndefinedEndian;
2944 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2949 (void) InterpretImageFilename(image_info,(
Image *) NULL,
2950 image_info->filename,(int) image_info->scene,component,exception);
2951 if ((LocaleCompare(component,image_info->filename) != 0) &&
2952 (strchr(component,
'%') == (
char *) NULL))
2953 image_info->adjoin=MagickFalse;
2955 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2960 magick_info=GetMagickInfo(magic,exception);
2961 if (magick_info != (
const MagickInfo *) NULL)
2962 if (GetMagickAdjoin(magick_info) == MagickFalse)
2963 image_info->adjoin=MagickFalse;
2965 if (image_info->affirm != MagickFalse)
2978 magick_size=GetMagicPatternExtent(exception);
2979 if (magick_size == 0)
2980 return(MagickFalse);
2981 image=AcquireImage(image_info,exception);
2982 (void) CopyMagickString(image->filename,image_info->filename,
2984 sans_exception=AcquireExceptionInfo();
2985 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
2986 sans_exception=DestroyExceptionInfo(sans_exception);
2987 if (status == MagickFalse)
2989 image=DestroyImage(image);
2990 return(MagickFalse);
2992 if ((IsBlobSeekable(image) == MagickFalse) ||
2993 (IsBlobExempt(image) != MagickFalse))
2999 status=ImageToFile(image,component,exception);
3000 if (CloseBlob(image) == MagickFalse)
3002 if (status == MagickFalse)
3004 (void) RelinquishUniqueFileResource(component);
3005 image=DestroyImage(image);
3006 return(MagickFalse);
3008 SetImageInfoFile(image_info,(FILE *) NULL);
3009 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3010 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3011 if (status == MagickFalse)
3013 (void) RelinquishUniqueFileResource(component);
3014 image=DestroyImage(image);
3015 return(MagickFalse);
3017 (void) CopyMagickString(image_info->filename,component,
3019 image_info->temporary=MagickTrue;
3021 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3022 if (magick == (
unsigned char *) NULL)
3024 (void) CloseBlob(image);
3025 image=DestroyImage(image);
3026 return(MagickFalse);
3028 (void) memset(magick,0,magick_size);
3029 count=ReadBlob(image,magick_size,magick);
3030 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3031 (void) CloseBlob(image);
3032 image=DestroyImage(image);
3036 sans_exception=AcquireExceptionInfo();
3037 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3038 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3039 if ((magic_info != (
const MagicInfo *) NULL) &&
3040 (GetMagicName(magic_info) != (
char *) NULL))
3045 if ((magick_info != (
const MagickInfo *) NULL) &&
3046 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3047 (LocaleCompare(magick_info->magick_module,GetMagicName(
3049 (
void) CopyMagickString(image_info->magick,magick_info->name,
3053 (void) CopyMagickString(image_info->magick,GetMagicName(
3054 magic_info),MagickPathExtent);
3055 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3057 if ((magick_info == (
const MagickInfo *) NULL) ||
3058 (GetMagickEndianSupport(magick_info) == MagickFalse))
3059 image_info->endian=UndefinedEndian;
3060 sans_exception=DestroyExceptionInfo(sans_exception);
3063 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3064 if ((magick_info == (
const MagickInfo *) NULL) ||
3065 (GetMagickEndianSupport(magick_info) == MagickFalse))
3066 image_info->endian=UndefinedEndian;
3067 sans_exception=DestroyExceptionInfo(sans_exception);
3099MagickExport
void SetImageInfoBlob(
ImageInfo *image_info,
const void *blob,
3100 const size_t length)
3102 assert(image_info != (
ImageInfo *) NULL);
3103 assert(image_info->signature == MagickCoreSignature);
3104 if (IsEventLogging() != MagickFalse)
3105 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3106 image_info->filename);
3107 image_info->blob=(
void *) blob;
3108 image_info->length=length;
3136MagickExport
void SetImageInfoCustomStream(
ImageInfo *image_info,
3139 assert(image_info != (
ImageInfo *) NULL);
3140 assert(image_info->signature == MagickCoreSignature);
3141 if (IsEventLogging() != MagickFalse)
3142 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3143 image_info->filename);
3171MagickExport
void SetImageInfoFile(
ImageInfo *image_info,FILE *file)
3173 assert(image_info != (
ImageInfo *) NULL);
3174 assert(image_info->signature == MagickCoreSignature);
3175 if (IsEventLogging() != MagickFalse)
3176 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3177 image_info->filename);
3178 image_info->file=file;
3211MagickExport MagickBooleanType SetImageMask(
Image *image,
const PixelMask type,
3227 assert(image != (
Image *) NULL);
3228 if (IsEventLogging() != MagickFalse)
3229 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3230 assert(image->signature == MagickCoreSignature);
3231 if (mask == (
const Image *) NULL)
3237 image->channels=(ChannelType) ((
unsigned int) image->channels &
3238 (
unsigned int) ~ReadMaskChannel);
3241 case WritePixelMask:
3243 image->channels=(ChannelType) ((
unsigned int) image->channels &
3244 (
unsigned int) ~WriteMaskChannel);
3249 image->channels=(ChannelType) ((
unsigned int) image->channels &
3250 (
unsigned int) ~CompositeMaskChannel);
3254 return(SyncImagePixelCache(image,exception));
3260 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3263 case WritePixelMask:
3265 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3270 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3274 if (SyncImagePixelCache(image,exception) == MagickFalse)
3275 return(MagickFalse);
3277 image->mask_trait=UpdatePixelTrait;
3278 mask_view=AcquireVirtualCacheView(mask,exception);
3279 image_view=AcquireAuthenticCacheView(image,exception);
3280#if defined(MAGICKCORE_OPENMP_SUPPORT)
3281 #pragma omp parallel for schedule(static) shared(status) \
3282 magick_number_threads(mask,image,image->rows,2)
3284 for (y=0; y < (ssize_t) image->rows; y++)
3295 if (status == MagickFalse)
3297 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3298 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3299 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3304 for (x=0; x < (ssize_t) image->columns; x++)
3310 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3311 intensity=GetPixelIntensity(mask,p);
3316 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3319 case WritePixelMask:
3321 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3326 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3330 p+=(ptrdiff_t) GetPixelChannels(mask);
3331 q+=(ptrdiff_t) GetPixelChannels(image);
3333 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3336 image->mask_trait=UndefinedPixelTrait;
3337 mask_view=DestroyCacheView(mask_view);
3338 image_view=DestroyCacheView(image_view);
3372MagickExport MagickBooleanType SetImageRegionMask(
Image *image,
3387 assert(image != (
Image *) NULL);
3388 assert(image->signature == MagickCoreSignature);
3389 if (IsEventLogging() != MagickFalse)
3390 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3397 image->channels=(ChannelType) ((
unsigned int) image->channels &
3398 (
unsigned int) ~ReadMaskChannel);
3401 case WritePixelMask:
3403 image->channels=(ChannelType) ((
unsigned int) image->channels &
3404 (
unsigned int) ~WriteMaskChannel);
3409 image->channels=(ChannelType) ((
unsigned int) image->channels &
3410 (
unsigned int) ~CompositeMaskChannel);
3414 return(SyncImagePixelCache(image,exception));
3420 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3423 case WritePixelMask:
3425 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3430 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3434 if (SyncImagePixelCache(image,exception) == MagickFalse)
3435 return(MagickFalse);
3437 image->mask_trait=UpdatePixelTrait;
3438 image_view=AcquireAuthenticCacheView(image,exception);
3439#if defined(MAGICKCORE_OPENMP_SUPPORT)
3440 #pragma omp parallel for schedule(static) shared(status) \
3441 magick_number_threads(image,image,image->rows,2)
3443 for (y=0; y < (ssize_t) image->rows; y++)
3451 if (status == MagickFalse)
3453 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3454 if (q == (Quantum *) NULL)
3459 for (x=0; x < (ssize_t) image->columns; x++)
3465 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3466 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3472 SetPixelReadMask(image,pixel,q);
3475 case WritePixelMask:
3477 SetPixelWriteMask(image,pixel,q);
3482 SetPixelCompositeMask(image,pixel,q);
3486 q+=(ptrdiff_t) GetPixelChannels(image);
3488 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3491 image->mask_trait=UndefinedPixelTrait;
3492 image_view=DestroyCacheView(image_view);
3525MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(
Image *image,
3526 const VirtualPixelMethod virtual_pixel_method,
ExceptionInfo *exception)
3528 assert(image != (
const Image *) NULL);
3529 assert(image->signature == MagickCoreSignature);
3530 if (IsEventLogging() != MagickFalse)
3531 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3532 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3570static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3598 if (images->previous == (
Image *) NULL)
3601 SetGeometry(smush_image,&right_geometry);
3602 GravityAdjustGeometry(right_image->columns,right_image->rows,
3603 right_image->gravity,&right_geometry);
3604 left_image=images->previous;
3605 SetGeometry(smush_image,&left_geometry);
3606 GravityAdjustGeometry(left_image->columns,left_image->rows,
3607 left_image->gravity,&left_geometry);
3608 gap=right_image->columns;
3609 left_view=AcquireVirtualCacheView(left_image,exception);
3610 right_view=AcquireVirtualCacheView(right_image,exception);
3611 for (y=0; y < (ssize_t) smush_image->rows; y++)
3613 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3615 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3616 if ((p == (
const Quantum *) NULL) ||
3617 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3618 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3621 i=(ssize_t) left_image->columns-x-1;
3622 for (x=0; x < (ssize_t) right_image->columns; x++)
3624 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3626 if ((p == (
const Quantum *) NULL) ||
3627 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3628 ((x+i) >= (ssize_t) gap))
3631 if ((x+i) < (ssize_t) gap)
3634 right_view=DestroyCacheView(right_view);
3635 left_view=DestroyCacheView(left_view);
3636 if (y < (ssize_t) smush_image->rows)
3638 return((ssize_t) gap-offset);
3641static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3669 if (images->previous == (
Image *) NULL)
3671 bottom_image=images;
3672 SetGeometry(smush_image,&bottom_geometry);
3673 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3674 bottom_image->gravity,&bottom_geometry);
3675 top_image=images->previous;
3676 SetGeometry(smush_image,&top_geometry);
3677 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3679 gap=bottom_image->rows;
3680 top_view=AcquireVirtualCacheView(top_image,exception);
3681 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3682 for (x=0; x < (ssize_t) smush_image->columns; x++)
3684 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3686 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3687 if ((p == (
const Quantum *) NULL) ||
3688 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3689 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3692 i=(ssize_t) top_image->rows-y-1;
3693 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3695 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3697 if ((p == (
const Quantum *) NULL) ||
3698 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3699 ((y+i) >= (ssize_t) gap))
3702 if ((y+i) < (ssize_t) gap)
3705 bottom_view=DestroyCacheView(bottom_view);
3706 top_view=DestroyCacheView(top_view);
3707 if (x < (ssize_t) smush_image->columns)
3709 return((ssize_t) gap-offset);
3712MagickExport
Image *SmushImages(
const Image *images,
3713 const MagickBooleanType stack,
const ssize_t offset,
ExceptionInfo *exception)
3715#define SmushImageTag "Smush/Image"
3751 assert(images != (
Image *) NULL);
3752 assert(images->signature == MagickCoreSignature);
3754 assert(exception->signature == MagickCoreSignature);
3755 if (IsEventLogging() != MagickFalse)
3756 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3758 alpha_trait=image->alpha_trait;
3760 width=image->columns;
3762 next=GetNextImageInList(image);
3763 for ( ; next != (
Image *) NULL; next=GetNextImageInList(next))
3765 if (next->alpha_trait != UndefinedPixelTrait)
3766 alpha_trait=BlendPixelTrait;
3768 if (stack != MagickFalse)
3770 if (next->columns > width)
3771 width=next->columns;
3773 if (next->previous != (
Image *) NULL)
3774 height=(
size_t) MagickMax((ssize_t) height+offset,0U);
3777 width+=next->columns;
3778 if (next->previous != (
Image *) NULL)
3779 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3780 if (next->rows > height)
3786 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3787 if (smush_image == (
Image *) NULL)
3788 return((
Image *) NULL);
3789 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3791 smush_image=DestroyImage(smush_image);
3792 return((
Image *) NULL);
3794 smush_image->alpha_trait=alpha_trait;
3795 (void) SetImageBackgroundColor(smush_image,exception);
3799 for (n=0; n < (MagickOffsetType) number_images; n++)
3801 SetGeometry(smush_image,&geometry);
3802 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3803 if (stack != MagickFalse)
3805 x_offset-=geometry.x;
3806 y_offset-=SmushYGap(smush_image,image,offset,exception);
3810 x_offset-=SmushXGap(smush_image,image,offset,exception);
3811 y_offset-=geometry.y;
3813 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3814 y_offset,exception);
3815 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3816 if (proceed == MagickFalse)
3818 if (stack == MagickFalse)
3820 x_offset+=(ssize_t) image->columns;
3826 y_offset+=(ssize_t) image->rows;
3828 image=GetNextImageInList(image);
3830 if (stack == MagickFalse)
3831 smush_image->columns=(size_t) x_offset;
3833 smush_image->rows=(size_t) y_offset;
3834 if (status == MagickFalse)
3835 smush_image=DestroyImage(smush_image);
3836 return(smush_image);
3863MagickExport MagickBooleanType StripImage(
Image *image,
3869 magick_unreferenced(exception);
3870 assert(image != (
Image *) NULL);
3871 if (IsEventLogging() != MagickFalse)
3872 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3873 DestroyImageProfiles(image);
3874 (void) DeleteImageProperty(image,
"comment");
3875 (void) DeleteImageProperty(image,
"date:create");
3876 (void) DeleteImageProperty(image,
"date:modify");
3877 (void) DeleteImageProperty(image,
"date:timestamp");
3878 status=SetImageArtifact(image,
"png:exclude-chunk",
3879 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3909static inline Quantum PushColormapIndex(
Image *image,
const Quantum index,
3910 MagickBooleanType *range_exception)
3912 if ((
size_t) index < image->colors)
3914 *range_exception=MagickTrue;
3915 return((Quantum) 0);
3931 assert(image != (
Image *) NULL);
3932 assert(image->signature == MagickCoreSignature);
3933 if (IsEventLogging() != MagickFalse)
3934 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3935 if (image->ping != MagickFalse)
3937 if (image->storage_class != PseudoClass)
3938 return(MagickFalse);
3939 assert(image->colormap != (
PixelInfo *) NULL);
3940 range_exception=MagickFalse;
3943 image_view=AcquireAuthenticCacheView(image,exception);
3944#if defined(MAGICKCORE_OPENMP_SUPPORT)
3945 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3946 magick_number_threads(image,image,image->rows,2)
3948 for (y=0; y < (ssize_t) image->rows; y++)
3959 if (status == MagickFalse)
3961 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3962 if (q == (Quantum *) NULL)
3967 for (x=0; x < (ssize_t) image->columns; x++)
3969 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3970 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3971 q+=(ptrdiff_t) GetPixelChannels(image);
3973 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3976 image_view=DestroyCacheView(image_view);
3978 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3979 (void) ThrowMagickException(exception,GetMagickModule(),
3980 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4021MagickExport MagickBooleanType SyncImagesSettings(
ImageInfo *image_info,
4027 assert(image_info != (
const ImageInfo *) NULL);
4028 assert(image_info->signature == MagickCoreSignature);
4029 assert(images != (
Image *) NULL);
4030 assert(images->signature == MagickCoreSignature);
4031 if (IsEventLogging() != MagickFalse)
4032 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4034 for ( ; image != (
Image *) NULL; image=GetNextImageInList(image))
4035 (
void) SyncImageSettings(image_info,image,exception);
4036 (void) DeleteImageOption(image_info,
"page");
4040MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4058 assert(image_info != (
const ImageInfo *) NULL);
4059 assert(image_info->signature == MagickCoreSignature);
4060 assert(image != (
Image *) NULL);
4061 assert(image->signature == MagickCoreSignature);
4062 if (IsEventLogging() != MagickFalse)
4063 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4064 option=GetImageOption(image_info,
"background");
4065 if (option != (
const char *) NULL)
4066 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4068 option=GetImageOption(image_info,
"black-point-compensation");
4069 if (option != (
const char *) NULL)
4070 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4071 MagickBooleanOptions,MagickFalse,option);
4072 option=GetImageOption(image_info,
"blue-primary");
4073 if (option != (
const char *) NULL)
4075 flags=ParseGeometry(option,&geometry_info);
4076 if ((flags & RhoValue) != 0)
4077 image->chromaticity.blue_primary.x=geometry_info.rho;
4078 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4079 if ((flags & SigmaValue) != 0)
4080 image->chromaticity.blue_primary.y=geometry_info.sigma;
4082 option=GetImageOption(image_info,
"bordercolor");
4083 if (option != (
const char *) NULL)
4084 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4087 option=GetImageOption(image_info,
"compose");
4088 if (option != (
const char *) NULL)
4089 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4090 MagickFalse,option);
4092 option=GetImageOption(image_info,
"compress");
4093 if (option != (
const char *) NULL)
4094 image->compression=(CompressionType) ParseCommandOption(
4095 MagickCompressOptions,MagickFalse,option);
4096 option=GetImageOption(image_info,
"debug");
4097 if (option != (
const char *) NULL)
4098 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4099 MagickFalse,option);
4100 option=GetImageOption(image_info,
"density");
4101 if (option != (
const char *) NULL)
4103 flags=ParseGeometry(option,&geometry_info);
4104 if ((flags & RhoValue) != 0)
4105 image->resolution.x=geometry_info.rho;
4106 image->resolution.y=image->resolution.x;
4107 if ((flags & SigmaValue) != 0)
4108 image->resolution.y=geometry_info.sigma;
4110 option=GetImageOption(image_info,
"depth");
4111 if (option != (
const char *) NULL)
4112 image->depth=StringToUnsignedLong(option);
4113 option=GetImageOption(image_info,
"endian");
4114 if (option != (
const char *) NULL)
4115 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4116 MagickFalse,option);
4117 option=GetImageOption(image_info,
"filter");
4118 if (option != (
const char *) NULL)
4119 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4120 MagickFalse,option);
4121 option=GetImageOption(image_info,
"fuzz");
4122 if (option != (
const char *) NULL)
4123 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4124 option=GetImageOption(image_info,
"gravity");
4125 if (option != (
const char *) NULL)
4126 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4127 MagickFalse,option);
4128 option=GetImageOption(image_info,
"green-primary");
4129 if (option != (
const char *) NULL)
4131 flags=ParseGeometry(option,&geometry_info);
4132 if ((flags & RhoValue) != 0)
4133 image->chromaticity.green_primary.x=geometry_info.rho;
4134 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4135 if ((flags & SigmaValue) != 0)
4136 image->chromaticity.green_primary.y=geometry_info.sigma;
4138 option=GetImageOption(image_info,
"intent");
4139 if (option != (
const char *) NULL)
4140 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4141 MagickIntentOptions,MagickFalse,option);
4142 option=GetImageOption(image_info,
"intensity");
4143 if (option != (
const char *) NULL)
4144 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4145 MagickPixelIntensityOptions,MagickFalse,option);
4146 option=GetImageOption(image_info,
"interlace");
4147 if (option != (
const char *) NULL)
4148 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4149 MagickFalse,option);
4150 option=GetImageOption(image_info,
"interpolate");
4151 if (option != (
const char *) NULL)
4152 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4153 MagickInterpolateOptions,MagickFalse,option);
4154 option=GetImageOption(image_info,
"loop");
4155 if (option != (
const char *) NULL)
4156 image->iterations=StringToUnsignedLong(option);
4157 option=GetImageOption(image_info,
"mattecolor");
4158 if (option != (
const char *) NULL)
4159 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4161 option=GetImageOption(image_info,
"orient");
4162 if (option != (
const char *) NULL)
4163 image->orientation=(OrientationType) ParseCommandOption(
4164 MagickOrientationOptions,MagickFalse,option);
4165 option=GetImageOption(image_info,
"page");
4166 if (option != (
const char *) NULL)
4171 geometry=GetPageGeometry(option);
4172 flags=ParseAbsoluteGeometry(geometry,&image->page);
4173 geometry=DestroyString(geometry);
4175 option=GetImageOption(image_info,
"quality");
4176 if (option != (
const char *) NULL)
4177 image->quality=StringToUnsignedLong(option);
4178 option=GetImageOption(image_info,
"red-primary");
4179 if (option != (
const char *) NULL)
4181 flags=ParseGeometry(option,&geometry_info);
4182 if ((flags & RhoValue) != 0)
4183 image->chromaticity.red_primary.x=geometry_info.rho;
4184 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4185 if ((flags & SigmaValue) != 0)
4186 image->chromaticity.red_primary.y=geometry_info.sigma;
4188 if (image_info->quality != UndefinedCompressionQuality)
4189 image->quality=image_info->quality;
4190 option=GetImageOption(image_info,
"scene");
4191 if (option != (
const char *) NULL)
4192 image->scene=StringToUnsignedLong(option);
4193 option=GetImageOption(image_info,
"taint");
4194 if (option != (
const char *) NULL)
4195 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4196 MagickFalse,option);
4197 option=GetImageOption(image_info,
"tile-offset");
4198 if (option != (
const char *) NULL)
4203 geometry=GetPageGeometry(option);
4204 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4205 geometry=DestroyString(geometry);
4207 option=GetImageOption(image_info,
"transparent-color");
4208 if (option != (
const char *) NULL)
4209 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4211 option=GetImageOption(image_info,
"type");
4212 if (option != (
const char *) NULL)
4213 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4215 option=GetImageOption(image_info,
"units");
4216 units=image_info->units;
4217 if (option != (
const char *) NULL)
4218 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4219 MagickFalse,option);
4220 if (units != UndefinedResolution)
4222 if (image->units != units)
4223 switch (image->units)
4225 case PixelsPerInchResolution:
4227 if (units == PixelsPerCentimeterResolution)
4229 image->resolution.x/=2.54;
4230 image->resolution.y/=2.54;
4234 case PixelsPerCentimeterResolution:
4236 if (units == PixelsPerInchResolution)
4238 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4239 image->resolution.x+0.5))/100.0;
4240 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4241 image->resolution.y+0.5))/100.0;
4249 option=GetImageOption(image_info,
"density");
4250 if (option != (
const char *) NULL)
4252 flags=ParseGeometry(option,&geometry_info);
4253 if ((flags & RhoValue) != 0)
4254 image->resolution.x=geometry_info.rho;
4255 image->resolution.y=image->resolution.x;
4256 if ((flags & SigmaValue) != 0)
4257 image->resolution.y=geometry_info.sigma;
4260 option=GetImageOption(image_info,
"virtual-pixel");
4261 if (option != (
const char *) NULL)
4262 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4263 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4265 option=GetImageOption(image_info,
"white-point");
4266 if (option != (
const char *) NULL)
4268 flags=ParseGeometry(option,&geometry_info);
4269 if ((flags & RhoValue) != 0)
4270 image->chromaticity.white_point.x=geometry_info.rho;
4271 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4272 if ((flags & SigmaValue) != 0)
4273 image->chromaticity.white_point.y=geometry_info.sigma;
4281 if (image->image_info != (
ImageInfo *) NULL)
4282 image->image_info=DestroyImageInfo(image->image_info);
4283 image->image_info=CloneImageInfo(image_info);