43#include "magick/studio.h"
44#include "magick/animate.h"
45#include "magick/artifact.h"
46#include "magick/blob.h"
47#include "magick/blob-private.h"
48#include "magick/cache.h"
49#include "magick/cache-private.h"
50#include "magick/cache-view.h"
51#include "magick/channel.h"
52#include "magick/client.h"
53#include "magick/color.h"
54#include "magick/color-private.h"
55#include "magick/colormap.h"
56#include "magick/colorspace.h"
57#include "magick/colorspace-private.h"
58#include "magick/composite.h"
59#include "magick/composite-private.h"
60#include "magick/compress.h"
61#include "magick/constitute.h"
62#include "magick/delegate.h"
63#include "magick/deprecate.h"
64#include "magick/display.h"
65#include "magick/draw.h"
66#include "magick/enhance.h"
67#include "magick/exception.h"
68#include "magick/exception-private.h"
69#include "magick/gem.h"
70#include "magick/geometry.h"
71#include "magick/histogram.h"
72#include "magick/image-private.h"
73#include "magick/list.h"
74#include "magick/magic.h"
75#include "magick/magick.h"
76#include "magick/memory_.h"
77#include "magick/memory-private.h"
78#include "magick/module.h"
79#include "magick/monitor.h"
80#include "magick/monitor-private.h"
81#include "magick/option.h"
82#include "magick/paint.h"
83#include "magick/pixel-accessor.h"
84#include "magick/pixel-private.h"
85#include "magick/profile.h"
86#include "magick/property.h"
87#include "magick/quantize.h"
88#include "magick/random_.h"
89#include "magick/resource_.h"
90#include "magick/segment.h"
91#include "magick/semaphore.h"
92#include "magick/signature-private.h"
93#include "magick/statistic.h"
94#include "magick/string_.h"
95#include "magick/string-private.h"
96#include "magick/thread-private.h"
97#include "magick/threshold.h"
98#include "magick/timer.h"
99#include "magick/timer-private.h"
100#include "magick/token.h"
101#include "magick/token-private.h"
102#include "magick/utility.h"
103#include "magick/version.h"
104#include "magick/xwindow-private.h"
131MagickExport Image *AcquireImage(
const ImageInfo *image_info)
148 if (IsEventLogging() != MagickFalse)
149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
150 image=(Image *) AcquireCriticalMemory(
sizeof(*image));
151 (void) memset(image,0,
sizeof(*image));
155 (void) CopyMagickString(image->magick,
"MIFF",MaxTextExtent);
156 image->storage_class=DirectClass;
157 image->depth=MAGICKCORE_QUANTUM_DEPTH;
158 image->colorspace=sRGBColorspace;
159 image->rendering_intent=PerceptualIntent;
160 image->gamma=1.000f/2.200f;
161 image->chromaticity.red_primary.x=0.6400f;
162 image->chromaticity.red_primary.y=0.3300f;
163 image->chromaticity.red_primary.z=0.0300f;
164 image->chromaticity.green_primary.x=0.3000f;
165 image->chromaticity.green_primary.y=0.6000f;
166 image->chromaticity.green_primary.z=0.1000f;
167 image->chromaticity.blue_primary.x=0.1500f;
168 image->chromaticity.blue_primary.y=0.0600f;
169 image->chromaticity.blue_primary.z=0.7900f;
170 image->chromaticity.white_point.x=0.3127f;
171 image->chromaticity.white_point.y=0.3290f;
172 image->chromaticity.white_point.z=0.3583f;
173 image->interlace=NoInterlace;
174 image->ticks_per_second=UndefinedTicksPerSecond;
175 image->compose=OverCompositeOp;
177 GetPixelPacketRGBA(BackgroundColorRGBA,&image->background_color);
178 GetPixelPacketRGBA(BorderColorRGBA,&image->border_color);
179 GetPixelPacketRGBA(MatteColorRGBA,&image->matte_color);
180 GetPixelPacketRGBA(TransparentColorRGBA,&image->transparent_color);
181 GetTimerInfo(&image->timer);
182 image->ping=MagickFalse;
183 image->cache=AcquirePixelCache(0);
184 image->blob=CloneBlobInfo((BlobInfo *) NULL);
185 InitializeExceptionInfo(&image->exception);
186 image->timestamp=time((time_t *) NULL);
187 time_limit=GetMagickResourceLimit(TimeResource);
188 if (time_limit != MagickResourceInfinity)
189 image->ttl=image->timestamp+(time_t) time_limit;
190 image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
191 != 0 ? MagickTrue : MagickFalse;
192 image->reference_count=1;
193 image->semaphore=AllocateSemaphoreInfo();
194 image->signature=MagickCoreSignature;
195 if (image_info == (ImageInfo *) NULL)
200 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
202 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
203 (void) CopyMagickString(image->magick_filename,image_info->filename,
205 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
206 if (image_info->size != (
char *) NULL)
208 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
209 image->columns=image->extract_info.width;
210 image->rows=image->extract_info.height;
211 image->offset=image->extract_info.x;
212 image->extract_info.x=0;
213 image->extract_info.y=0;
215 if (image_info->extract != (
char *) NULL)
220 (void) memset(&geometry,0,
sizeof(geometry));
221 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
222 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
224 image->extract_info=geometry;
225 Swap(image->columns,image->extract_info.width);
226 Swap(image->rows,image->extract_info.height);
229 image->compression=image_info->compression;
230 image->quality=image_info->quality;
231 image->endian=image_info->endian;
232 image->interlace=image_info->interlace;
233 image->units=image_info->units;
234 if (image_info->density != (
char *) NULL)
239 flags=ParseGeometry(image_info->density,&geometry_info);
240 if ((flags & RhoValue) != 0)
241 image->x_resolution=geometry_info.rho;
242 image->y_resolution=image->x_resolution;
243 if ((flags & SigmaValue) != 0)
244 image->y_resolution=geometry_info.sigma;
246 if (image_info->page != (
char *) NULL)
251 image->page=image->extract_info;
252 geometry=GetPageGeometry(image_info->page);
253 (void) ParseAbsoluteGeometry(geometry,&image->page);
254 geometry=DestroyString(geometry);
256 if (image_info->depth != 0)
257 image->depth=image_info->depth;
258 image->dither=image_info->dither;
259 image->background_color=image_info->background_color;
260 image->border_color=image_info->border_color;
261 image->matte_color=image_info->matte_color;
262 image->transparent_color=image_info->transparent_color;
263 image->ping=image_info->ping;
264 image->progress_monitor=image_info->progress_monitor;
265 image->client_data=image_info->client_data;
266 if (image_info->cache != (
void *) NULL)
267 ClonePixelCacheMethods(image->cache,image_info->cache);
268 (void) SyncImageSettings(image_info,image);
269 option=GetImageOption(image_info,
"delay");
270 if (option != (
const char *) NULL)
275 flags=ParseGeometry(option,&geometry_info);
276 if ((flags & GreaterValue) != 0)
278 if ((
double) image->delay > floor(geometry_info.rho+0.5))
279 image->delay=(size_t) CastDoubleToLong(floor(
280 geometry_info.rho+0.5));
283 if ((flags & LessValue) != 0)
285 if ((
double) image->delay < floor(geometry_info.rho+0.5))
286 image->ticks_per_second=CastDoubleToLong(floor(
287 geometry_info.sigma+0.5));
290 image->delay=(size_t) CastDoubleToLong(floor(
291 geometry_info.rho+0.5));
292 if ((flags & SigmaValue) != 0)
293 image->ticks_per_second=CastDoubleToLong(floor(
294 geometry_info.sigma+0.5));
296 option=GetImageOption(image_info,
"dispose");
297 if (option != (
const char *) NULL)
298 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
321MagickExport ImageInfo *AcquireImageInfo(
void)
326 image_info=(ImageInfo *) AcquireMagickMemory(
sizeof(*image_info));
327 if (image_info == (ImageInfo *) NULL)
328 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
329 GetImageInfo(image_info);
361MagickExport
void AcquireNextImage(
const ImageInfo *image_info,Image *image)
366 assert(image != (Image *) NULL);
367 assert(image->signature == MagickCoreSignature);
368 if (IsEventLogging() != MagickFalse)
369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
370 image->next=AcquireImage(image_info);
371 if (GetNextImageInList(image) == (Image *) NULL)
373 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
375 if (image_info != (ImageInfo *) NULL)
376 (void) CopyMagickString(GetNextImageInList(image)->filename,
377 image_info->filename,MaxTextExtent);
378 DestroyBlob(GetNextImageInList(image));
379 image->next->blob=ReferenceBlob(image->blob);
380 image->next->endian=image->endian;
381 image->next->scene=image->scene+1;
382 image->next->previous=image;
417MagickExport Image *AppendImages(
const Image *images,
418 const MagickBooleanType stack,ExceptionInfo *exception)
420#define AppendImageTag "Append/Image"
429 homogeneous_colorspace,
456 assert(images != (Image *) NULL);
457 assert(images->signature == MagickCoreSignature);
458 assert(exception != (ExceptionInfo *) NULL);
459 assert(exception->signature == MagickCoreSignature);
460 if (IsEventLogging() != MagickFalse)
461 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
464 width=images->columns;
467 homogeneous_colorspace=MagickTrue;
468 next=GetNextImageInList(images);
469 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
471 if (next->depth > depth)
473 if (next->colorspace != images->colorspace)
474 homogeneous_colorspace=MagickFalse;
475 if (next->matte != MagickFalse)
478 if (stack != MagickFalse)
480 if (next->columns > width)
485 width+=next->columns;
486 if (next->rows > height)
492 append_image=CloneImage(images,width,height,MagickTrue,exception);
493 if (append_image == (Image *) NULL)
494 return((Image *) NULL);
495 if (SetImageStorageClass(append_image,DirectClass) == MagickFalse)
497 InheritException(exception,&append_image->exception);
498 append_image=DestroyImage(append_image);
499 return((Image *) NULL);
501 if (homogeneous_colorspace == MagickFalse)
502 (void) SetImageColorspace(append_image,sRGBColorspace);
503 append_image->depth=depth;
504 append_image->matte=matte;
505 append_image->page=images->page;
506 (void) SetImageBackgroundColor(append_image);
511 append_view=AcquireAuthenticCacheView(append_image,exception);
512 for (n=0; n < (MagickOffsetType) number_images; n++)
520 SetGeometry(append_image,&geometry);
521 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
522 if (stack != MagickFalse)
523 x_offset-=geometry.x;
525 y_offset-=geometry.y;
526 image_view=AcquireVirtualCacheView(next,exception);
527#if defined(MAGICKCORE_OPENMP_SUPPORT)
528 #pragma omp parallel for schedule(static) shared(status) \
529 magick_number_threads(next,next,next->rows,2)
531 for (y=0; y < (ssize_t) next->rows; y++)
534 *magick_restrict indexes;
540 *magick_restrict append_indexes;
551 if (status == MagickFalse)
553 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
554 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
555 next->columns,1,exception);
556 if ((p == (
const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
561 indexes=GetCacheViewVirtualIndexQueue(image_view);
562 append_indexes=GetCacheViewAuthenticIndexQueue(append_view);
563 for (x=0; x < (ssize_t) next->columns; x++)
565 SetPixelRed(q,GetPixelRed(p));
566 SetPixelGreen(q,GetPixelGreen(p));
567 SetPixelBlue(q,GetPixelBlue(p));
568 SetPixelOpacity(q,OpaqueOpacity);
569 if (next->matte != MagickFalse)
570 SetPixelOpacity(q,GetPixelOpacity(p));
571 if ((next->colorspace == CMYKColorspace) &&
572 (append_image->colorspace == CMYKColorspace))
573 SetPixelIndex(append_indexes+x,GetPixelIndex(indexes+x));
577 sync=SyncCacheViewAuthenticPixels(append_view,exception);
578 if (sync == MagickFalse)
581 image_view=DestroyCacheView(image_view);
582 if (stack == MagickFalse)
584 x_offset+=(ssize_t) next->columns;
590 y_offset+=(ssize_t) next->rows;
592 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
593 if (proceed == MagickFalse)
595 next=GetNextImageInList(next);
597 append_view=DestroyCacheView(append_view);
598 if (status == MagickFalse)
599 append_image=DestroyImage(append_image);
600 return(append_image);
627MagickExport ExceptionType CatchImageException(Image *image)
635 assert(image != (
const Image *) NULL);
636 assert(image->signature == MagickCoreSignature);
637 if (IsEventLogging() != MagickFalse)
638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
639 exception=AcquireExceptionInfo();
640 GetImageException(image,exception);
641 CatchException(exception);
642 severity=exception->severity;
643 exception=DestroyExceptionInfo(exception);
678MagickExport MagickBooleanType ClipImage(Image *image)
680 return(ClipImagePath(image,
"#1",MagickTrue));
683MagickExport MagickBooleanType ClipImagePath(Image *image,
const char *pathname,
684 const MagickBooleanType inside)
686#define ClipImagePathTag "ClipPath/Image"
701 assert(image != (
const Image *) NULL);
702 assert(image->signature == MagickCoreSignature);
703 assert(pathname != NULL);
704 if (IsEventLogging() != MagickFalse)
705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
706 property=AcquireString(pathname);
707 (void) FormatLocaleString(property,MaxTextExtent,
"8BIM:1999,2998:%s",
709 value=GetImageProperty(image,property);
710 property=DestroyString(property);
711 if (value == (
const char *) NULL)
713 ThrowFileException(&image->exception,OptionError,
"NoClipPathDefined",
717 image_info=AcquireImageInfo();
718 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
719 (void) ConcatenateMagickString(image_info->filename,
"_",MagickPathExtent);
720 sanitized_pathname=SanitizeString(pathname);
721 (void) ConcatenateMagickString(image_info->filename,sanitized_pathname,
723 sanitized_pathname=DestroyString(sanitized_pathname);
724 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
725 image_info=DestroyImageInfo(image_info);
726 if (clip_mask == (Image *) NULL)
728 if (clip_mask->storage_class == PseudoClass)
730 (void) SyncImage(clip_mask);
731 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
734 if (inside == MagickFalse)
735 (void) NegateImage(clip_mask,MagickFalse);
736 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
737 "8BIM:1999,2998:%s\nPS",pathname);
738 (void) SetImageClipMask(image,clip_mask);
739 clip_mask=DestroyImage(clip_mask);
782MagickExport Image *CloneImage(
const Image *image,
const size_t columns,
783 const size_t rows,
const MagickBooleanType detach,ExceptionInfo *exception)
798 assert(image != (
const Image *) NULL);
799 assert(image->signature == MagickCoreSignature);
800 assert(exception != (ExceptionInfo *) NULL);
801 assert(exception->signature == MagickCoreSignature);
802 if (IsEventLogging() != MagickFalse)
803 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
804 if ((image->columns == 0) || (image->rows == 0))
806 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
807 "NegativeOrZeroImageSize",
"`%s'",image->filename);
808 return((Image *) NULL);
810 clone_image=(Image *) AcquireCriticalMemory(
sizeof(*clone_image));
811 (void) memset(clone_image,0,
sizeof(*clone_image));
812 clone_image->signature=MagickCoreSignature;
813 clone_image->storage_class=image->storage_class;
814 clone_image->channels=image->channels;
815 clone_image->colorspace=image->colorspace;
816 clone_image->matte=image->matte;
817 clone_image->columns=image->columns;
818 clone_image->rows=image->rows;
819 clone_image->dither=image->dither;
820 (void) CloneImageProfiles(clone_image,image);
821 (void) CloneImageProperties(clone_image,image);
822 (void) CloneImageArtifacts(clone_image,image);
823 GetTimerInfo(&clone_image->timer);
824 InitializeExceptionInfo(&clone_image->exception);
825 InheritException(&clone_image->exception,&image->exception);
826 if (image->ascii85 != (
void *) NULL)
827 Ascii85Initialize(clone_image);
828 clone_image->extent=image->extent;
829 clone_image->magick_columns=image->magick_columns;
830 clone_image->magick_rows=image->magick_rows;
831 clone_image->type=image->type;
832 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
834 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
835 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
836 clone_image->progress_monitor=image->progress_monitor;
837 clone_image->client_data=image->client_data;
838 clone_image->reference_count=1;
839 clone_image->next=image->next;
840 clone_image->previous=image->previous;
841 clone_image->list=NewImageList();
842 clone_image->clip_mask=NewImageList();
843 clone_image->mask=NewImageList();
844 if (detach == MagickFalse)
845 clone_image->blob=ReferenceBlob(image->blob);
848 clone_image->next=NewImageList();
849 clone_image->previous=NewImageList();
850 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
852 clone_image->ping=image->ping;
853 clone_image->timestamp=image->timestamp;
854 clone_image->ttl=image->ttl;
855 clone_image->debug=image->debug;
856 clone_image->semaphore=AllocateSemaphoreInfo();
857 if (image->colormap != (PixelPacket *) NULL)
862 clone_image->colors=image->colors;
863 length=(size_t) image->colors;
864 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length+1,
865 sizeof(*clone_image->colormap));
866 if (clone_image->colormap == (PixelPacket *) NULL)
868 clone_image=DestroyImage(clone_image);
869 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
871 (void) memcpy(clone_image->colormap,image->colormap,length*
872 sizeof(*clone_image->colormap));
874 if ((columns == 0) || (rows == 0))
876 if (image->montage != (
char *) NULL)
877 (void) CloneString(&clone_image->montage,image->montage);
878 if (image->directory != (
char *) NULL)
879 (void) CloneString(&clone_image->directory,image->directory);
880 if (image->clip_mask != (Image *) NULL)
881 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
883 if (image->mask != (Image *) NULL)
884 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
885 clone_image->cache=ReferencePixelCache(image->cache);
888 if ((columns == image->columns) && (rows == image->rows))
890 if (image->clip_mask != (Image *) NULL)
891 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
893 if (image->mask != (Image *) NULL)
894 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
898 if (image->columns != 0)
899 scale_x=(double) columns/(
double) image->columns;
900 if (image->rows != 0)
901 scale_y=(double) rows/(
double) image->rows;
902 clone_image->page.width=(size_t) CastDoubleToLong(floor(scale_x*
903 image->page.width+0.5));
904 clone_image->page.height=(size_t) CastDoubleToLong(floor(scale_y*
905 image->page.height+0.5));
906 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
907 scale_x=scale_y=MagickMin(scale_x,scale_y);
908 clone_image->page.x=CastDoubleToLong(ceil(scale_x*image->page.x-0.5));
909 clone_image->tile_offset.x=CastDoubleToLong(ceil(scale_x*
910 image->tile_offset.x-0.5));
911 clone_image->page.y=CastDoubleToLong(ceil(scale_y*image->page.y-0.5));
912 clone_image->tile_offset.y=CastDoubleToLong(ceil(scale_y*
913 image->tile_offset.y-0.5));
914 clone_image->cache=ClonePixelCache(image->cache);
915 if (SetImageExtent(clone_image,columns,rows) == MagickFalse)
917 InheritException(exception,&clone_image->exception);
918 clone_image=DestroyImage(clone_image);
947MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
952 clone_info=AcquireImageInfo();
953 if (image_info == (ImageInfo *) NULL)
955 clone_info->compression=image_info->compression;
956 clone_info->temporary=image_info->temporary;
957 clone_info->adjoin=image_info->adjoin;
958 clone_info->antialias=image_info->antialias;
959 clone_info->scene=image_info->scene;
960 clone_info->number_scenes=image_info->number_scenes;
961 clone_info->depth=image_info->depth;
962 if (image_info->size != (
char *) NULL)
963 (void) CloneString(&clone_info->size,image_info->size);
964 if (image_info->extract != (
char *) NULL)
965 (void) CloneString(&clone_info->extract,image_info->extract);
966 if (image_info->scenes != (
char *) NULL)
967 (void) CloneString(&clone_info->scenes,image_info->scenes);
968 if (image_info->page != (
char *) NULL)
969 (void) CloneString(&clone_info->page,image_info->page);
970 clone_info->interlace=image_info->interlace;
971 clone_info->endian=image_info->endian;
972 clone_info->units=image_info->units;
973 clone_info->quality=image_info->quality;
974 if (image_info->sampling_factor != (
char *) NULL)
975 (void) CloneString(&clone_info->sampling_factor,
976 image_info->sampling_factor);
977 if (image_info->server_name != (
char *) NULL)
978 (void) CloneString(&clone_info->server_name,image_info->server_name);
979 if (image_info->font != (
char *) NULL)
980 (void) CloneString(&clone_info->font,image_info->font);
981 if (image_info->texture != (
char *) NULL)
982 (void) CloneString(&clone_info->texture,image_info->texture);
983 if (image_info->density != (
char *) NULL)
984 (void) CloneString(&clone_info->density,image_info->density);
985 clone_info->pointsize=image_info->pointsize;
986 clone_info->fuzz=image_info->fuzz;
987 clone_info->pen=image_info->pen;
988 clone_info->background_color=image_info->background_color;
989 clone_info->border_color=image_info->border_color;
990 clone_info->matte_color=image_info->matte_color;
991 clone_info->transparent_color=image_info->transparent_color;
992 clone_info->dither=image_info->dither;
993 clone_info->monochrome=image_info->monochrome;
994 clone_info->colors=image_info->colors;
995 clone_info->colorspace=image_info->colorspace;
996 clone_info->type=image_info->type;
997 clone_info->orientation=image_info->orientation;
998 clone_info->preview_type=image_info->preview_type;
999 clone_info->group=image_info->group;
1000 clone_info->ping=image_info->ping;
1001 clone_info->verbose=image_info->verbose;
1002 if (image_info->view != (
char *) NULL)
1003 (void) CloneString(&clone_info->view,image_info->view);
1004 if (image_info->authenticate != (
char *) NULL)
1005 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
1006 (void) CloneImageOptions(clone_info,image_info);
1007 clone_info->progress_monitor=image_info->progress_monitor;
1008 clone_info->client_data=image_info->client_data;
1009 clone_info->cache=image_info->cache;
1010 if (image_info->cache != (
void *) NULL)
1011 clone_info->cache=ReferencePixelCache(image_info->cache);
1012 if (image_info->profile != (
void *) NULL)
1013 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1014 image_info->profile);
1015 SetImageInfoFile(clone_info,image_info->file);
1016 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1017 clone_info->stream=image_info->stream;
1018 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
1019 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
1020 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
1021 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
1022 (void) CopyMagickString(clone_info->filename,image_info->filename,
1024 clone_info->subimage=image_info->scene;
1025 clone_info->subrange=image_info->number_scenes;
1026 clone_info->channel=image_info->channel;
1027 clone_info->debug=image_info->debug;
1028 clone_info->signature=image_info->signature;
1065MagickExport MagickBooleanType CopyImagePixels(Image *image,
1066 const Image *source_image,
const RectangleInfo *geometry,
1067 const OffsetInfo *offset,ExceptionInfo *exception)
1069#define CopyImageTag "Copy/Image"
1084 assert(image != (Image *) NULL);
1085 assert(source_image != (Image *) NULL);
1086 assert(geometry != (RectangleInfo *) NULL);
1087 assert(offset != (OffsetInfo *) NULL);
1088 if (IsEventLogging() != MagickFalse)
1089 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1090 if ((offset->x < 0) || (offset->y < 0) ||
1091 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1092 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1093 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1095 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1096 return(MagickFalse);
1102 source_view=AcquireVirtualCacheView(source_image,exception);
1103 image_view=AcquireAuthenticCacheView(image,exception);
1104#if defined(MAGICKCORE_OPENMP_SUPPORT)
1105 #pragma omp parallel for schedule(static) shared(progress,status) \
1106 magick_number_threads(source_image,image,geometry->height,2)
1108 for (y=0; y < (ssize_t) geometry->height; y++)
1111 *magick_restrict source_indexes;
1117 *magick_restrict indexes;
1125 if (status == MagickFalse)
1127 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1128 geometry->width,1,exception);
1129 q=GetCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1130 geometry->width,1,exception);
1131 if ((p == (
const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1136 source_indexes=GetCacheViewVirtualIndexQueue(source_view);
1137 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1138 for (x=0; x < (ssize_t) geometry->width; x++)
1141 if (image->colorspace == CMYKColorspace)
1142 indexes[x]=source_indexes[x];
1146 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1148 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1153#if defined(MAGICKCORE_OPENMP_SUPPORT)
1157 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1158 if (proceed == MagickFalse)
1162 image_view=DestroyCacheView(image_view);
1163 source_view=DestroyCacheView(source_view);
1190MagickExport Image *DestroyImage(Image *image)
1198 assert(image != (Image *) NULL);
1199 assert(image->signature == MagickCoreSignature);
1200 if (IsEventLogging() != MagickFalse)
1201 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1202 destroy=MagickFalse;
1203 LockSemaphoreInfo(image->semaphore);
1204 image->reference_count--;
1205 if (image->reference_count == 0)
1207 UnlockSemaphoreInfo(image->semaphore);
1208 if (destroy == MagickFalse)
1209 return((Image *) NULL);
1213 DestroyImagePixels(image);
1214 if (image->clip_mask != (Image *) NULL)
1215 image->clip_mask=DestroyImage(image->clip_mask);
1216 if (image->mask != (Image *) NULL)
1217 image->mask=DestroyImage(image->mask);
1218 if (image->montage != (
char *) NULL)
1219 image->montage=DestroyString(image->montage);
1220 if (image->directory != (
char *) NULL)
1221 image->directory=DestroyString(image->directory);
1222 if (image->colormap != (PixelPacket *) NULL)
1223 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1224 if (image->geometry != (
char *) NULL)
1225 image->geometry=DestroyString(image->geometry);
1226 DestroyImageProfiles(image);
1227 DestroyImageProperties(image);
1228 DestroyImageArtifacts(image);
1229 if (image->ascii85 != (Ascii85Info*) NULL)
1230 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1232 (void) ClearExceptionInfo(&image->exception,MagickTrue);
1234 DestroySemaphoreInfo(&image->semaphore);
1235 image->signature=(~MagickCoreSignature);
1236 image=(Image *) RelinquishMagickMemory(image);
1263MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1265 assert(image_info != (ImageInfo *) NULL);
1266 assert(image_info->signature == MagickCoreSignature);
1267 if (IsEventLogging() != MagickFalse)
1268 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1269 image_info->filename);
1270 if (image_info->size != (
char *) NULL)
1271 image_info->size=DestroyString(image_info->size);
1272 if (image_info->extract != (
char *) NULL)
1273 image_info->extract=DestroyString(image_info->extract);
1274 if (image_info->scenes != (
char *) NULL)
1275 image_info->scenes=DestroyString(image_info->scenes);
1276 if (image_info->page != (
char *) NULL)
1277 image_info->page=DestroyString(image_info->page);
1278 if (image_info->sampling_factor != (
char *) NULL)
1279 image_info->sampling_factor=DestroyString(
1280 image_info->sampling_factor);
1281 if (image_info->server_name != (
char *) NULL)
1282 image_info->server_name=DestroyString(
1283 image_info->server_name);
1284 if (image_info->font != (
char *) NULL)
1285 image_info->font=DestroyString(image_info->font);
1286 if (image_info->texture != (
char *) NULL)
1287 image_info->texture=DestroyString(image_info->texture);
1288 if (image_info->density != (
char *) NULL)
1289 image_info->density=DestroyString(image_info->density);
1290 if (image_info->view != (
char *) NULL)
1291 image_info->view=DestroyString(image_info->view);
1292 if (image_info->authenticate != (
char *) NULL)
1293 image_info->authenticate=DestroyString(
1294 image_info->authenticate);
1295 DestroyImageOptions(image_info);
1296 if (image_info->cache != (
void *) NULL)
1297 image_info->cache=DestroyPixelCache(image_info->cache);
1298 if (image_info->profile != (StringInfo *) NULL)
1299 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1300 image_info->profile);
1301 image_info->signature=(~MagickCoreSignature);
1302 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1330MagickExport
void DisassociateImageStream(Image *image)
1332 assert(image != (Image *) NULL);
1333 assert(image->signature == MagickCoreSignature);
1334 if (IsEventLogging() != MagickFalse)
1335 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1336 DisassociateBlob(image);
1361MagickExport Image *GetImageClipMask(
const Image *image,
1362 ExceptionInfo *exception)
1364 assert(image != (
const Image *) NULL);
1365 assert(image->signature == MagickCoreSignature);
1366 if (IsEventLogging() != MagickFalse)
1367 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1368 if (image->clip_mask == (Image *) NULL)
1369 return((Image *) NULL);
1370 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1398MagickExport
void GetImageException(Image *image,ExceptionInfo *exception)
1403 assert(image != (Image *) NULL);
1404 assert(image->signature == MagickCoreSignature);
1405 assert(exception != (ExceptionInfo *) NULL);
1406 assert(exception->signature == MagickCoreSignature);
1407 if (IsEventLogging() != MagickFalse)
1408 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1409 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1411 if (next->exception.severity == UndefinedException)
1413 if (next->exception.severity > exception->severity)
1414 InheritException(exception,&next->exception);
1415 next->exception.severity=UndefinedException;
1441MagickExport
void GetImageInfo(ImageInfo *image_info)
1449 assert(image_info != (ImageInfo *) NULL);
1450 if (IsEventLogging() != MagickFalse)
1451 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1452 (void) memset(image_info,0,
sizeof(*image_info));
1453 image_info->adjoin=MagickTrue;
1454 image_info->interlace=NoInterlace;
1455 image_info->channel=DefaultChannels;
1456 image_info->quality=UndefinedCompressionQuality;
1457 image_info->antialias=MagickTrue;
1458 image_info->dither=MagickTrue;
1459 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1460 if (synchronize != (
const char *) NULL)
1462 image_info->synchronize=IsStringTrue(synchronize);
1463 synchronize=DestroyString(synchronize);
1465 GetPixelPacketRGBA(BackgroundColorRGBA,&image_info->background_color);
1466 GetPixelPacketRGBA(BorderColorRGBA,&image_info->border_color);
1467 GetPixelPacketRGBA(MatteColorRGBA,&image_info->matte_color);
1468 GetPixelPacketRGBA(TransparentColorRGBA,&image_info->transparent_color);
1469 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1471 image_info->signature=MagickCoreSignature;
1496MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1498 return(image_info->file);
1523MagickExport Image *GetImageMask(
const Image *image,ExceptionInfo *exception)
1525 assert(image != (
const Image *) NULL);
1526 assert(image->signature == MagickCoreSignature);
1527 if (IsEventLogging() != MagickFalse)
1528 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1529 if (image->mask == (Image *) NULL)
1530 return((Image *) NULL);
1531 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1557MagickExport
size_t GetImageChannels(Image *image)
1559 assert(image != (Image *) NULL);
1560 assert(image->signature == MagickCoreSignature);
1561 if (IsEventLogging() != MagickFalse)
1562 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1563 return(image->channels);
1588MagickExport ssize_t GetImageReferenceCount(Image *image)
1593 assert(image != (Image *) NULL);
1594 assert(image->signature == MagickCoreSignature);
1595 if (IsEventLogging() != MagickFalse)
1596 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1597 LockSemaphoreInfo(image->semaphore);
1598 reference_count=image->reference_count;
1599 UnlockSemaphoreInfo(image->semaphore);
1600 return(reference_count);
1627MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1629 assert(image != (Image *) NULL);
1630 assert(image->signature == MagickCoreSignature);
1631 if (IsEventLogging() != MagickFalse)
1632 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1633 return(GetPixelCacheVirtualMethod(image));
1670static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1674 specifier = end[-1];
1682 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1683 return(MagickFalse);
1684 if ((length == 1) && (*start == specifier))
1693 if ((length >= 3) && (start[1] ==
'0'))
1694 return(MagickFalse);
1697 for ( ; i < (length-1); i++)
1698 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1699 return(MagickFalse);
1702 return(MagickFalse);
1705MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1706 Image *image,
const char *format,
int value,
char *filename)
1710 pattern[MagickPathExtent];
1715 assert(format != (
const char *) NULL);
1716 assert(filename != (
char *) NULL);
1717 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1719 (void) CopyMagickString(filename,format,MagickPathExtent);
1720 return(strlen(filename));
1722 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1740 specifier_start=cursor;
1741 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1743 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1746 *specifier_end = cursor+1;
1748 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1751 format_specifier[MagickPathExtent];
1754 length = cursor-specifier_start,
1760 (void) snprintf(format_specifier,
sizeof(format_specifier),
1761 "%%%.*s%c",(
int) length,specifier_start,*cursor);
1762 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1764 pattern_length=strlen(pattern);
1765 if ((count <= 0) || ((
size_t) count != pattern_length))
1767 if ((p-filename+pattern_length) >= MagickPathExtent)
1769 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
1787 *end = strchr(cursor,
']'),
1788 *option = (
const char *) NULL;
1794 if (end == (
const char *) NULL)
1796 extent=(size_t) (end-cursor-1);
1797 if (extent >=
sizeof(pattern))
1799 (void) CopyMagickString(pattern,cursor+1,extent+1);
1800 pattern[extent]=
'\0';
1803 option=GetImageProperty(image,pattern);
1804 if (option == (
const char *) NULL)
1805 option=GetImageArtifact(image,pattern);
1807 if ((option == (
const char *) NULL) &&
1808 (image_info != (ImageInfo *) NULL))
1809 option=GetImageOption(image_info,pattern);
1810 if (option == (
const char *) NULL)
1812 option_length=strlen(option);
1813 if ((p-filename+option_length) >= MagickPathExtent)
1815 (void) CopyMagickString(p,option,MagickPathExtent-(p-filename));
1824 if ((p-filename+1) >= MagickPathExtent)
1829 return(strlen(filename));
1859MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1860 ExceptionInfo *exception)
1862#if !defined(MAGICKCORE_HDRI_SUPPORT)
1865 return(MagickFalse);
1879 assert(image != (Image *) NULL);
1880 assert(image->signature == MagickCoreSignature);
1881 if (IsEventLogging() != MagickFalse)
1882 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1883 GetMagickPixelPacket(image,&zero);
1884 image_view=AcquireVirtualCacheView(image,exception);
1885#if defined(MAGICKCORE_OPENMP_SUPPORT)
1886 #pragma omp parallel for schedule(static) shared(hdri) \
1887 magick_number_threads(image,image,image->rows,2)
1889 for (y=0; y < (ssize_t) image->rows; y++)
1903 if (hdri != MagickFalse)
1905 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1906 if (p == (
const PixelPacket *) NULL)
1908 indexes=GetCacheViewVirtualIndexQueue(image_view);
1910 for (x=0; x < (ssize_t) image->columns; x++)
1912 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1913 if ((pixel.red < 0.0) || (pixel.red > (MagickRealType) QuantumRange) ||
1914 (pixel.red != (QuantumAny) pixel.red))
1916 if ((pixel.green < 0.0) ||
1917 (pixel.green > (MagickRealType) QuantumRange) ||
1918 (pixel.green != (QuantumAny) pixel.green))
1920 if ((pixel.blue < 0.0) || (pixel.blue > (MagickRealType) QuantumRange) ||
1921 (pixel.blue != (QuantumAny) pixel.blue))
1923 if (pixel.matte != MagickFalse)
1925 if ((pixel.opacity < 0.0) || (pixel.opacity > (MagickRealType) QuantumRange) ||
1926 (pixel.opacity != (QuantumAny) pixel.opacity))
1929 if (pixel.colorspace == CMYKColorspace)
1931 if ((pixel.index < 0.0) ||
1932 (pixel.index > (MagickRealType) QuantumRange) ||
1933 (pixel.index != (QuantumAny) pixel.index))
1936 if (hdri != MagickFalse)
1941 image_view=DestroyCacheView(image_view);
1969MagickExport MagickBooleanType IsImageObject(
const Image *image)
1974 assert(image != (Image *) NULL);
1975 if (IsEventLogging() != MagickFalse)
1976 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1977 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1978 if (p->signature != MagickCoreSignature)
1979 return(MagickFalse);
2006MagickExport MagickBooleanType IsTaintImage(
const Image *image)
2009 magick[MaxTextExtent],
2010 filename[MaxTextExtent];
2015 assert(image != (Image *) NULL);
2016 assert(image->signature == MagickCoreSignature);
2017 if (IsEventLogging() != MagickFalse)
2018 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2019 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2020 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2021 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2023 if (p->taint != MagickFalse)
2025 if (LocaleCompare(p->magick,magick) != 0)
2027 if (LocaleCompare(p->filename,filename) != 0)
2030 return(MagickFalse);
2059MagickExport MagickBooleanType ModifyImage(Image **image,
2060 ExceptionInfo *exception)
2065 assert(image != (Image **) NULL);
2066 assert(*image != (Image *) NULL);
2067 assert((*image)->signature == MagickCoreSignature);
2068 if (IsEventLogging() != MagickFalse)
2069 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2070 if (GetImageReferenceCount(*image) <= 1)
2072 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2073 LockSemaphoreInfo((*image)->semaphore);
2074 (*image)->reference_count--;
2075 UnlockSemaphoreInfo((*image)->semaphore);
2110MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2111 const size_t width,
const size_t height,
const MagickPixelPacket *background)
2128 assert(image_info != (
const ImageInfo *) NULL);
2129 assert(image_info->signature == MagickCoreSignature);
2130 assert(background != (
const MagickPixelPacket *) NULL);
2131 if (IsEventLogging() != MagickFalse)
2132 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2133 image=AcquireImage(image_info);
2134 image->columns=width;
2136 image->colorspace=background->colorspace;
2137 image->matte=background->matte;
2138 image->fuzz=background->fuzz;
2139 image->depth=background->depth;
2141 exception=(&image->exception);
2142 image_view=AcquireAuthenticCacheView(image,exception);
2143#if defined(MAGICKCORE_OPENMP_SUPPORT)
2144 #pragma omp parallel for schedule(static) shared(status) \
2145 magick_number_threads(image,image,image->rows,2)
2147 for (y=0; y < (ssize_t) image->rows; y++)
2150 *magick_restrict indexes;
2158 if (status == MagickFalse)
2160 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2161 if (q == (PixelPacket *) NULL)
2166 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2167 for (x=0; x < (ssize_t) image->columns; x++)
2169 SetPixelPacket(image,background,q,indexes+x);
2172 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2175 image_view=DestroyCacheView(image_view);
2176 if (status == MagickFalse)
2177 image=DestroyImage(image);
2204MagickExport Image *ReferenceImage(Image *image)
2206 assert(image != (Image *) NULL);
2207 assert(image->signature == MagickCoreSignature);
2208 if (IsEventLogging() != MagickFalse)
2209 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2210 LockSemaphoreInfo(image->semaphore);
2211 image->reference_count++;
2212 UnlockSemaphoreInfo(image->semaphore);
2240MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2248 assert(image != (Image *) NULL);
2249 assert(image->signature == MagickCoreSignature);
2250 if (IsEventLogging() != MagickFalse)
2251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2252 flags=ParseAbsoluteGeometry(page,&geometry);
2253 if ((flags & WidthValue) != 0)
2255 if ((flags & HeightValue) == 0)
2256 geometry.height=geometry.width;
2257 image->page.width=geometry.width;
2258 image->page.height=geometry.height;
2260 if ((flags & AspectValue) != 0)
2262 if ((flags & XValue) != 0)
2263 image->page.x+=geometry.x;
2264 if ((flags & YValue) != 0)
2265 image->page.y+=geometry.y;
2269 if ((flags & XValue) != 0)
2271 image->page.x=geometry.x;
2272 if ((image->page.width == 0) && (geometry.x > 0))
2273 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2275 if ((flags & YValue) != 0)
2277 image->page.y=geometry.y;
2278 if ((image->page.height == 0) && (geometry.y > 0))
2279 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2311MagickExport MagickBooleanType ResetImagePixels(Image *image,
2312 ExceptionInfo *exception)
2329 assert(image != (Image *) NULL);
2330 assert(image->signature == MagickCoreSignature);
2331 if (IsEventLogging() != MagickFalse)
2332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2333 pixels=AcquirePixelCachePixels(image,&length,exception);
2334 if (pixels != (
void *) NULL)
2339 (void) memset((
void *) pixels,0,(
size_t) length);
2346 image_view=AcquireAuthenticCacheView(image,exception);
2347#if defined(MAGICKCORE_OPENMP_SUPPORT)
2348 #pragma omp parallel for schedule(static) shared(status) \
2349 magick_number_threads(image,image,image->rows,2)
2351 for (y=0; y < (ssize_t) image->rows; y++)
2354 *magick_restrict indexes;
2362 if (status == MagickFalse)
2364 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2365 if (q == (PixelPacket *) NULL)
2370 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2371 for (x=0; x < (ssize_t) image->columns; x++)
2373 (void) memset(q,0,
sizeof(PixelPacket));
2374 if ((image->storage_class == PseudoClass) ||
2375 (image->colorspace == CMYKColorspace))
2379 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2382 image_view=DestroyCacheView(image_view);
2410MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2433 assert(image != (Image *) NULL);
2434 assert(image->signature == MagickCoreSignature);
2435 if (IsEventLogging() != MagickFalse)
2436 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2437 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2438 return(MagickFalse);
2439 if ((IsPixelGray(&image->background_color) == MagickFalse) &&
2440 (IsGrayColorspace(image->colorspace) != MagickFalse))
2441 (void) TransformImageColorspace(image,RGBColorspace);
2442 if ((image->background_color.opacity != OpaqueOpacity) &&
2443 (image->matte == MagickFalse))
2444 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
2445 GetMagickPixelPacket(image,&background);
2446 SetMagickPixelPacket(image,&image->background_color,(
const IndexPacket *)
2448 if (image->colorspace == CMYKColorspace)
2449 ConvertRGBToCMYK(&background);
2451 pixel.opacity=OpaqueOpacity;
2452 SetPixelPacket(image,&background,&pixel,&index);
2457 exception=(&image->exception);
2458 image_view=AcquireAuthenticCacheView(image,exception);
2459#if defined(MAGICKCORE_OPENMP_SUPPORT)
2460 #pragma omp parallel for schedule(static) shared(status) \
2461 magick_number_threads(image,image,image->rows,2)
2463 for (y=0; y < (ssize_t) image->rows; y++)
2471 if (status == MagickFalse)
2473 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2474 if (q == (PixelPacket *) NULL)
2479 for (x=0; x < (ssize_t) image->columns; x++)
2481 if (image->colorspace == CMYKColorspace)
2484 *magick_restrict indexes;
2486 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2487 for (x=0; x < (ssize_t) image->columns; x++)
2488 SetPixelIndex(indexes+x,index);
2490 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2493 image_view=DestroyCacheView(image_view);
2522MagickExport MagickBooleanType SetImageChannels(Image *image,
2523 const size_t channels)
2525 image->channels=channels;
2554MagickExport MagickBooleanType SetImageColor(Image *image,
2555 const MagickPixelPacket *color)
2569 assert(image != (Image *) NULL);
2570 assert(image->signature == MagickCoreSignature);
2571 assert(color != (
const MagickPixelPacket *) NULL);
2572 if (IsEventLogging() != MagickFalse)
2573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2574 image->colorspace=color->colorspace;
2575 image->matte=color->matte;
2576 image->fuzz=color->fuzz;
2577 image->depth=color->depth;
2579 exception=(&image->exception);
2580 image_view=AcquireAuthenticCacheView(image,exception);
2581#if defined(MAGICKCORE_OPENMP_SUPPORT)
2582 #pragma omp parallel for schedule(static) shared(status) \
2583 magick_number_threads(image,image,image->rows,2)
2585 for (y=0; y < (ssize_t) image->rows; y++)
2588 *magick_restrict indexes;
2596 if (status == MagickFalse)
2598 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2599 if (q == (PixelPacket *) NULL)
2604 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2605 for (x=0; x < (ssize_t) image->columns; x++)
2607 SetPixelPacket(image,color,q,
2608 indexes == (IndexPacket *) NULL ? NULL : indexes+x);
2611 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2614 image_view=DestroyCacheView(image_view);
2644MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2645 const ClassType storage_class)
2647 assert(image != (Image *) NULL);
2648 assert(image->signature == MagickCoreSignature);
2649 if (IsEventLogging() != MagickFalse)
2650 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2651 image->storage_class=storage_class;
2652 return(SyncImagePixelCache(image,&image->exception));
2682MagickExport MagickBooleanType SetImageClipMask(Image *image,
2683 const Image *clip_mask)
2685 assert(image != (Image *) NULL);
2686 assert(image->signature == MagickCoreSignature);
2687 if (IsEventLogging() != MagickFalse)
2688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2689 if (clip_mask != (
const Image *) NULL)
2690 if ((clip_mask->columns != image->columns) ||
2691 (clip_mask->rows != image->rows))
2692 ThrowBinaryImageException(ImageError,
"ImageSizeDiffers",image->filename);
2693 if (image->clip_mask != (Image *) NULL)
2694 image->clip_mask=DestroyImage(image->clip_mask);
2695 image->clip_mask=NewImageList();
2696 if (clip_mask == (Image *) NULL)
2698 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2699 return(MagickFalse);
2700 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2701 if (image->clip_mask == (Image *) NULL)
2702 return(MagickFalse);
2733MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2736 if ((columns == 0) || (rows == 0))
2737 ThrowBinaryImageException(ImageError,
"NegativeOrZeroImageSize",
2739 if ((columns > (
size_t) MAGICK_SSIZE_MAX) ||
2740 (rows > (
size_t) MAGICK_SSIZE_MAX))
2741 ThrowBinaryImageException(ImageError,
"ImageSizeLimitExceeded",
2743 image->columns=columns;
2745 if (image->depth == 0)
2748 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2749 ImageError,
"ImageDepthNotSupported",
"`%s'",image->filename);
2751 if (image->depth > (8*
sizeof(MagickSizeType)))
2753 image->depth=8*
sizeof(MagickSizeType);
2754 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2755 ImageError,
"ImageDepthNotSupported",
"`%s'",image->filename);
2757 return(SyncImagePixelCache(image,&image->exception));
2794MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2795 const unsigned int frames,ExceptionInfo *exception)
2798 extension[MaxTextExtent],
2799 filename[MaxTextExtent],
2800 magic[MaxTextExtent],
2802 subimage[MaxTextExtent];
2826 magick[2*MaxTextExtent];
2831 assert(image_info != (ImageInfo *) NULL);
2832 assert(image_info->signature == MagickCoreSignature);
2833 if (IsEventLogging() != MagickFalse)
2834 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2835 image_info->filename);
2837 GetPathComponent(image_info->filename,SubimagePath,subimage);
2838 if (*subimage !=
'\0')
2843 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2845 if (IsGeometry(subimage) != MagickFalse)
2846 (void) CloneString(&image_info->extract,subimage);
2854 (void) CloneString(&image_info->scenes,subimage);
2855 image_info->scene=StringToUnsignedLong(image_info->scenes);
2856 image_info->number_scenes=image_info->scene;
2857 p=image_info->scenes;
2858 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2860 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2862 first=(size_t) strtol(p,&q,10);
2864 while (isspace((
int) ((
unsigned char) *q)) != 0)
2867 last=(size_t) strtol(q+1,&q,10);
2870 if (first < image_info->scene)
2871 image_info->scene=first;
2872 if (last > image_info->number_scenes)
2873 image_info->number_scenes=last;
2876 image_info->number_scenes-=image_info->scene-1;
2877 image_info->subimage=image_info->scene;
2878 image_info->subrange=image_info->number_scenes;
2882 if (*image_info->magick ==
'\0')
2883 GetPathComponent(image_info->filename,ExtensionPath,extension);
2884 if (*extension !=
'\0')
2887 path[MaxTextExtent];
2892 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2893 GetPathComponent(path,ExtensionPath,extension);
2895 image_info->affirm=MagickFalse;
2896 sans_exception=AcquireExceptionInfo();
2897 if ((*extension !=
'\0') && (IsGlob(extension) == MagickFalse))
2906 *format_type_formats[] =
2930 (void) CopyMagickString(magic,extension,MaxTextExtent);
2935 format_type=UndefinedFormatType;
2937 while ((format_type == UndefinedFormatType) &&
2938 (format_type_formats[i] != (
char *) NULL))
2940 if ((*magic == *format_type_formats[i]) &&
2941 (LocaleCompare(magic,format_type_formats[i]) == 0))
2942 format_type=ExplicitFormatType;
2945 magick_info=GetMagickInfo(magic,sans_exception);
2946 if ((magick_info != (
const MagickInfo *) NULL) &&
2947 (magick_info->format_type != UndefinedFormatType))
2948 format_type=magick_info->format_type;
2949 if (format_type == UndefinedFormatType)
2950 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2952 if (format_type == ExplicitFormatType)
2954 image_info->affirm=MagickTrue;
2955 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2957 if (LocaleCompare(magic,
"RGB") == 0)
2958 image_info->affirm=MagickFalse;
2964 GetPathComponent(image_info->filename,MagickPath,magic);
2967 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
2968 magick_info=GetMagickInfo(magic,sans_exception);
2969 if ((magick_info != (
const MagickInfo *) NULL) &&
2970 (magick_info->format_type == ExplicitFormatType))
2971 image_info->affirm=MagickTrue;
2973 GetPathComponent(image_info->filename,CanonicalPath,filename);
2975 GetPathComponent(image_info->filename,SubcanonicalPath,filename);
2976 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2987 magick_info=GetMagickInfo(magic,sans_exception);
2988 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2989 if (delegate_info == (
const DelegateInfo *) NULL)
2990 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2991 if (((magick_info != (
const MagickInfo *) NULL) ||
2992 (delegate_info != (
const DelegateInfo *) NULL)) &&
2993 (IsMagickConflict(magic) == MagickFalse))
2995 image_info->affirm=MagickTrue;
2996 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2997 GetPathComponent(image_info->filename,CanonicalPath,filename);
2998 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
2999 GetPathComponent(image_info->filename,SubcanonicalPath,filename);
3000 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3003 sans_exception=DestroyExceptionInfo(sans_exception);
3004 if ((magick_info == (
const MagickInfo *) NULL) ||
3005 (GetMagickEndianSupport(magick_info) == MagickFalse))
3006 image_info->endian=UndefinedEndian;
3007 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3012 (void) InterpretImageFilename(image_info,(Image *) NULL,
3013 image_info->filename,(
int) image_info->scene,filename);
3014 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3015 (strchr(filename,
'%') == (
char *) NULL))
3016 image_info->adjoin=MagickFalse;
3018 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3023 magick_info=GetMagickInfo(magic,exception);
3024 if (magick_info != (
const MagickInfo *) NULL)
3025 if (GetMagickAdjoin(magick_info) == MagickFalse)
3026 image_info->adjoin=MagickFalse;
3028 if (image_info->affirm != MagickFalse)
3035 image=AcquireImage(image_info);
3036 (void) CopyMagickString(image->filename,image_info->filename,
3038 sans_exception=AcquireExceptionInfo();
3039 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3040 sans_exception=DestroyExceptionInfo(sans_exception);
3041 if (status == MagickFalse)
3043 image=DestroyImage(image);
3044 return(MagickFalse);
3046 if ((IsBlobSeekable(image) == MagickFalse) ||
3047 (IsBlobExempt(image) != MagickFalse))
3053 status=ImageToFile(image,filename,exception);
3054 if (CloseBlob(image) == MagickFalse)
3056 if (status == MagickFalse)
3058 (void) RelinquishUniqueFileResource(filename);
3059 image=DestroyImage(image);
3060 return(MagickFalse);
3062 SetImageInfoFile(image_info,(FILE *) NULL);
3063 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3064 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3065 if (status == MagickFalse)
3067 (void) RelinquishUniqueFileResource(filename);
3068 image=DestroyImage(image);
3069 return(MagickFalse);
3071 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3072 image_info->temporary=MagickTrue;
3074 (void) memset(magick,0,
sizeof(magick));
3075 count=ReadBlob(image,2*MaxTextExtent,magick);
3076 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3077 (void) CloseBlob(image);
3078 image=DestroyImage(image);
3082 sans_exception=AcquireExceptionInfo();
3083 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3084 if ((magic_info != (
const MagicInfo *) NULL) &&
3085 (GetMagicName(magic_info) != (
char *) NULL))
3087 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3089 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3090 if ((magick_info == (
const MagickInfo *) NULL) ||
3091 (GetMagickEndianSupport(magick_info) == MagickFalse))
3092 image_info->endian=UndefinedEndian;
3093 sans_exception=DestroyExceptionInfo(sans_exception);
3096 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3097 if ((magick_info == (
const MagickInfo *) NULL) ||
3098 (GetMagickEndianSupport(magick_info) == MagickFalse))
3099 image_info->endian=UndefinedEndian;
3100 sans_exception=DestroyExceptionInfo(sans_exception);
3132MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3133 const size_t length)
3135 assert(image_info != (ImageInfo *) NULL);
3136 assert(image_info->signature == MagickCoreSignature);
3137 if (IsEventLogging() != MagickFalse)
3138 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3139 image_info->filename);
3140 image_info->blob=(
void *) blob;
3141 image_info->length=length;
3168MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3170 assert(image_info != (ImageInfo *) NULL);
3171 assert(image_info->signature == MagickCoreSignature);
3172 if (IsEventLogging() != MagickFalse)
3173 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3174 image_info->filename);
3175 image_info->file=file;
3203MagickExport MagickBooleanType SetImageMask(Image *image,
const Image *mask)
3205 assert(image != (Image *) NULL);
3206 assert(image->signature == MagickCoreSignature);
3207 if (IsEventLogging() != MagickFalse)
3208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3209 if (mask != (
const Image *) NULL)
3210 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3211 ThrowBinaryImageException(ImageError,
"ImageSizeDiffers",image->filename);
3212 if (image->mask != (Image *) NULL)
3213 image->mask=DestroyImage(image->mask);
3214 image->mask=NewImageList();
3215 if (mask == (Image *) NULL)
3217 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3218 return(MagickFalse);
3219 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3220 if (image->mask == (Image *) NULL)
3221 return(MagickFalse);
3250MagickExport MagickBooleanType SetImageOpacity(Image *image,
3251 const Quantum opacity)
3265 assert(image != (Image *) NULL);
3266 assert(image->signature == MagickCoreSignature);
3267 if (IsEventLogging() != MagickFalse)
3268 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3269 image->matte=MagickTrue;
3271 exception=(&image->exception);
3272 image_view=AcquireAuthenticCacheView(image,exception);
3273#if defined(MAGICKCORE_OPENMP_SUPPORT)
3274 #pragma omp parallel for schedule(static) shared(status) \
3275 magick_number_threads(image,image,image->rows,2)
3277 for (y=0; y < (ssize_t) image->rows; y++)
3285 if (status == MagickFalse)
3287 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3288 if (q == (PixelPacket *) NULL)
3293 for (x=0; x < (ssize_t) image->columns; x++)
3295 SetPixelOpacity(q,opacity);
3298 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3301 image_view=DestroyCacheView(image_view);
3332MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(
const Image *image,
3333 const VirtualPixelMethod virtual_pixel_method)
3335 assert(image != (
const Image *) NULL);
3336 assert(image->signature == MagickCoreSignature);
3337 if (IsEventLogging() != MagickFalse)
3338 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3339 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3377static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3378 const ssize_t offset,ExceptionInfo *exception)
3405 if (images->previous == (Image *) NULL)
3408 SetGeometry(smush_image,&right_geometry);
3409 GravityAdjustGeometry(right_image->columns,right_image->rows,
3410 right_image->gravity,&right_geometry);
3411 left_image=images->previous;
3412 SetGeometry(smush_image,&left_geometry);
3413 GravityAdjustGeometry(left_image->columns,left_image->rows,
3414 left_image->gravity,&left_geometry);
3415 gap=right_image->columns;
3416 left_view=AcquireVirtualCacheView(left_image,exception);
3417 right_view=AcquireVirtualCacheView(right_image,exception);
3418 for (y=0; y < (ssize_t) smush_image->rows; y++)
3420 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3422 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3423 if ((p == (
const PixelPacket *) NULL) ||
3424 (GetPixelOpacity(p) != TransparentOpacity) ||
3425 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3428 i=(ssize_t) left_image->columns-x-1;
3429 for (x=0; x < (ssize_t) right_image->columns; x++)
3431 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3433 if ((p == (
const PixelPacket *) NULL) ||
3434 (GetPixelOpacity(p) != TransparentOpacity) ||
3435 ((x+i) >= (ssize_t) gap))
3438 if ((x+i) < (ssize_t) gap)
3441 right_view=DestroyCacheView(right_view);
3442 left_view=DestroyCacheView(left_view);
3443 if (y < (ssize_t) smush_image->rows)
3445 return((ssize_t) gap-offset);
3448static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3449 const ssize_t offset,ExceptionInfo *exception)
3476 if (images->previous == (Image *) NULL)
3478 bottom_image=images;
3479 SetGeometry(smush_image,&bottom_geometry);
3480 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3481 bottom_image->gravity,&bottom_geometry);
3482 top_image=images->previous;
3483 SetGeometry(smush_image,&top_geometry);
3484 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3486 gap=bottom_image->rows;
3487 top_view=AcquireVirtualCacheView(top_image,exception);
3488 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3489 for (x=0; x < (ssize_t) smush_image->columns; x++)
3491 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3493 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3494 if ((p == (
const PixelPacket *) NULL) ||
3495 (GetPixelOpacity(p) != TransparentOpacity) ||
3496 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3499 i=(ssize_t) top_image->rows-y-1;
3500 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3502 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3504 if ((p == (
const PixelPacket *) NULL) ||
3505 (GetPixelOpacity(p) != TransparentOpacity) ||
3506 ((y+i) >= (ssize_t) gap))
3509 if ((y+i) < (ssize_t) gap)
3512 bottom_view=DestroyCacheView(bottom_view);
3513 top_view=DestroyCacheView(top_view);
3514 if (x < (ssize_t) smush_image->columns)
3516 return((ssize_t) gap-offset);
3519MagickExport Image *SmushImages(
const Image *images,
3520 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3522#define SmushImageTag "Smush/Image"
3559 assert(images != (Image *) NULL);
3560 assert(images->signature == MagickCoreSignature);
3561 assert(exception != (ExceptionInfo *) NULL);
3562 assert(exception->signature == MagickCoreSignature);
3563 if (IsEventLogging() != MagickFalse)
3564 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3568 width=image->columns;
3570 next=GetNextImageInList(image);
3571 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3573 if (next->matte != MagickFalse)
3576 if (stack != MagickFalse)
3578 if (next->columns > width)
3579 width=next->columns;
3581 if (next->previous != (Image *) NULL)
3582 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3585 width+=next->columns;
3586 if (next->previous != (Image *) NULL)
3587 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3588 if (next->rows > height)
3594 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3595 if (smush_image == (Image *) NULL)
3596 return((Image *) NULL);
3597 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
3599 InheritException(exception,&smush_image->exception);
3600 smush_image=DestroyImage(smush_image);
3601 return((Image *) NULL);
3603 smush_image->matte=matte;
3604 (void) SetImageBackgroundColor(smush_image);
3608 smush_view=AcquireVirtualCacheView(smush_image,exception);
3609 for (n=0; n < (MagickOffsetType) number_images; n++)
3611 SetGeometry(smush_image,&geometry);
3612 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3613 if (stack != MagickFalse)
3615 x_offset-=geometry.x;
3616 y_offset-=SmushYGap(smush_image,image,offset,exception);
3620 x_offset-=SmushXGap(smush_image,image,offset,exception);
3621 y_offset-=geometry.y;
3623 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
3624 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3625 if (proceed == MagickFalse)
3627 if (stack == MagickFalse)
3629 x_offset+=(ssize_t) image->columns;
3635 y_offset+=(ssize_t) image->rows;
3637 image=GetNextImageInList(image);
3639 if (stack == MagickFalse)
3640 smush_image->columns=(size_t) x_offset;
3642 smush_image->rows=(size_t) y_offset;
3643 smush_view=DestroyCacheView(smush_view);
3644 if (status == MagickFalse)
3645 smush_image=DestroyImage(smush_image);
3646 return(smush_image);
3671MagickExport MagickBooleanType StripImage(Image *image)
3676 assert(image != (Image *) NULL);
3677 if (IsEventLogging() != MagickFalse)
3678 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3679 DestroyImageProfiles(image);
3680 (void) DeleteImageProperty(image,
"comment");
3681 (void) DeleteImageProperty(image,
"date:create");
3682 (void) DeleteImageProperty(image,
"date:modify");
3683 status=SetImageArtifact(image,
"png:exclude-chunk",
3684 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3712static inline IndexPacket PushColormapIndex(Image *image,
3713 const size_t index,MagickBooleanType *range_exception)
3715 if (index < image->colors)
3716 return((IndexPacket) index);
3717 *range_exception=MagickTrue;
3718 return((IndexPacket) 0);
3721MagickExport MagickBooleanType SyncImage(Image *image)
3737 assert(image != (Image *) NULL);
3738 assert(image->signature == MagickCoreSignature);
3739 if (IsEventLogging() != MagickFalse)
3740 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3741 if (image->ping != MagickFalse)
3743 if (image->storage_class != PseudoClass)
3744 return(MagickFalse);
3745 assert(image->colormap != (PixelPacket *) NULL);
3746 range_exception=MagickFalse;
3749 exception=(&image->exception);
3750 image_view=AcquireAuthenticCacheView(image,exception);
3751#if defined(MAGICKCORE_OPENMP_SUPPORT)
3752 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3753 magick_number_threads(image,image,image->rows,2)
3755 for (y=0; y < (ssize_t) image->rows; y++)
3761 *magick_restrict indexes;
3769 if (status == MagickFalse)
3771 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3772 if (q == (PixelPacket *) NULL)
3777 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3778 for (x=0; x < (ssize_t) image->columns; x++)
3780 index=PushColormapIndex(image,(
size_t) GetPixelIndex(indexes+x),
3782 if (image->matte == MagickFalse)
3783 SetPixelRgb(q,image->colormap+(ssize_t) index)
3785 SetPixelRGBO(q,image->colormap+(ssize_t) index);
3788 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3791 image_view=DestroyCacheView(image_view);
3793 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3794 (void) ThrowMagickException(&image->exception,GetMagickModule(),
3795 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
3827MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3833 assert(image_info != (
const ImageInfo *) NULL);
3834 assert(image_info->signature == MagickCoreSignature);
3835 assert(images != (Image *) NULL);
3836 assert(images->signature == MagickCoreSignature);
3837 if (IsEventLogging() != MagickFalse)
3838 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3840 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3841 (
void) SyncImageSettings(image_info,image);
3842 (void) DeleteImageOption(image_info,
"page");
3846MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
3850 property[MaxTextExtent];
3868 assert(image_info != (
const ImageInfo *) NULL);
3869 assert(image_info->signature == MagickCoreSignature);
3870 assert(image != (Image *) NULL);
3871 assert(image->signature == MagickCoreSignature);
3872 if (IsEventLogging() != MagickFalse)
3873 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3874 option=GetImageOption(image_info,
"background");
3875 if (option != (
const char *) NULL)
3876 (void) QueryColorDatabase(option,&image->background_color,
3878 option=GetImageOption(image_info,
"bias");
3879 if (option != (
const char *) NULL)
3880 image->bias=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
3881 option=GetImageOption(image_info,
"black-point-compensation");
3882 if (option != (
const char *) NULL)
3883 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3884 MagickBooleanOptions,MagickFalse,option);
3885 option=GetImageOption(image_info,
"blue-primary");
3886 if (option != (
const char *) NULL)
3888 flags=ParseGeometry(option,&geometry_info);
3889 if ((flags & RhoValue) != 0)
3890 image->chromaticity.blue_primary.x=geometry_info.rho;
3891 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3892 if ((flags & SigmaValue) != 0)
3893 image->chromaticity.blue_primary.y=geometry_info.sigma;
3895 option=GetImageOption(image_info,
"bordercolor");
3896 if (option != (
const char *) NULL)
3897 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
3898 option=GetImageOption(image_info,
"colors");
3899 if (option != (
const char *) NULL)
3900 image->colors=StringToUnsignedLong(option);
3901 option=GetImageOption(image_info,
"compose");
3902 if (option != (
const char *) NULL)
3903 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3904 MagickFalse,option);
3905 option=GetImageOption(image_info,
"compress");
3906 if (option != (
const char *) NULL)
3907 image->compression=(CompressionType) ParseCommandOption(
3908 MagickCompressOptions,MagickFalse,option);
3909 option=GetImageOption(image_info,
"debug");
3910 if (option != (
const char *) NULL)
3911 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3912 MagickFalse,option);
3913 option=GetImageOption(image_info,
"density");
3914 if (option != (
const char *) NULL)
3922 flags=ParseGeometry(option,&geometry_info);
3923 if ((flags & RhoValue) != 0)
3924 image->x_resolution=geometry_info.rho;
3925 image->y_resolution=image->x_resolution;
3926 if ((flags & SigmaValue) != 0)
3927 image->y_resolution=geometry_info.sigma;
3929 option=GetImageOption(image_info,
"depth");
3930 if (option != (
const char *) NULL)
3931 image->depth=StringToUnsignedLong(option);
3932 option=GetImageOption(image_info,
"endian");
3933 if (option != (
const char *) NULL)
3934 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3935 MagickFalse,option);
3936 option=GetImageOption(image_info,
"filter");
3937 if (option != (
const char *) NULL)
3938 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3939 MagickFalse,option);
3940 option=GetImageOption(image_info,
"fuzz");
3941 if (option != (
const char *) NULL)
3942 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
3943 option=GetImageOption(image_info,
"gravity");
3944 if (option != (
const char *) NULL)
3945 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3946 MagickFalse,option);
3947 option=GetImageOption(image_info,
"green-primary");
3948 if (option != (
const char *) NULL)
3950 flags=ParseGeometry(option,&geometry_info);
3951 if ((flags & RhoValue) != 0)
3952 image->chromaticity.green_primary.x=geometry_info.rho;
3953 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3954 if ((flags & SigmaValue) != 0)
3955 image->chromaticity.green_primary.y=geometry_info.sigma;
3957 option=GetImageOption(image_info,
"intensity");
3958 if (option != (
const char *) NULL)
3959 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3960 MagickPixelIntensityOptions,MagickFalse,option);
3961 option=GetImageOption(image_info,
"intent");
3962 if (option != (
const char *) NULL)
3963 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3964 MagickIntentOptions,MagickFalse,option);
3965 option=GetImageOption(image_info,
"interlace");
3966 if (option != (
const char *) NULL)
3967 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3968 MagickFalse,option);
3969 option=GetImageOption(image_info,
"interpolate");
3970 if (option != (
const char *) NULL)
3971 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
3972 MagickInterpolateOptions,MagickFalse,option);
3973 option=GetImageOption(image_info,
"loop");
3974 if (option != (
const char *) NULL)
3975 image->iterations=StringToUnsignedLong(option);
3976 option=GetImageOption(image_info,
"mattecolor");
3977 if (option != (
const char *) NULL)
3978 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
3979 option=GetImageOption(image_info,
"orient");
3980 if (option != (
const char *) NULL)
3981 image->orientation=(OrientationType) ParseCommandOption(
3982 MagickOrientationOptions,MagickFalse,option);
3983 option=GetImageOption(image_info,
"page");
3984 if (option != (
const char *) NULL)
3989 geometry=GetPageGeometry(option);
3990 flags=ParseAbsoluteGeometry(geometry,&image->page);
3991 geometry=DestroyString(geometry);
3993 option=GetImageOption(image_info,
"quality");
3994 if (option != (
const char *) NULL)
3995 image->quality=StringToUnsignedLong(option);
3996 option=GetImageOption(image_info,
"red-primary");
3997 if (option != (
const char *) NULL)
3999 flags=ParseGeometry(option,&geometry_info);
4000 if ((flags & RhoValue) != 0)
4001 image->chromaticity.red_primary.x=geometry_info.rho;
4002 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4003 if ((flags & SigmaValue) != 0)
4004 image->chromaticity.red_primary.y=geometry_info.sigma;
4006 if (image_info->quality != UndefinedCompressionQuality)
4007 image->quality=image_info->quality;
4008 option=GetImageOption(image_info,
"scene");
4009 if (option != (
const char *) NULL)
4010 image->scene=StringToUnsignedLong(option);
4011 option=GetImageOption(image_info,
"taint");
4012 if (option != (
const char *) NULL)
4013 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4014 MagickFalse,option);
4015 option=GetImageOption(image_info,
"tile-offset");
4016 if (option != (
const char *) NULL)
4021 geometry=GetPageGeometry(option);
4022 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4023 geometry=DestroyString(geometry);
4025 option=GetImageOption(image_info,
"transparent-color");
4026 if (option != (
const char *) NULL)
4027 (void) QueryColorDatabase(option,&image->transparent_color,
4029 option=GetImageOption(image_info,
"type");
4030 if (option != (
const char *) NULL)
4031 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4033 option=GetImageOption(image_info,
"units");
4034 units=image_info->units;
4035 if (option != (
const char *) NULL)
4036 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4037 MagickFalse,option);
4038 if (units != UndefinedResolution)
4040 if (image->units != units)
4041 switch (image->units)
4043 case PixelsPerInchResolution:
4045 if (units == PixelsPerCentimeterResolution)
4047 image->x_resolution/=2.54;
4048 image->y_resolution/=2.54;
4052 case PixelsPerCentimeterResolution:
4054 if (units == PixelsPerInchResolution)
4056 image->x_resolution=(double) ((
size_t) (100.0*2.54*
4057 image->x_resolution+0.5))/100.0;
4058 image->y_resolution=(double) ((
size_t) (100.0*2.54*
4059 image->y_resolution+0.5))/100.0;
4067 option=GetImageOption(image_info,
"density");
4068 if (option != (
const char *) NULL)
4070 flags=ParseGeometry(option,&geometry_info);
4071 if ((flags & RhoValue) != 0)
4072 image->x_resolution=geometry_info.rho;
4073 image->y_resolution=image->x_resolution;
4074 if ((flags & SigmaValue) != 0)
4075 image->y_resolution=geometry_info.sigma;
4078 option=GetImageOption(image_info,
"white-point");
4079 if (option != (
const char *) NULL)
4081 flags=ParseGeometry(option,&geometry_info);
4082 if ((flags & RhoValue) != 0)
4083 image->chromaticity.white_point.x=geometry_info.rho;
4084 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4085 if ((flags & SigmaValue) != 0)
4086 image->chromaticity.white_point.y=geometry_info.sigma;
4088 ResetImageOptionIterator(image_info);
4089 for (option=GetNextImageOption(image_info); option != (
const char *) NULL; )
4091 value=GetImageOption(image_info,option);
4092 if (value != (
const char *) NULL)
4094 (void) FormatLocaleString(property,MaxTextExtent,
"%s",option);
4095 (void) SetImageArtifact(image,property,value);
4097 option=GetNextImageOption(image_info);