43#include "MagickCore/studio.h"
44#include "MagickCore/animate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/blob.h"
48#include "MagickCore/blob-private.h"
49#include "MagickCore/cache.h"
50#include "MagickCore/cache-private.h"
51#include "MagickCore/cache-view.h"
52#include "MagickCore/channel.h"
53#include "MagickCore/client.h"
54#include "MagickCore/color.h"
55#include "MagickCore/color-private.h"
56#include "MagickCore/colormap.h"
57#include "MagickCore/colorspace.h"
58#include "MagickCore/colorspace-private.h"
59#include "MagickCore/composite.h"
60#include "MagickCore/composite-private.h"
61#include "MagickCore/compress.h"
62#include "MagickCore/constitute.h"
63#include "MagickCore/delegate.h"
64#include "MagickCore/display.h"
65#include "MagickCore/draw.h"
66#include "MagickCore/enhance.h"
67#include "MagickCore/exception.h"
68#include "MagickCore/exception-private.h"
69#include "MagickCore/gem.h"
70#include "MagickCore/geometry.h"
71#include "MagickCore/histogram.h"
72#include "MagickCore/image-private.h"
73#include "MagickCore/list.h"
74#include "MagickCore/magic.h"
75#include "MagickCore/magick.h"
76#include "MagickCore/magick-private.h"
77#include "MagickCore/memory_.h"
78#include "MagickCore/memory-private.h"
79#include "MagickCore/module.h"
80#include "MagickCore/monitor.h"
81#include "MagickCore/monitor-private.h"
82#include "MagickCore/option.h"
83#include "MagickCore/paint.h"
84#include "MagickCore/pixel-accessor.h"
85#include "MagickCore/profile.h"
86#include "MagickCore/property.h"
87#include "MagickCore/quantize.h"
88#include "MagickCore/random_.h"
89#include "MagickCore/resource_.h"
90#include "MagickCore/segment.h"
91#include "MagickCore/semaphore.h"
92#include "MagickCore/signature-private.h"
93#include "MagickCore/statistic.h"
94#include "MagickCore/string_.h"
95#include "MagickCore/string-private.h"
96#include "MagickCore/thread-private.h"
97#include "MagickCore/threshold.h"
98#include "MagickCore/timer.h"
99#include "MagickCore/timer-private.h"
100#include "MagickCore/token.h"
101#include "MagickCore/token-private.h"
102#include "MagickCore/utility.h"
103#include "MagickCore/utility-private.h"
104#include "MagickCore/version.h"
105#include "MagickCore/xwindow-private.h"
134MagickExport Image *AcquireImage(
const ImageInfo *image_info,
135 ExceptionInfo *exception)
152 if (IsEventLogging() != MagickFalse)
153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
154 image=(Image *) AcquireCriticalMemory(
sizeof(*image));
155 (void) memset(image,0,
sizeof(*image));
159 (void) CopyMagickString(image->magick,
"MIFF",MagickPathExtent);
160 image->storage_class=DirectClass;
161 image->depth=MAGICKCORE_QUANTUM_DEPTH;
162 image->colorspace=sRGBColorspace;
163 image->rendering_intent=PerceptualIntent;
164 image->gamma=1.000/2.200;
165 image->chromaticity.red_primary.x=0.6400;
166 image->chromaticity.red_primary.y=0.3300;
167 image->chromaticity.red_primary.z=0.0300;
168 image->chromaticity.green_primary.x=0.3000;
169 image->chromaticity.green_primary.y=0.6000;
170 image->chromaticity.green_primary.z=0.1000;
171 image->chromaticity.blue_primary.x=0.1500;
172 image->chromaticity.blue_primary.y=0.0600;
173 image->chromaticity.blue_primary.z=0.7900;
174 image->chromaticity.white_point.x=0.3127;
175 image->chromaticity.white_point.y=0.3290;
176 image->chromaticity.white_point.z=0.3583;
177 image->interlace=NoInterlace;
178 image->ticks_per_second=UndefinedTicksPerSecond;
179 image->compose=OverCompositeOp;
180 GetPixelInfoRGBA(BackgroundColorRGBA,&image->background_color);
181 GetPixelInfoRGBA(BorderColorRGBA,&image->border_color);
182 GetPixelInfoRGBA(MatteColorRGBA,&image->matte_color);
183 GetPixelInfoRGBA(TransparentColorRGBA,&image->transparent_color);
184 GetTimerInfo(&image->timer);
185 image->cache=AcquirePixelCache(0);
186 image->channel_mask=AllChannels;
187 image->channel_map=AcquirePixelChannelMap();
188 image->blob=CloneBlobInfo((BlobInfo *) NULL);
189 image->timestamp=time((time_t *) NULL);
190 time_limit=GetMagickResourceLimit(TimeResource);
191 if (time_limit != MagickResourceInfinity)
192 image->ttl=image->timestamp+(time_t) time_limit;
193 image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
194 != 0 ? MagickTrue : MagickFalse;
195 image->reference_count=1;
196 image->semaphore=AcquireSemaphoreInfo();
197 image->signature=MagickCoreSignature;
198 if (image_info == (ImageInfo *) NULL)
203 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
205 (void) CopyMagickString(image->filename,image_info->filename,
207 (void) CopyMagickString(image->magick_filename,image_info->filename,
209 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
210 if (image_info->size != (
char *) NULL)
212 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
213 image->columns=image->extract_info.width;
214 image->rows=image->extract_info.height;
215 image->offset=image->extract_info.x;
216 image->extract_info.x=0;
217 image->extract_info.y=0;
219 if (image_info->extract != (
char *) NULL)
224 (void) memset(&geometry,0,
sizeof(geometry));
225 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
226 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
228 image->extract_info=geometry;
229 Swap(image->columns,image->extract_info.width);
230 Swap(image->rows,image->extract_info.height);
233 image->compression=image_info->compression;
234 image->quality=image_info->quality;
235 image->endian=image_info->endian;
236 image->interlace=image_info->interlace;
237 image->units=image_info->units;
238 if (image_info->density != (
char *) NULL)
243 flags=ParseGeometry(image_info->density,&geometry_info);
244 if ((flags & RhoValue) != 0)
245 image->resolution.x=geometry_info.rho;
246 image->resolution.y=image->resolution.x;
247 if ((flags & SigmaValue) != 0)
248 image->resolution.y=geometry_info.sigma;
250 if (image_info->page != (
char *) NULL)
255 image->page=image->extract_info;
256 geometry=GetPageGeometry(image_info->page);
257 (void) ParseAbsoluteGeometry(geometry,&image->page);
258 geometry=DestroyString(geometry);
260 if (image_info->depth != 0)
261 image->depth=image_info->depth;
262 image->dither=image_info->dither;
263 image->matte_color=image_info->matte_color;
264 image->background_color=image_info->background_color;
265 image->border_color=image_info->border_color;
266 image->transparent_color=image_info->transparent_color;
267 image->ping=image_info->ping;
268 image->progress_monitor=image_info->progress_monitor;
269 image->client_data=image_info->client_data;
270 if (image_info->cache != (
void *) NULL)
271 ClonePixelCacheMethods(image->cache,image_info->cache);
275 (void) SyncImageSettings(image_info,image,exception);
279 option=GetImageOption(image_info,
"delay");
280 if (option != (
const char *) NULL)
285 flags=ParseGeometry(option,&geometry_info);
286 if ((flags & GreaterValue) != 0)
288 if ((
double) image->delay > floor(geometry_info.rho+0.5))
289 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+
293 if ((flags & LessValue) != 0)
295 if ((
double) image->delay < floor(geometry_info.rho+0.5))
296 image->ticks_per_second=CastDoubleToSsizeT(floor(
297 geometry_info.sigma+0.5));
300 image->delay=(size_t) CastDoubleToSsizeT(floor(geometry_info.rho+
302 if ((flags & SigmaValue) != 0)
303 image->ticks_per_second=CastDoubleToSsizeT(floor(geometry_info.sigma+
306 option=GetImageOption(image_info,
"dispose");
307 if (option != (
const char *) NULL)
308 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
331MagickExport ImageInfo *AcquireImageInfo(
void)
336 image_info=(ImageInfo *) AcquireCriticalMemory(
sizeof(*image_info));
337 GetImageInfo(image_info);
372MagickExport
void AcquireNextImage(
const ImageInfo *image_info,Image *image,
373 ExceptionInfo *exception)
378 assert(image != (Image *) NULL);
379 assert(image->signature == MagickCoreSignature);
380 if (IsEventLogging() != MagickFalse)
381 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
382 image->next=AcquireImage(image_info,exception);
383 if (GetNextImageInList(image) == (Image *) NULL)
385 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
387 if (image_info != (ImageInfo *) NULL)
388 (void) CopyMagickString(GetNextImageInList(image)->filename,
389 image_info->filename,MagickPathExtent);
390 DestroyBlob(GetNextImageInList(image));
391 image->next->blob=ReferenceBlob(image->blob);
392 image->next->endian=image->endian;
393 image->next->scene=image->scene+1;
394 image->next->previous=image;
429MagickExport Image *AppendImages(
const Image *images,
430 const MagickBooleanType stack,ExceptionInfo *exception)
432#define AppendImageTag "Append/Image"
444 homogeneous_colorspace,
473 assert(images != (Image *) NULL);
474 assert(images->signature == MagickCoreSignature);
475 assert(exception != (ExceptionInfo *) NULL);
476 assert(exception->signature == MagickCoreSignature);
477 if (IsEventLogging() != MagickFalse)
478 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
479 alpha_trait=images->alpha_trait;
481 width=images->columns;
484 image_type=images->type;
485 homogeneous_colorspace=MagickTrue;
486 next=GetNextImageInList(images);
487 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
489 if (next->depth > depth)
491 if (next->type != images->type)
492 image_type=UndefinedType;
493 if (next->colorspace != images->colorspace)
494 homogeneous_colorspace=MagickFalse;
495 if (next->alpha_trait != UndefinedPixelTrait)
496 alpha_trait=BlendPixelTrait;
498 if (stack != MagickFalse)
500 if (next->columns > width)
505 width+=next->columns;
506 if (next->rows > height)
512 append_image=CloneImage(images,width,height,MagickTrue,exception);
513 if (append_image == (Image *) NULL)
514 return((Image *) NULL);
515 if (image_type != BilevelType)
517 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
519 append_image=DestroyImage(append_image);
520 return((Image *) NULL);
522 if (homogeneous_colorspace == MagickFalse)
523 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
525 append_image->depth=depth;
526 append_image->alpha_trait=alpha_trait;
527 append_image->page=images->page;
528 (void) SetImageBackgroundColor(append_image,exception);
533 append_view=AcquireAuthenticCacheView(append_image,exception);
534 for (n=0; n < (MagickOffsetType) number_images; n++)
542 SetGeometry(append_image,&geometry);
543 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
544 if (stack != MagickFalse)
545 x_offset-=geometry.x;
547 y_offset-=geometry.y;
548 image_view=AcquireVirtualCacheView(next,exception);
549#if defined(MAGICKCORE_OPENMP_SUPPORT)
550 #pragma omp parallel for schedule(static) shared(status) \
551 magick_number_threads(next,next,next->rows,2)
553 for (y=0; y < (ssize_t) next->rows; y++)
570 if (status == MagickFalse)
572 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
573 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
574 next->columns,1,exception);
575 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
580 GetPixelInfo(next,&pixel);
581 for (x=0; x < (ssize_t) next->columns; x++)
583 GetPixelInfoPixel(next,p,&pixel);
584 SetPixelViaPixelInfo(append_image,&pixel,q);
585 p+=(ptrdiff_t) GetPixelChannels(next);
586 q+=(ptrdiff_t) GetPixelChannels(append_image);
588 sync=SyncCacheViewAuthenticPixels(append_view,exception);
589 if (sync == MagickFalse)
592 image_view=DestroyCacheView(image_view);
593 if (stack == MagickFalse)
595 x_offset+=(ssize_t) next->columns;
601 y_offset+=(ssize_t) next->rows;
603 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
604 if (proceed == MagickFalse)
606 next=GetNextImageInList(next);
608 append_view=DestroyCacheView(append_view);
609 if (status == MagickFalse)
610 append_image=DestroyImage(append_image);
611 return(append_image);
638MagickExport ExceptionType CatchImageException(Image *image)
646 assert(image != (
const Image *) NULL);
647 assert(image->signature == MagickCoreSignature);
648 if (IsEventLogging() != MagickFalse)
649 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
650 exception=AcquireExceptionInfo();
651 CatchException(exception);
652 severity=exception->severity;
653 exception=DestroyExceptionInfo(exception);
690MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
692 return(ClipImagePath(image,
"#1",MagickTrue,exception));
695MagickExport MagickBooleanType ClipImagePath(Image *image,
const char *pathname,
696 const MagickBooleanType inside,ExceptionInfo *exception)
698#define ClipImagePathTag "ClipPath/Image"
712 assert(image != (
const Image *) NULL);
713 assert(image->signature == MagickCoreSignature);
714 assert(pathname != NULL);
715 if (IsEventLogging() != MagickFalse)
716 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
717 property=AcquireString(pathname);
718 (void) FormatLocaleString(property,MagickPathExtent,
"8BIM:1999,2998:%s",
720 value=GetImageProperty(image,property,exception);
721 property=DestroyString(property);
722 if (value == (
const char *) NULL)
724 ThrowFileException(exception,OptionError,
"NoClipPathDefined",
728 image_info=AcquireImageInfo();
729 (void) CopyMagickString(image_info->filename,image->filename,
731 (void) ConcatenateMagickString(image_info->filename,pathname,
733 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
734 image_info=DestroyImageInfo(image_info);
735 if (clip_mask == (Image *) NULL)
737 if (clip_mask->storage_class == PseudoClass)
739 (void) SyncImage(clip_mask,exception);
740 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
743 if (inside != MagickFalse)
744 (void) NegateImage(clip_mask,MagickFalse,exception);
745 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
746 "8BIM:1999,2998:%s\nPS",pathname);
747 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
748 image->mask_trait=UpdatePixelTrait;
749 clip_mask=DestroyImage(clip_mask);
792MagickExport Image *CloneImage(
const Image *image,
const size_t columns,
793 const size_t rows,
const MagickBooleanType detach,ExceptionInfo *exception)
808 assert(image != (
const Image *) NULL);
809 assert(image->signature == MagickCoreSignature);
810 assert(exception != (ExceptionInfo *) NULL);
811 assert(exception->signature == MagickCoreSignature);
812 if (IsEventLogging() != MagickFalse)
813 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
814 if ((image->columns == 0) || (image->rows == 0))
816 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
817 "NegativeOrZeroImageSize",
"`%s'",image->filename);
818 return((Image *) NULL);
820 clone_image=(Image *) AcquireCriticalMemory(
sizeof(*clone_image));
821 (void) memset(clone_image,0,
sizeof(*clone_image));
822 clone_image->signature=MagickCoreSignature;
823 clone_image->storage_class=image->storage_class;
824 clone_image->number_channels=image->number_channels;
825 clone_image->number_meta_channels=image->number_meta_channels;
826 clone_image->metacontent_extent=image->metacontent_extent;
827 clone_image->colorspace=image->colorspace;
828 clone_image->alpha_trait=image->alpha_trait;
829 clone_image->channels=image->channels;
830 clone_image->mask_trait=image->mask_trait;
831 clone_image->columns=image->columns;
832 clone_image->rows=image->rows;
833 clone_image->dither=image->dither;
834 clone_image->image_info=CloneImageInfo(image->image_info);
835 (void) CloneImageProfiles(clone_image,image);
836 (void) CloneImageProperties(clone_image,image);
837 (void) CloneImageArtifacts(clone_image,image);
838 GetTimerInfo(&clone_image->timer);
839 if (image->ascii85 != (
void *) NULL)
840 Ascii85Initialize(clone_image);
841 clone_image->extent=image->extent;
842 clone_image->magick_columns=image->magick_columns;
843 clone_image->magick_rows=image->magick_rows;
844 clone_image->type=image->type;
845 clone_image->channel_mask=image->channel_mask;
846 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
847 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
849 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
850 (void) CopyMagickString(clone_image->filename,image->filename,
852 clone_image->progress_monitor=image->progress_monitor;
853 clone_image->client_data=image->client_data;
854 clone_image->reference_count=1;
855 clone_image->next=image->next;
856 clone_image->previous=image->previous;
857 clone_image->list=NewImageList();
858 if (detach == MagickFalse)
859 clone_image->blob=ReferenceBlob(image->blob);
862 clone_image->next=NewImageList();
863 clone_image->previous=NewImageList();
864 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
866 clone_image->ping=image->ping;
867 clone_image->timestamp=image->timestamp;
868 clone_image->ttl=image->ttl;
869 clone_image->debug=image->debug;
870 clone_image->semaphore=AcquireSemaphoreInfo();
871 if (image->colormap != (PixelInfo *) NULL)
876 clone_image->colors=image->colors;
877 length=(size_t) image->colors;
878 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length+1,
879 sizeof(*clone_image->colormap));
880 if (clone_image->colormap == (PixelInfo *) NULL)
882 clone_image=DestroyImage(clone_image);
883 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
885 (void) memcpy(clone_image->colormap,image->colormap,length*
886 sizeof(*clone_image->colormap));
888 if ((columns == 0) || (rows == 0))
890 if (image->montage != (
char *) NULL)
891 (void) CloneString(&clone_image->montage,image->montage);
892 if (image->directory != (
char *) NULL)
893 (void) CloneString(&clone_image->directory,image->directory);
894 clone_image->cache=ReferencePixelCache(image->cache);
899 if (image->columns != 0)
900 scale_x=(double) columns/(
double) image->columns;
901 if (image->rows != 0)
902 scale_y=(double) rows/(
double) image->rows;
903 clone_image->page.width=(size_t) CastDoubleToSsizeT(floor(scale_x*
904 image->page.width+0.5));
905 clone_image->page.height=(size_t) CastDoubleToSsizeT(floor(scale_y*
906 image->page.height+0.5));
907 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
908 scale_x=scale_y=MagickMin(scale_x,scale_y);
909 clone_image->page.x=CastDoubleToSsizeT(ceil(scale_x*image->page.x-0.5));
910 clone_image->tile_offset.x=CastDoubleToSsizeT(ceil(scale_x*
911 image->tile_offset.x-0.5));
912 clone_image->page.y=CastDoubleToSsizeT(ceil(scale_y*image->page.y-0.5));
913 clone_image->tile_offset.y=CastDoubleToSsizeT(ceil(scale_y*
914 image->tile_offset.y-0.5));
915 clone_image->cache=ClonePixelCache(image->cache);
916 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
917 clone_image=DestroyImage(clone_image);
945MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
950 clone_info=AcquireImageInfo();
951 if (image_info == (ImageInfo *) NULL)
953 clone_info->compression=image_info->compression;
954 clone_info->temporary=image_info->temporary;
955 clone_info->adjoin=image_info->adjoin;
956 clone_info->antialias=image_info->antialias;
957 clone_info->scene=image_info->scene;
958 clone_info->number_scenes=image_info->number_scenes;
959 clone_info->depth=image_info->depth;
960 if (image_info->size != (
char *) NULL)
961 (void) CloneString(&clone_info->size,image_info->size);
962 if (image_info->extract != (
char *) NULL)
963 (void) CloneString(&clone_info->extract,image_info->extract);
964 if (image_info->scenes != (
char *) NULL)
965 (void) CloneString(&clone_info->scenes,image_info->scenes);
966 if (image_info->page != (
char *) NULL)
967 (void) CloneString(&clone_info->page,image_info->page);
968 clone_info->interlace=image_info->interlace;
969 clone_info->endian=image_info->endian;
970 clone_info->units=image_info->units;
971 clone_info->quality=image_info->quality;
972 if (image_info->sampling_factor != (
char *) NULL)
973 (void) CloneString(&clone_info->sampling_factor,
974 image_info->sampling_factor);
975 if (image_info->server_name != (
char *) NULL)
976 (void) CloneString(&clone_info->server_name,image_info->server_name);
977 if (image_info->font != (
char *) NULL)
978 (void) CloneString(&clone_info->font,image_info->font);
979 if (image_info->texture != (
char *) NULL)
980 (void) CloneString(&clone_info->texture,image_info->texture);
981 if (image_info->density != (
char *) NULL)
982 (void) CloneString(&clone_info->density,image_info->density);
983 clone_info->pointsize=image_info->pointsize;
984 clone_info->fuzz=image_info->fuzz;
985 clone_info->matte_color=image_info->matte_color;
986 clone_info->background_color=image_info->background_color;
987 clone_info->border_color=image_info->border_color;
988 clone_info->transparent_color=image_info->transparent_color;
989 clone_info->dither=image_info->dither;
990 clone_info->monochrome=image_info->monochrome;
991 clone_info->colorspace=image_info->colorspace;
992 clone_info->type=image_info->type;
993 clone_info->orientation=image_info->orientation;
994 clone_info->ping=image_info->ping;
995 clone_info->verbose=image_info->verbose;
996 clone_info->progress_monitor=image_info->progress_monitor;
997 clone_info->client_data=image_info->client_data;
998 clone_info->cache=image_info->cache;
999 if (image_info->cache != (
void *) NULL)
1000 clone_info->cache=ReferencePixelCache(image_info->cache);
1001 if (image_info->profile != (
void *) NULL)
1002 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1003 image_info->profile);
1004 SetImageInfoFile(clone_info,image_info->file);
1005 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1006 clone_info->stream=image_info->stream;
1007 clone_info->custom_stream=image_info->custom_stream;
1008 (void) CopyMagickString(clone_info->magick,image_info->magick,
1010 (void) CopyMagickString(clone_info->unique,image_info->unique,
1012 (void) CopyMagickString(clone_info->filename,image_info->filename,
1014 clone_info->channel=image_info->channel;
1015 (void) CloneImageOptions(clone_info,image_info);
1016 clone_info->debug=image_info->debug;
1017 clone_info->signature=image_info->signature;
1054MagickExport MagickBooleanType CopyImagePixels(Image *image,
1055 const Image *source_image,
const RectangleInfo *geometry,
1056 const OffsetInfo *offset,ExceptionInfo *exception)
1058#define CopyImageTag "Copy/Image"
1073 assert(image != (Image *) NULL);
1074 assert(source_image != (Image *) NULL);
1075 assert(geometry != (RectangleInfo *) NULL);
1076 assert(offset != (OffsetInfo *) NULL);
1077 if (IsEventLogging() != MagickFalse)
1078 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1079 if ((offset->x < 0) || (offset->y < 0) ||
1080 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1081 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1082 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1084 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1085 return(MagickFalse);
1091 source_view=AcquireVirtualCacheView(source_image,exception);
1092 image_view=AcquireAuthenticCacheView(image,exception);
1093#if defined(MAGICKCORE_OPENMP_SUPPORT)
1094 #pragma omp parallel for schedule(static) shared(progress,status) \
1095 magick_number_threads(image,source_image,geometry->height,2)
1097 for (y=0; y < (ssize_t) geometry->height; y++)
1111 if (status == MagickFalse)
1113 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1114 geometry->width,1,exception);
1115 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1116 geometry->width,1,exception);
1117 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1122 for (x=0; x < (ssize_t) geometry->width; x++)
1127 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1129 PixelChannel channel = GetPixelChannelChannel(image,i);
1130 PixelTrait traits = GetPixelChannelTraits(image,channel);
1131 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1132 if ((traits == UndefinedPixelTrait) ||
1133 ((traits & UpdatePixelTrait) == 0) ||
1134 (source_traits == UndefinedPixelTrait))
1136 SetPixelChannel(image,channel,p[i],q);
1138 p+=(ptrdiff_t) GetPixelChannels(source_image);
1139 q+=(ptrdiff_t) GetPixelChannels(image);
1141 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1142 if (sync == MagickFalse)
1144 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1149#if defined(MAGICKCORE_OPENMP_SUPPORT)
1153 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1154 if (proceed == MagickFalse)
1158 source_view=DestroyCacheView(source_view);
1159 image_view=DestroyCacheView(image_view);
1186MagickExport Image *DestroyImage(Image *image)
1194 assert(image != (Image *) NULL);
1195 assert(image->signature == MagickCoreSignature);
1196 if (IsEventLogging() != MagickFalse)
1197 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1198 destroy=MagickFalse;
1199 LockSemaphoreInfo(image->semaphore);
1200 image->reference_count--;
1201 if (image->reference_count == 0)
1203 UnlockSemaphoreInfo(image->semaphore);
1204 if (destroy == MagickFalse)
1205 return((Image *) NULL);
1209 DestroyImagePixels(image);
1210 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1211 if (image->montage != (
char *) NULL)
1212 image->montage=DestroyString(image->montage);
1213 if (image->directory != (
char *) NULL)
1214 image->directory=DestroyString(image->directory);
1215 if (image->colormap != (PixelInfo *) NULL)
1216 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1217 if (image->geometry != (
char *) NULL)
1218 image->geometry=DestroyString(image->geometry);
1219 DestroyImageProfiles(image);
1220 DestroyImageProperties(image);
1221 DestroyImageArtifacts(image);
1222 if (image->ascii85 != (Ascii85Info *) NULL)
1223 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1224 if (image->image_info != (ImageInfo *) NULL)
1225 image->image_info=DestroyImageInfo(image->image_info);
1228 RelinquishSemaphoreInfo(&image->semaphore);
1229 image->signature=(~MagickCoreSignature);
1230 image=(Image *) RelinquishMagickMemory(image);
1257MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1259 assert(image_info != (ImageInfo *) NULL);
1260 assert(image_info->signature == MagickCoreSignature);
1261 if (IsEventLogging() != MagickFalse)
1262 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1263 image_info->filename);
1264 if (image_info->size != (
char *) NULL)
1265 image_info->size=DestroyString(image_info->size);
1266 if (image_info->extract != (
char *) NULL)
1267 image_info->extract=DestroyString(image_info->extract);
1268 if (image_info->scenes != (
char *) NULL)
1269 image_info->scenes=DestroyString(image_info->scenes);
1270 if (image_info->page != (
char *) NULL)
1271 image_info->page=DestroyString(image_info->page);
1272 if (image_info->sampling_factor != (
char *) NULL)
1273 image_info->sampling_factor=DestroyString(
1274 image_info->sampling_factor);
1275 if (image_info->server_name != (
char *) NULL)
1276 image_info->server_name=DestroyString(
1277 image_info->server_name);
1278 if (image_info->font != (
char *) NULL)
1279 image_info->font=DestroyString(image_info->font);
1280 if (image_info->texture != (
char *) NULL)
1281 image_info->texture=DestroyString(image_info->texture);
1282 if (image_info->density != (
char *) NULL)
1283 image_info->density=DestroyString(image_info->density);
1284 if (image_info->cache != (
void *) NULL)
1285 image_info->cache=DestroyPixelCache(image_info->cache);
1286 if (image_info->profile != (StringInfo *) NULL)
1287 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1288 image_info->profile);
1289 DestroyImageOptions(image_info);
1290 image_info->signature=(~MagickCoreSignature);
1291 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1319MagickExport
void DisassociateImageStream(Image *image)
1321 assert(image != (Image *) NULL);
1322 assert(image->signature == MagickCoreSignature);
1323 if (IsEventLogging() != MagickFalse)
1324 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1325 DisassociateBlob(image);
1350MagickExport
void GetImageInfo(ImageInfo *image_info)
1358 assert(image_info != (ImageInfo *) NULL);
1359 if (IsEventLogging() != MagickFalse)
1360 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1361 (void) memset(image_info,0,
sizeof(*image_info));
1362 image_info->adjoin=MagickTrue;
1363 image_info->interlace=NoInterlace;
1364 image_info->channel=AllChannels;
1365 image_info->quality=UndefinedCompressionQuality;
1366 image_info->antialias=MagickTrue;
1367 image_info->dither=MagickTrue;
1368 image_info->depth=0;
1369 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1370 if (synchronize != (
const char *) NULL)
1372 image_info->synchronize=IsStringTrue(synchronize);
1373 synchronize=DestroyString(synchronize);
1375 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1376 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1377 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1378 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1379 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1381 image_info->signature=MagickCoreSignature;
1406MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1408 return(image_info->file);
1436MagickExport Image *GetImageMask(
const Image *image,
const PixelMask type,
1437 ExceptionInfo *exception)
1455 assert(image != (Image *) NULL);
1456 assert(image->signature == MagickCoreSignature);
1457 if (IsEventLogging() != MagickFalse)
1458 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1463 if ((image->channels & ReadMaskChannel) == 0)
1464 return((Image *) NULL);
1467 case WritePixelMask:
1469 if ((image->channels & WriteMaskChannel) == 0)
1470 return((Image *) NULL);
1475 if ((image->channels & CompositeMaskChannel) == 0)
1476 return((Image *) NULL);
1480 mask_image=AcquireImage((ImageInfo *) NULL,exception);
1481 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1482 if (status == MagickFalse)
1483 return(DestroyImage(mask_image));
1485 mask_image->alpha_trait=UndefinedPixelTrait;
1486 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1487 image_view=AcquireVirtualCacheView(image,exception);
1488 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1489#if defined(MAGICKCORE_OPENMP_SUPPORT)
1490 #pragma omp parallel for schedule(static) shared(status) \
1491 magick_number_threads(image,image,image->rows,2)
1493 for (y=0; y < (ssize_t) image->rows; y++)
1504 if (status == MagickFalse)
1506 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1507 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1509 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
1514 for (x=0; x < (ssize_t) image->columns; x++)
1520 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1523 case WritePixelMask:
1525 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1530 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1534 p+=(ptrdiff_t) GetPixelChannels(image);
1535 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1537 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1540 mask_view=DestroyCacheView(mask_view);
1541 image_view=DestroyCacheView(image_view);
1542 if (status == MagickFalse)
1543 mask_image=DestroyImage(mask_image);
1569MagickExport ssize_t GetImageReferenceCount(Image *image)
1574 assert(image != (Image *) NULL);
1575 assert(image->signature == MagickCoreSignature);
1576 if (IsEventLogging() != MagickFalse)
1577 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1578 LockSemaphoreInfo(image->semaphore);
1579 reference_count=image->reference_count;
1580 UnlockSemaphoreInfo(image->semaphore);
1581 return(reference_count);
1608MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1610 assert(image != (Image *) NULL);
1611 assert(image->signature == MagickCoreSignature);
1612 if (IsEventLogging() != MagickFalse)
1613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1614 return(GetPixelCacheVirtualMethod(image));
1653static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1657 specifier = end[-1];
1665 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1666 return(MagickFalse);
1667 if ((length == 1) && (*start == specifier))
1676 if ((length >= 3) && (start[1] ==
'0'))
1677 return(MagickFalse);
1680 for ( ; i < (length-1); i++)
1681 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1682 return(MagickFalse);
1685 return(MagickFalse);
1688MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1689 Image *image,
const char *format,
int value,
char *filename,
1690 ExceptionInfo *exception)
1694 pattern[MagickPathExtent];
1699 assert(format != (
const char *) NULL);
1700 assert(filename != (
char *) NULL);
1701 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1703 (void) CopyMagickString(filename,format,MagickPathExtent);
1704 return(strlen(filename));
1706 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1724 specifier_start=cursor;
1725 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1727 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1730 *specifier_end = cursor+1;
1732 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1735 format_specifier[MagickPathExtent];
1738 length = cursor-specifier_start;
1743 (void) snprintf(format_specifier,
sizeof(format_specifier),
1744 "%%%.*s%c",(
int) length,specifier_start,*cursor);
1745 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1747 if ((count <= 0) || ((p-filename+count) >= MagickPathExtent))
1749 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
1767 *end = strchr(cursor,
']'),
1768 *option = (
const char *) NULL;
1774 if (end == (
const char *) NULL)
1776 extent=(size_t) (end-cursor-1);
1777 if (extent >=
sizeof(pattern))
1779 (void) CopyMagickString(pattern,cursor+1,extent+1);
1780 pattern[extent]=
'\0';
1783 option=GetImageProperty(image,pattern,exception);
1784 if (option == (
const char *) NULL)
1785 option=GetImageArtifact(image,pattern);
1787 if ((option == (
const char *) NULL) &&
1788 (image_info != (ImageInfo *) NULL))
1789 option=GetImageOption(image_info,pattern);
1790 if (option == (
const char *) NULL)
1792 option_length=strlen(option);
1793 if ((p-filename+option_length) >= MagickPathExtent)
1795 (void) CopyMagickString(p,option,MagickPathExtent-(p-filename));
1804 if ((p-filename+1) >= MagickPathExtent)
1809 return(strlen(filename));
1839MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1840 ExceptionInfo *exception)
1842#if !defined(MAGICKCORE_HDRI_SUPPORT)
1845 return(MagickFalse);
1856 assert(image != (Image *) NULL);
1857 assert(image->signature == MagickCoreSignature);
1858 if (IsEventLogging() != MagickFalse)
1859 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1860 image_view=AcquireVirtualCacheView(image,exception);
1861#if defined(MAGICKCORE_OPENMP_SUPPORT)
1862 #pragma omp parallel for schedule(static) shared(hdri) \
1863 magick_number_threads(image,image,image->rows,2)
1865 for (y=0; y < (ssize_t) image->rows; y++)
1873 if (hdri != MagickFalse)
1875 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1876 if (p == (
const Quantum *) NULL)
1878 for (x=0; x < (ssize_t) image->columns; x++)
1883 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1891 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1892 if (traits == UndefinedPixelTrait)
1894 pixel=(double) p[i];
1895 if ((pixel < 0.0) || (pixel > (
double) QuantumRange) ||
1896 (pixel != (
double) ((QuantumAny) pixel)))
1902 if (hdri != MagickFalse)
1904 p+=(ptrdiff_t) GetPixelChannels(image);
1907 image_view=DestroyCacheView(image_view);
1935MagickExport MagickBooleanType IsImageObject(
const Image *image)
1940 assert(image != (Image *) NULL);
1941 if (IsEventLogging() != MagickFalse)
1942 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1943 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1944 if (p->signature != MagickCoreSignature)
1945 return(MagickFalse);
1972MagickExport MagickBooleanType IsTaintImage(
const Image *image)
1975 magick[MagickPathExtent],
1976 filename[MagickPathExtent];
1981 assert(image != (Image *) NULL);
1982 assert(image->signature == MagickCoreSignature);
1983 if (IsEventLogging() != MagickFalse)
1984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1985 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1986 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1987 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1989 if (p->taint != MagickFalse)
1991 if (LocaleCompare(p->magick,magick) != 0)
1993 if (LocaleCompare(p->filename,filename) != 0)
1996 return(MagickFalse);
2025MagickExport MagickBooleanType ModifyImage(Image **image,
2026 ExceptionInfo *exception)
2031 assert(image != (Image **) NULL);
2032 assert(*image != (Image *) NULL);
2033 assert((*image)->signature == MagickCoreSignature);
2034 if (IsEventLogging() != MagickFalse)
2035 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2036 if (GetImageReferenceCount(*image) <= 1)
2038 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2039 LockSemaphoreInfo((*image)->semaphore);
2040 (*image)->reference_count--;
2041 UnlockSemaphoreInfo((*image)->semaphore);
2079MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2080 const size_t width,
const size_t height,
const PixelInfo *background,
2081 ExceptionInfo *exception)
2095 assert(image_info != (
const ImageInfo *) NULL);
2096 assert(image_info->signature == MagickCoreSignature);
2097 assert(background != (
const PixelInfo *) NULL);
2098 if (IsEventLogging() != MagickFalse)
2099 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2100 image=AcquireImage(image_info,exception);
2101 image->columns=width;
2103 image->colorspace=background->colorspace;
2104 image->alpha_trait=background->alpha_trait;
2105 image->fuzz=background->fuzz;
2106 image->depth=background->depth;
2108 image_view=AcquireAuthenticCacheView(image,exception);
2109#if defined(MAGICKCORE_OPENMP_SUPPORT)
2110 #pragma omp parallel for schedule(static) shared(status) \
2111 magick_number_threads(image,image,image->rows,2)
2113 for (y=0; y < (ssize_t) image->rows; y++)
2121 if (status == MagickFalse)
2123 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2124 if (q == (Quantum *) NULL)
2129 for (x=0; x < (ssize_t) image->columns; x++)
2131 SetPixelViaPixelInfo(image,background,q);
2132 q+=(ptrdiff_t) GetPixelChannels(image);
2134 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2137 image_view=DestroyCacheView(image_view);
2138 if (status == MagickFalse)
2139 image=DestroyImage(image);
2166MagickExport Image *ReferenceImage(Image *image)
2168 assert(image != (Image *) NULL);
2169 assert(image->signature == MagickCoreSignature);
2170 if (IsEventLogging() != MagickFalse)
2171 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2172 LockSemaphoreInfo(image->semaphore);
2173 image->reference_count++;
2174 UnlockSemaphoreInfo(image->semaphore);
2202MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2210 assert(image != (Image *) NULL);
2211 assert(image->signature == MagickCoreSignature);
2212 if (IsEventLogging() != MagickFalse)
2213 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2214 flags=ParseAbsoluteGeometry(page,&geometry);
2215 if ((flags & WidthValue) != 0)
2217 if ((flags & HeightValue) == 0)
2218 geometry.height=geometry.width;
2219 image->page.width=geometry.width;
2220 image->page.height=geometry.height;
2222 if ((flags & AspectValue) != 0)
2224 if ((flags & XValue) != 0)
2225 image->page.x+=geometry.x;
2226 if ((flags & YValue) != 0)
2227 image->page.y+=geometry.y;
2231 if ((flags & XValue) != 0)
2233 image->page.x=geometry.x;
2234 if ((image->page.width == 0) && (geometry.x > 0))
2235 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2237 if ((flags & YValue) != 0)
2239 image->page.y=geometry.y;
2240 if ((image->page.height == 0) && (geometry.y > 0))
2241 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2273MagickExport MagickBooleanType ResetImagePixels(Image *image,
2274 ExceptionInfo *exception)
2291 assert(image != (Image *) NULL);
2292 assert(image->signature == MagickCoreSignature);
2293 if (IsEventLogging() != MagickFalse)
2294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2295 pixels=AcquirePixelCachePixels(image,&length,exception);
2296 if (pixels != (
void *) NULL)
2301 (void) memset(pixels,0,length);
2308 image_view=AcquireAuthenticCacheView(image,exception);
2309#if defined(MAGICKCORE_OPENMP_SUPPORT)
2310 #pragma omp parallel for schedule(static) shared(status) \
2311 magick_number_threads(image,image,image->rows,2)
2313 for (y=0; y < (ssize_t) image->rows; y++)
2321 if (status == MagickFalse)
2323 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2324 if (q == (Quantum *) NULL)
2329 for (x=0; x < (ssize_t) image->columns; x++)
2331 (void) memset(q,0,GetPixelChannels(image)*
sizeof(Quantum));
2332 q+=(ptrdiff_t) GetPixelChannels(image);
2334 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2337 image_view=DestroyCacheView(image_view);
2369MagickExport MagickBooleanType SetImageAlpha(Image *image,
const Quantum alpha,
2370 ExceptionInfo *exception)
2381 assert(image != (Image *) NULL);
2382 assert(image->signature == MagickCoreSignature);
2383 if (IsEventLogging() != MagickFalse)
2384 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2385 image->alpha_trait=BlendPixelTrait;
2387 image_view=AcquireAuthenticCacheView(image,exception);
2388#if defined(MAGICKCORE_OPENMP_SUPPORT)
2389 #pragma omp parallel for schedule(static) shared(status) \
2390 magick_number_threads(image,image,image->rows,2)
2392 for (y=0; y < (ssize_t) image->rows; y++)
2400 if (status == MagickFalse)
2402 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2403 if (q == (Quantum *) NULL)
2408 for (x=0; x < (ssize_t) image->columns; x++)
2410 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2411 SetPixelAlpha(image,alpha,q);
2412 q+=(ptrdiff_t) GetPixelChannels(image);
2414 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2417 image_view=DestroyCacheView(image_view);
2448MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2449 ExceptionInfo *exception)
2463 assert(image != (Image *) NULL);
2464 assert(image->signature == MagickCoreSignature);
2465 if (IsEventLogging() != MagickFalse)
2466 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2467 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2468 return(MagickFalse);
2469 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2470 ((image->alpha_trait & BlendPixelTrait) == 0))
2471 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2472 ConformPixelInfo(image,&image->background_color,&background,exception);
2477 image_view=AcquireAuthenticCacheView(image,exception);
2478#if defined(MAGICKCORE_OPENMP_SUPPORT)
2479 #pragma omp parallel for schedule(static) shared(status) \
2480 magick_number_threads(image,image,image->rows,2)
2482 for (y=0; y < (ssize_t) image->rows; y++)
2490 if (status == MagickFalse)
2492 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2493 if (q == (Quantum *) NULL)
2498 for (x=0; x < (ssize_t) image->columns; x++)
2500 SetPixelViaPixelInfo(image,&background,q);
2501 q+=(ptrdiff_t) GetPixelChannels(image);
2503 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2506 image_view=DestroyCacheView(image_view);
2536MagickExport ChannelType SetImageChannelMask(Image *image,
2537 const ChannelType channel_mask)
2539 return(SetPixelChannelMask(image,channel_mask));
2569MagickExport MagickBooleanType SetImageColor(Image *image,
2570 const PixelInfo *color,ExceptionInfo *exception)
2581 assert(image != (Image *) NULL);
2582 assert(image->signature == MagickCoreSignature);
2583 assert(color != (
const PixelInfo *) NULL);
2584 if (IsEventLogging() != MagickFalse)
2585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2586 image->colorspace=color->colorspace;
2587 image->alpha_trait=color->alpha_trait;
2588 image->fuzz=color->fuzz;
2589 image->depth=color->depth;
2591 image_view=AcquireAuthenticCacheView(image,exception);
2592#if defined(MAGICKCORE_OPENMP_SUPPORT)
2593 #pragma omp parallel for schedule(static) shared(status) \
2594 magick_number_threads(image,image,image->rows,2)
2596 for (y=0; y < (ssize_t) image->rows; y++)
2604 if (status == MagickFalse)
2606 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2607 if (q == (Quantum *) NULL)
2612 for (x=0; x < (ssize_t) image->columns; x++)
2614 SetPixelViaPixelInfo(image,color,q);
2615 q+=(ptrdiff_t) GetPixelChannels(image);
2617 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2620 image_view=DestroyCacheView(image_view);
2652MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2653 const ClassType storage_class,ExceptionInfo *exception)
2655 assert(image != (Image *) NULL);
2656 assert(image->signature == MagickCoreSignature);
2657 assert(exception != (ExceptionInfo *) NULL);
2658 assert(exception->signature == MagickCoreSignature);
2659 if (IsEventLogging() != MagickFalse)
2660 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2661 image->storage_class=storage_class;
2662 return(SyncImagePixelCache(image,exception));
2694MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2695 const size_t rows,ExceptionInfo *exception)
2697 if ((columns == 0) || (rows == 0))
2698 ThrowBinaryException(ImageError,
"NegativeOrZeroImageSize",image->filename);
2699 image->columns=columns;
2701 if (image->depth == 0)
2704 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2705 "ImageDepthNotSupported",
"`%s'",image->filename);
2707 if (image->depth > (8*
sizeof(MagickSizeType)))
2709 image->depth=8*
sizeof(MagickSizeType);
2710 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2711 "ImageDepthNotSupported",
"`%s'",image->filename);
2713 return(SyncImagePixelCache(image,exception));
2751static const MagickInfo *SetImageInfoFromExtension(ImageInfo *image_info,
2752 const char *component,
char *magic,ExceptionInfo *exception)
2764 *format_type_formats[] =
2788 (void) CopyMagickString(magic,component,MagickPathExtent);
2793 format_type=UndefinedFormatType;
2794 magick_info=GetMagickInfo(magic,exception);
2795 if ((magick_info != (
const MagickInfo *) NULL) &&
2796 (magick_info->format_type != UndefinedFormatType))
2797 format_type=magick_info->format_type;
2799 while ((format_type == UndefinedFormatType) &&
2800 (format_type_formats[i] != (
char *) NULL))
2802 if ((*magic == *format_type_formats[i]) &&
2803 (LocaleCompare(magic,format_type_formats[i]) == 0))
2804 format_type=ExplicitFormatType;
2807 if (format_type == UndefinedFormatType)
2808 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2810 if (format_type == ExplicitFormatType)
2812 image_info->affirm=MagickTrue;
2813 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2815 if (LocaleCompare(magic,
"RGB") == 0)
2816 image_info->affirm=MagickFalse;
2817 return(magick_info);
2820MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2821 const unsigned int frames,ExceptionInfo *exception)
2824 component[MagickPathExtent],
2825 magic[MagickPathExtent],
2826 path[MagickPathExtent],
2853 assert(image_info != (ImageInfo *) NULL);
2854 assert(image_info->signature == MagickCoreSignature);
2855 if (IsEventLogging() != MagickFalse)
2856 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2857 image_info->filename);
2859 GetPathComponent(image_info->filename,SubimagePath,component);
2860 if (*component !=
'\0')
2865 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2867 if (IsGeometry(component) != MagickFalse)
2868 (void) CloneString(&image_info->extract,component);
2876 (void) CloneString(&image_info->scenes,component);
2877 image_info->scene=StringToUnsignedLong(image_info->scenes);
2878 image_info->number_scenes=image_info->scene;
2879 p=image_info->scenes;
2880 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2882 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2884 first=(size_t) strtol(p,&q,10);
2886 while (isspace((
int) ((
unsigned char) *q)) != 0)
2889 last=(size_t) strtol(q+1,&q,10);
2892 if (first < image_info->scene)
2893 image_info->scene=first;
2894 if (last > image_info->number_scenes)
2895 image_info->number_scenes=last;
2898 image_info->number_scenes-=image_info->scene-1;
2902 if (*image_info->magick ==
'\0')
2903 GetPathComponent(image_info->filename,ExtensionPath,component);
2904 if (*component !=
'\0')
2909 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2910 GetPathComponent(path,ExtensionPath,component);
2912 image_info->affirm=MagickFalse;
2913 sans_exception=AcquireExceptionInfo();
2914 if ((*component !=
'\0') && (IsGlob(component) == MagickFalse))
2915 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2921 GetPathComponent(image_info->filename,MagickPath,magic);
2924 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2925 magick_info=GetMagickInfo(magic,sans_exception);
2926 if ((magick_info != (
const MagickInfo *) NULL) &&
2927 (magick_info->format_type == ExplicitFormatType))
2928 image_info->affirm=MagickTrue;
2930 GetPathComponent(image_info->filename,CanonicalPath,component);
2932 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2933 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2944 magick_info=GetMagickInfo(magic,sans_exception);
2945 delegate_info=(
const DelegateInfo *) NULL;
2946 if (magick_info == (
const MagickInfo *) NULL)
2948 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2949 if (delegate_info == (
const DelegateInfo *) NULL)
2950 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2951 if ((delegate_info == (
const DelegateInfo *) NULL) &&
2952 ((*component !=
'\0') && (IsGlob(component) == MagickFalse)))
2957 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2961 if (((magick_info != (
const MagickInfo *) NULL) ||
2962 (delegate_info != (
const DelegateInfo *) NULL)) &&
2963 (IsMagickConflict(magic) == MagickFalse))
2965 image_info->affirm=MagickTrue;
2966 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2967 GetPathComponent(image_info->filename,CanonicalPath,component);
2968 (void) CopyMagickString(image_info->filename,component,
2972 sans_exception=DestroyExceptionInfo(sans_exception);
2973 if ((magick_info == (
const MagickInfo *) NULL) ||
2974 (GetMagickEndianSupport(magick_info) == MagickFalse))
2975 image_info->endian=UndefinedEndian;
2976 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2981 (void) InterpretImageFilename(image_info,(Image *) NULL,
2982 image_info->filename,(
int) image_info->scene,component,exception);
2983 if ((LocaleCompare(component,image_info->filename) != 0) &&
2984 (strchr(component,
'%') == (
char *) NULL))
2985 image_info->adjoin=MagickFalse;
2987 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2992 magick_info=GetMagickInfo(magic,exception);
2993 if (magick_info != (
const MagickInfo *) NULL)
2994 if (GetMagickAdjoin(magick_info) == MagickFalse)
2995 image_info->adjoin=MagickFalse;
2997 if (image_info->affirm != MagickFalse)
3010 magick_size=GetMagicPatternExtent(exception);
3011 if (magick_size == 0)
3012 return(MagickFalse);
3013 image=AcquireImage(image_info,exception);
3014 (void) CopyMagickString(image->filename,image_info->filename,
3016 sans_exception=AcquireExceptionInfo();
3017 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3018 sans_exception=DestroyExceptionInfo(sans_exception);
3019 if (status == MagickFalse)
3021 image=DestroyImage(image);
3022 return(MagickFalse);
3024 if ((IsBlobSeekable(image) == MagickFalse) ||
3025 (IsBlobExempt(image) != MagickFalse))
3031 status=ImageToFile(image,component,exception);
3032 if (CloseBlob(image) == MagickFalse)
3034 if (status == MagickFalse)
3036 (void) RelinquishUniqueFileResource(component);
3037 image=DestroyImage(image);
3038 return(MagickFalse);
3040 SetImageInfoFile(image_info,(FILE *) NULL);
3041 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3042 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3043 if (status == MagickFalse)
3045 (void) RelinquishUniqueFileResource(component);
3046 image=DestroyImage(image);
3047 return(MagickFalse);
3049 (void) CopyMagickString(image_info->filename,component,
3051 image_info->temporary=MagickTrue;
3053 magick=(
unsigned char *) AcquireQuantumMemory(1,magick_size);
3054 if (magick == (
unsigned char *) NULL)
3056 (void) CloseBlob(image);
3057 image=DestroyImage(image);
3058 return(MagickFalse);
3060 (void) memset(magick,0,magick_size);
3061 count=ReadBlob(image,magick_size,magick);
3062 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3063 (void) CloseBlob(image);
3064 image=DestroyImage(image);
3068 sans_exception=AcquireExceptionInfo();
3069 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3070 magick=(
unsigned char *) RelinquishMagickMemory(magick);
3071 if ((magic_info != (
const MagicInfo *) NULL) &&
3072 (GetMagicName(magic_info) != (
char *) NULL))
3077 if ((magick_info != (
const MagickInfo *) NULL) &&
3078 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3079 (LocaleCompare(magick_info->magick_module,GetMagicName(
3081 (void) CopyMagickString(image_info->magick,magick_info->name,
3085 (void) CopyMagickString(image_info->magick,GetMagicName(
3086 magic_info),MagickPathExtent);
3087 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3089 if ((magick_info == (
const MagickInfo *) NULL) ||
3090 (GetMagickEndianSupport(magick_info) == MagickFalse))
3091 image_info->endian=UndefinedEndian;
3092 sans_exception=DestroyExceptionInfo(sans_exception);
3095 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3096 if ((magick_info == (
const MagickInfo *) NULL) ||
3097 (GetMagickEndianSupport(magick_info) == MagickFalse))
3098 image_info->endian=UndefinedEndian;
3099 sans_exception=DestroyExceptionInfo(sans_exception);
3131MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3132 const size_t length)
3134 assert(image_info != (ImageInfo *) NULL);
3135 assert(image_info->signature == MagickCoreSignature);
3136 if (IsEventLogging() != MagickFalse)
3137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3138 image_info->filename);
3139 image_info->blob=(
void *) blob;
3140 image_info->length=length;
3168MagickExport
void SetImageInfoCustomStream(ImageInfo *image_info,
3169 CustomStreamInfo *custom_stream)
3171 assert(image_info != (ImageInfo *) NULL);
3172 assert(image_info->signature == MagickCoreSignature);
3173 if (IsEventLogging() != MagickFalse)
3174 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3175 image_info->filename);
3176 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3203MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3205 assert(image_info != (ImageInfo *) NULL);
3206 assert(image_info->signature == MagickCoreSignature);
3207 if (IsEventLogging() != MagickFalse)
3208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3209 image_info->filename);
3210 image_info->file=file;
3243MagickExport MagickBooleanType SetImageMask(Image *image,
const PixelMask type,
3244 const Image *mask,ExceptionInfo *exception)
3259 assert(image != (Image *) NULL);
3260 if (IsEventLogging() != MagickFalse)
3261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3262 assert(image->signature == MagickCoreSignature);
3263 if (mask == (
const Image *) NULL)
3269 image->channels=(ChannelType) ((
unsigned int) image->channels &
3270 (
unsigned int) ~ReadMaskChannel);
3273 case WritePixelMask:
3275 image->channels=(ChannelType) ((
unsigned int) image->channels &
3276 (
unsigned int) ~WriteMaskChannel);
3281 image->channels=(ChannelType) ((
unsigned int) image->channels &
3282 (
unsigned int) ~CompositeMaskChannel);
3286 return(SyncImagePixelCache(image,exception));
3292 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3295 case WritePixelMask:
3297 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3302 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3306 if (SyncImagePixelCache(image,exception) == MagickFalse)
3307 return(MagickFalse);
3309 image->mask_trait=UpdatePixelTrait;
3310 mask_view=AcquireVirtualCacheView(mask,exception);
3311 image_view=AcquireAuthenticCacheView(image,exception);
3312#if defined(MAGICKCORE_OPENMP_SUPPORT)
3313 #pragma omp parallel for schedule(static) shared(status) \
3314 magick_number_threads(mask,image,image->rows,2)
3316 for (y=0; y < (ssize_t) image->rows; y++)
3327 if (status == MagickFalse)
3329 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3330 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3331 if ((p == (
const Quantum *) NULL) || (q == (Quantum *) NULL))
3336 for (x=0; x < (ssize_t) image->columns; x++)
3342 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3343 intensity=GetPixelIntensity(mask,p);
3348 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3351 case WritePixelMask:
3353 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3358 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3362 p+=(ptrdiff_t) GetPixelChannels(mask);
3363 q+=(ptrdiff_t) GetPixelChannels(image);
3365 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3368 image->mask_trait=UndefinedPixelTrait;
3369 mask_view=DestroyCacheView(mask_view);
3370 image_view=DestroyCacheView(image_view);
3404MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3405 const PixelMask type,
const RectangleInfo *region,ExceptionInfo *exception)
3419 assert(image != (Image *) NULL);
3420 assert(image->signature == MagickCoreSignature);
3421 if (IsEventLogging() != MagickFalse)
3422 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3423 if (region == (
const RectangleInfo *) NULL)
3429 image->channels=(ChannelType) ((
unsigned int) image->channels &
3430 (
unsigned int) ~ReadMaskChannel);
3433 case WritePixelMask:
3435 image->channels=(ChannelType) ((
unsigned int) image->channels &
3436 (
unsigned int) ~WriteMaskChannel);
3441 image->channels=(ChannelType) ((
unsigned int) image->channels &
3442 (
unsigned int) ~CompositeMaskChannel);
3446 return(SyncImagePixelCache(image,exception));
3452 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3455 case WritePixelMask:
3457 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3462 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3466 if (SyncImagePixelCache(image,exception) == MagickFalse)
3467 return(MagickFalse);
3469 image->mask_trait=UpdatePixelTrait;
3470 image_view=AcquireAuthenticCacheView(image,exception);
3471#if defined(MAGICKCORE_OPENMP_SUPPORT)
3472 #pragma omp parallel for schedule(static) shared(status) \
3473 magick_number_threads(image,image,image->rows,2)
3475 for (y=0; y < (ssize_t) image->rows; y++)
3483 if (status == MagickFalse)
3485 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3486 if (q == (Quantum *) NULL)
3491 for (x=0; x < (ssize_t) image->columns; x++)
3497 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3498 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3504 SetPixelReadMask(image,pixel,q);
3507 case WritePixelMask:
3509 SetPixelWriteMask(image,pixel,q);
3514 SetPixelCompositeMask(image,pixel,q);
3518 q+=(ptrdiff_t) GetPixelChannels(image);
3520 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3523 image->mask_trait=UndefinedPixelTrait;
3524 image_view=DestroyCacheView(image_view);
3557MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3558 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3560 assert(image != (
const Image *) NULL);
3561 assert(image->signature == MagickCoreSignature);
3562 if (IsEventLogging() != MagickFalse)
3563 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3564 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3602static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3603 const ssize_t offset,ExceptionInfo *exception)
3630 if (images->previous == (Image *) NULL)
3633 SetGeometry(smush_image,&right_geometry);
3634 GravityAdjustGeometry(right_image->columns,right_image->rows,
3635 right_image->gravity,&right_geometry);
3636 left_image=images->previous;
3637 SetGeometry(smush_image,&left_geometry);
3638 GravityAdjustGeometry(left_image->columns,left_image->rows,
3639 left_image->gravity,&left_geometry);
3640 gap=right_image->columns;
3641 left_view=AcquireVirtualCacheView(left_image,exception);
3642 right_view=AcquireVirtualCacheView(right_image,exception);
3643 for (y=0; y < (ssize_t) smush_image->rows; y++)
3645 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3647 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3648 if ((p == (
const Quantum *) NULL) ||
3649 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3650 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3653 i=(ssize_t) left_image->columns-x-1;
3654 for (x=0; x < (ssize_t) right_image->columns; x++)
3656 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3658 if ((p == (
const Quantum *) NULL) ||
3659 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3660 ((x+i) >= (ssize_t) gap))
3663 if ((x+i) < (ssize_t) gap)
3666 right_view=DestroyCacheView(right_view);
3667 left_view=DestroyCacheView(left_view);
3668 if (y < (ssize_t) smush_image->rows)
3670 return((ssize_t) gap-offset);
3673static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3674 const ssize_t offset,ExceptionInfo *exception)
3701 if (images->previous == (Image *) NULL)
3703 bottom_image=images;
3704 SetGeometry(smush_image,&bottom_geometry);
3705 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3706 bottom_image->gravity,&bottom_geometry);
3707 top_image=images->previous;
3708 SetGeometry(smush_image,&top_geometry);
3709 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3711 gap=bottom_image->rows;
3712 top_view=AcquireVirtualCacheView(top_image,exception);
3713 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3714 for (x=0; x < (ssize_t) smush_image->columns; x++)
3716 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3718 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3719 if ((p == (
const Quantum *) NULL) ||
3720 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3721 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3724 i=(ssize_t) top_image->rows-y-1;
3725 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3727 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3729 if ((p == (
const Quantum *) NULL) ||
3730 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3731 ((y+i) >= (ssize_t) gap))
3734 if ((y+i) < (ssize_t) gap)
3737 bottom_view=DestroyCacheView(bottom_view);
3738 top_view=DestroyCacheView(top_view);
3739 if (x < (ssize_t) smush_image->columns)
3741 return((ssize_t) gap-offset);
3744MagickExport Image *SmushImages(
const Image *images,
3745 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3747#define SmushImageTag "Smush/Image"
3783 assert(images != (Image *) NULL);
3784 assert(images->signature == MagickCoreSignature);
3785 assert(exception != (ExceptionInfo *) NULL);
3786 assert(exception->signature == MagickCoreSignature);
3787 if (IsEventLogging() != MagickFalse)
3788 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3790 alpha_trait=image->alpha_trait;
3792 width=image->columns;
3794 next=GetNextImageInList(image);
3795 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3797 if (next->alpha_trait != UndefinedPixelTrait)
3798 alpha_trait=BlendPixelTrait;
3800 if (stack != MagickFalse)
3802 if (next->columns > width)
3803 width=next->columns;
3805 if (next->previous != (Image *) NULL)
3806 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3809 width+=next->columns;
3810 if (next->previous != (Image *) NULL)
3811 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3812 if (next->rows > height)
3818 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3819 if (smush_image == (Image *) NULL)
3820 return((Image *) NULL);
3821 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3823 smush_image=DestroyImage(smush_image);
3824 return((Image *) NULL);
3826 smush_image->alpha_trait=alpha_trait;
3827 (void) SetImageBackgroundColor(smush_image,exception);
3831 for (n=0; n < (MagickOffsetType) number_images; n++)
3833 SetGeometry(smush_image,&geometry);
3834 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3835 if (stack != MagickFalse)
3837 x_offset-=geometry.x;
3838 y_offset-=SmushYGap(smush_image,image,offset,exception);
3842 x_offset-=SmushXGap(smush_image,image,offset,exception);
3843 y_offset-=geometry.y;
3845 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3846 y_offset,exception);
3847 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3848 if (proceed == MagickFalse)
3850 if (stack == MagickFalse)
3852 x_offset+=(ssize_t) image->columns;
3858 y_offset+=(ssize_t) image->rows;
3860 image=GetNextImageInList(image);
3862 if (stack == MagickFalse)
3863 smush_image->columns=(size_t) x_offset;
3865 smush_image->rows=(size_t) y_offset;
3866 if (status == MagickFalse)
3867 smush_image=DestroyImage(smush_image);
3868 return(smush_image);
3895MagickExport MagickBooleanType StripImage(Image *image,
3896 ExceptionInfo *magick_unused(exception))
3901 magick_unreferenced(exception);
3902 assert(image != (Image *) NULL);
3903 if (IsEventLogging() != MagickFalse)
3904 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3905 DestroyImageProfiles(image);
3906 (void) DeleteImageProperty(image,
"comment");
3907 (void) DeleteImageProperty(image,
"date:create");
3908 (void) DeleteImageProperty(image,
"date:modify");
3909 (void) DeleteImageProperty(image,
"date:timestamp");
3910 status=SetImageArtifact(image,
"png:exclude-chunk",
3911 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3941static inline Quantum PushColormapIndex(Image *image,
const Quantum index,
3942 MagickBooleanType *range_exception)
3944 if ((
size_t) index < image->colors)
3946 *range_exception=MagickTrue;
3947 return((Quantum) 0);
3950MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3963 assert(image != (Image *) NULL);
3964 assert(image->signature == MagickCoreSignature);
3965 if (IsEventLogging() != MagickFalse)
3966 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3967 if (image->ping != MagickFalse)
3969 if (image->storage_class != PseudoClass)
3970 return(MagickFalse);
3971 assert(image->colormap != (PixelInfo *) NULL);
3972 range_exception=MagickFalse;
3975 image_view=AcquireAuthenticCacheView(image,exception);
3976#if defined(MAGICKCORE_OPENMP_SUPPORT)
3977 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3978 magick_number_threads(image,image,image->rows,2)
3980 for (y=0; y < (ssize_t) image->rows; y++)
3991 if (status == MagickFalse)
3993 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3994 if (q == (Quantum *) NULL)
3999 for (x=0; x < (ssize_t) image->columns; x++)
4001 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4002 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4003 q+=(ptrdiff_t) GetPixelChannels(image);
4005 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4008 image_view=DestroyCacheView(image_view);
4010 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4011 (void) ThrowMagickException(exception,GetMagickModule(),
4012 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
4053MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4054 Image *images,ExceptionInfo *exception)
4059 assert(image_info != (
const ImageInfo *) NULL);
4060 assert(image_info->signature == MagickCoreSignature);
4061 assert(images != (Image *) NULL);
4062 assert(images->signature == MagickCoreSignature);
4063 if (IsEventLogging() != MagickFalse)
4064 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
4066 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4067 (
void) SyncImageSettings(image_info,image,exception);
4068 (void) DeleteImageOption(image_info,
"page");
4072MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
4073 Image *image,ExceptionInfo *exception)
4090 assert(image_info != (
const ImageInfo *) NULL);
4091 assert(image_info->signature == MagickCoreSignature);
4092 assert(image != (Image *) NULL);
4093 assert(image->signature == MagickCoreSignature);
4094 if (IsEventLogging() != MagickFalse)
4095 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4096 option=GetImageOption(image_info,
"background");
4097 if (option != (
const char *) NULL)
4098 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4100 option=GetImageOption(image_info,
"black-point-compensation");
4101 if (option != (
const char *) NULL)
4102 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4103 MagickBooleanOptions,MagickFalse,option);
4104 option=GetImageOption(image_info,
"blue-primary");
4105 if (option != (
const char *) NULL)
4107 flags=ParseGeometry(option,&geometry_info);
4108 if ((flags & RhoValue) != 0)
4109 image->chromaticity.blue_primary.x=geometry_info.rho;
4110 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4111 if ((flags & SigmaValue) != 0)
4112 image->chromaticity.blue_primary.y=geometry_info.sigma;
4114 option=GetImageOption(image_info,
"bordercolor");
4115 if (option != (
const char *) NULL)
4116 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4119 option=GetImageOption(image_info,
"compose");
4120 if (option != (
const char *) NULL)
4121 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4122 MagickFalse,option);
4124 option=GetImageOption(image_info,
"compress");
4125 if (option != (
const char *) NULL)
4126 image->compression=(CompressionType) ParseCommandOption(
4127 MagickCompressOptions,MagickFalse,option);
4128 option=GetImageOption(image_info,
"debug");
4129 if (option != (
const char *) NULL)
4130 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4131 MagickFalse,option);
4132 option=GetImageOption(image_info,
"density");
4133 if (option != (
const char *) NULL)
4135 flags=ParseGeometry(option,&geometry_info);
4136 if ((flags & RhoValue) != 0)
4137 image->resolution.x=geometry_info.rho;
4138 image->resolution.y=image->resolution.x;
4139 if ((flags & SigmaValue) != 0)
4140 image->resolution.y=geometry_info.sigma;
4142 option=GetImageOption(image_info,
"depth");
4143 if (option != (
const char *) NULL)
4144 image->depth=StringToUnsignedLong(option);
4145 option=GetImageOption(image_info,
"endian");
4146 if (option != (
const char *) NULL)
4147 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4148 MagickFalse,option);
4149 option=GetImageOption(image_info,
"filter");
4150 if (option != (
const char *) NULL)
4151 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4152 MagickFalse,option);
4153 option=GetImageOption(image_info,
"fuzz");
4154 if (option != (
const char *) NULL)
4155 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
4156 option=GetImageOption(image_info,
"gravity");
4157 if (option != (
const char *) NULL)
4158 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4159 MagickFalse,option);
4160 option=GetImageOption(image_info,
"green-primary");
4161 if (option != (
const char *) NULL)
4163 flags=ParseGeometry(option,&geometry_info);
4164 if ((flags & RhoValue) != 0)
4165 image->chromaticity.green_primary.x=geometry_info.rho;
4166 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4167 if ((flags & SigmaValue) != 0)
4168 image->chromaticity.green_primary.y=geometry_info.sigma;
4170 option=GetImageOption(image_info,
"intent");
4171 if (option != (
const char *) NULL)
4172 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4173 MagickIntentOptions,MagickFalse,option);
4174 option=GetImageOption(image_info,
"intensity");
4175 if (option != (
const char *) NULL)
4176 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4177 MagickPixelIntensityOptions,MagickFalse,option);
4178 option=GetImageOption(image_info,
"interlace");
4179 if (option != (
const char *) NULL)
4180 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4181 MagickFalse,option);
4182 option=GetImageOption(image_info,
"interpolate");
4183 if (option != (
const char *) NULL)
4184 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4185 MagickInterpolateOptions,MagickFalse,option);
4186 option=GetImageOption(image_info,
"loop");
4187 if (option != (
const char *) NULL)
4188 image->iterations=StringToUnsignedLong(option);
4189 option=GetImageOption(image_info,
"mattecolor");
4190 if (option != (
const char *) NULL)
4191 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4193 option=GetImageOption(image_info,
"orient");
4194 if (option != (
const char *) NULL)
4195 image->orientation=(OrientationType) ParseCommandOption(
4196 MagickOrientationOptions,MagickFalse,option);
4197 option=GetImageOption(image_info,
"page");
4198 if (option != (
const char *) NULL)
4203 geometry=GetPageGeometry(option);
4204 flags=ParseAbsoluteGeometry(geometry,&image->page);
4205 geometry=DestroyString(geometry);
4207 option=GetImageOption(image_info,
"quality");
4208 if (option != (
const char *) NULL)
4209 image->quality=StringToUnsignedLong(option);
4210 option=GetImageOption(image_info,
"red-primary");
4211 if (option != (
const char *) NULL)
4213 flags=ParseGeometry(option,&geometry_info);
4214 if ((flags & RhoValue) != 0)
4215 image->chromaticity.red_primary.x=geometry_info.rho;
4216 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4217 if ((flags & SigmaValue) != 0)
4218 image->chromaticity.red_primary.y=geometry_info.sigma;
4220 if (image_info->quality != UndefinedCompressionQuality)
4221 image->quality=image_info->quality;
4222 option=GetImageOption(image_info,
"scene");
4223 if (option != (
const char *) NULL)
4224 image->scene=StringToUnsignedLong(option);
4225 option=GetImageOption(image_info,
"taint");
4226 if (option != (
const char *) NULL)
4227 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4228 MagickFalse,option);
4229 option=GetImageOption(image_info,
"tile-offset");
4230 if (option != (
const char *) NULL)
4235 geometry=GetPageGeometry(option);
4236 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4237 geometry=DestroyString(geometry);
4239 option=GetImageOption(image_info,
"transparent-color");
4240 if (option != (
const char *) NULL)
4241 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4243 option=GetImageOption(image_info,
"type");
4244 if (option != (
const char *) NULL)
4245 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4247 option=GetImageOption(image_info,
"units");
4248 units=image_info->units;
4249 if (option != (
const char *) NULL)
4250 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4251 MagickFalse,option);
4252 if (units != UndefinedResolution)
4254 if (image->units != units)
4255 switch (image->units)
4257 case PixelsPerInchResolution:
4259 if (units == PixelsPerCentimeterResolution)
4261 image->resolution.x/=2.54;
4262 image->resolution.y/=2.54;
4266 case PixelsPerCentimeterResolution:
4268 if (units == PixelsPerInchResolution)
4270 image->resolution.x=(double) ((
size_t) (100.0*2.54*
4271 image->resolution.x+0.5))/100.0;
4272 image->resolution.y=(double) ((
size_t) (100.0*2.54*
4273 image->resolution.y+0.5))/100.0;
4281 option=GetImageOption(image_info,
"density");
4282 if (option != (
const char *) NULL)
4284 flags=ParseGeometry(option,&geometry_info);
4285 if ((flags & RhoValue) != 0)
4286 image->resolution.x=geometry_info.rho;
4287 image->resolution.y=image->resolution.x;
4288 if ((flags & SigmaValue) != 0)
4289 image->resolution.y=geometry_info.sigma;
4292 option=GetImageOption(image_info,
"virtual-pixel");
4293 if (option != (
const char *) NULL)
4294 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4295 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4297 option=GetImageOption(image_info,
"white-point");
4298 if (option != (
const char *) NULL)
4300 flags=ParseGeometry(option,&geometry_info);
4301 if ((flags & RhoValue) != 0)
4302 image->chromaticity.white_point.x=geometry_info.rho;
4303 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4304 if ((flags & SigmaValue) != 0)
4305 image->chromaticity.white_point.y=geometry_info.sigma;
4313 if (image->image_info != (ImageInfo *) NULL)
4314 image->image_info=DestroyImageInfo(image->image_info);
4315 image->image_info=CloneImageInfo(image_info);