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"
700 assert(image != (
const Image *) NULL);
701 assert(image->signature == MagickCoreSignature);
702 assert(pathname != NULL);
703 if (IsEventLogging() != MagickFalse)
704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
705 property=AcquireString(pathname);
706 (void) FormatLocaleString(property,MaxTextExtent,
"8BIM:1999,2998:%s",
708 value=GetImageProperty(image,property);
709 property=DestroyString(property);
710 if (value == (
const char *) NULL)
712 ThrowFileException(&image->exception,OptionError,
"NoClipPathDefined",
716 image_info=AcquireImageInfo();
717 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
718 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
719 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
720 image_info=DestroyImageInfo(image_info);
721 if (clip_mask == (Image *) NULL)
723 if (clip_mask->storage_class == PseudoClass)
725 (void) SyncImage(clip_mask);
726 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
729 if (inside == MagickFalse)
730 (void) NegateImage(clip_mask,MagickFalse);
731 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
732 "8BIM:1999,2998:%s\nPS",pathname);
733 (void) SetImageClipMask(image,clip_mask);
734 clip_mask=DestroyImage(clip_mask);
777MagickExport Image *CloneImage(
const Image *image,
const size_t columns,
778 const size_t rows,
const MagickBooleanType detach,ExceptionInfo *exception)
793 assert(image != (
const Image *) NULL);
794 assert(image->signature == MagickCoreSignature);
795 assert(exception != (ExceptionInfo *) NULL);
796 assert(exception->signature == MagickCoreSignature);
797 if (IsEventLogging() != MagickFalse)
798 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
799 if ((image->columns == 0) || (image->rows == 0))
801 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
802 "NegativeOrZeroImageSize",
"`%s'",image->filename);
803 return((Image *) NULL);
805 clone_image=(Image *) AcquireCriticalMemory(
sizeof(*clone_image));
806 (void) memset(clone_image,0,
sizeof(*clone_image));
807 clone_image->signature=MagickCoreSignature;
808 clone_image->storage_class=image->storage_class;
809 clone_image->channels=image->channels;
810 clone_image->colorspace=image->colorspace;
811 clone_image->matte=image->matte;
812 clone_image->columns=image->columns;
813 clone_image->rows=image->rows;
814 clone_image->dither=image->dither;
815 (void) CloneImageProfiles(clone_image,image);
816 (void) CloneImageProperties(clone_image,image);
817 (void) CloneImageArtifacts(clone_image,image);
818 GetTimerInfo(&clone_image->timer);
819 InitializeExceptionInfo(&clone_image->exception);
820 InheritException(&clone_image->exception,&image->exception);
821 if (image->ascii85 != (
void *) NULL)
822 Ascii85Initialize(clone_image);
823 clone_image->extent=image->extent;
824 clone_image->magick_columns=image->magick_columns;
825 clone_image->magick_rows=image->magick_rows;
826 clone_image->type=image->type;
827 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
829 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
830 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
831 clone_image->progress_monitor=image->progress_monitor;
832 clone_image->client_data=image->client_data;
833 clone_image->reference_count=1;
834 clone_image->next=image->next;
835 clone_image->previous=image->previous;
836 clone_image->list=NewImageList();
837 clone_image->clip_mask=NewImageList();
838 clone_image->mask=NewImageList();
839 if (detach == MagickFalse)
840 clone_image->blob=ReferenceBlob(image->blob);
843 clone_image->next=NewImageList();
844 clone_image->previous=NewImageList();
845 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
847 clone_image->ping=image->ping;
848 clone_image->timestamp=image->timestamp;
849 clone_image->ttl=image->ttl;
850 clone_image->debug=image->debug;
851 clone_image->semaphore=AllocateSemaphoreInfo();
852 if (image->colormap != (PixelPacket *) NULL)
857 clone_image->colors=image->colors;
858 length=(size_t) image->colors;
859 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length+1,
860 sizeof(*clone_image->colormap));
861 if (clone_image->colormap == (PixelPacket *) NULL)
863 clone_image=DestroyImage(clone_image);
864 ThrowImageException(ResourceLimitError,
"MemoryAllocationFailed");
866 (void) memcpy(clone_image->colormap,image->colormap,length*
867 sizeof(*clone_image->colormap));
869 if ((columns == 0) || (rows == 0))
871 if (image->montage != (
char *) NULL)
872 (void) CloneString(&clone_image->montage,image->montage);
873 if (image->directory != (
char *) NULL)
874 (void) CloneString(&clone_image->directory,image->directory);
875 if (image->clip_mask != (Image *) NULL)
876 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
878 if (image->mask != (Image *) NULL)
879 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
880 clone_image->cache=ReferencePixelCache(image->cache);
883 if ((columns == image->columns) && (rows == image->rows))
885 if (image->clip_mask != (Image *) NULL)
886 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
888 if (image->mask != (Image *) NULL)
889 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
893 if (image->columns != 0)
894 scale_x=(double) columns/(
double) image->columns;
895 if (image->rows != 0)
896 scale_y=(double) rows/(
double) image->rows;
897 clone_image->page.width=(size_t) CastDoubleToLong(floor(scale_x*
898 image->page.width+0.5));
899 clone_image->page.height=(size_t) CastDoubleToLong(floor(scale_y*
900 image->page.height+0.5));
901 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
902 scale_x=scale_y=MagickMin(scale_x,scale_y);
903 clone_image->page.x=CastDoubleToLong(ceil(scale_x*image->page.x-0.5));
904 clone_image->tile_offset.x=CastDoubleToLong(ceil(scale_x*
905 image->tile_offset.x-0.5));
906 clone_image->page.y=CastDoubleToLong(ceil(scale_y*image->page.y-0.5));
907 clone_image->tile_offset.y=CastDoubleToLong(ceil(scale_y*
908 image->tile_offset.y-0.5));
909 clone_image->cache=ClonePixelCache(image->cache);
910 if (SetImageExtent(clone_image,columns,rows) == MagickFalse)
912 InheritException(exception,&clone_image->exception);
913 clone_image=DestroyImage(clone_image);
942MagickExport ImageInfo *CloneImageInfo(
const ImageInfo *image_info)
947 clone_info=AcquireImageInfo();
948 if (image_info == (ImageInfo *) NULL)
950 clone_info->compression=image_info->compression;
951 clone_info->temporary=image_info->temporary;
952 clone_info->adjoin=image_info->adjoin;
953 clone_info->antialias=image_info->antialias;
954 clone_info->scene=image_info->scene;
955 clone_info->number_scenes=image_info->number_scenes;
956 clone_info->depth=image_info->depth;
957 if (image_info->size != (
char *) NULL)
958 (void) CloneString(&clone_info->size,image_info->size);
959 if (image_info->extract != (
char *) NULL)
960 (void) CloneString(&clone_info->extract,image_info->extract);
961 if (image_info->scenes != (
char *) NULL)
962 (void) CloneString(&clone_info->scenes,image_info->scenes);
963 if (image_info->page != (
char *) NULL)
964 (void) CloneString(&clone_info->page,image_info->page);
965 clone_info->interlace=image_info->interlace;
966 clone_info->endian=image_info->endian;
967 clone_info->units=image_info->units;
968 clone_info->quality=image_info->quality;
969 if (image_info->sampling_factor != (
char *) NULL)
970 (void) CloneString(&clone_info->sampling_factor,
971 image_info->sampling_factor);
972 if (image_info->server_name != (
char *) NULL)
973 (void) CloneString(&clone_info->server_name,image_info->server_name);
974 if (image_info->font != (
char *) NULL)
975 (void) CloneString(&clone_info->font,image_info->font);
976 if (image_info->texture != (
char *) NULL)
977 (void) CloneString(&clone_info->texture,image_info->texture);
978 if (image_info->density != (
char *) NULL)
979 (void) CloneString(&clone_info->density,image_info->density);
980 clone_info->pointsize=image_info->pointsize;
981 clone_info->fuzz=image_info->fuzz;
982 clone_info->pen=image_info->pen;
983 clone_info->background_color=image_info->background_color;
984 clone_info->border_color=image_info->border_color;
985 clone_info->matte_color=image_info->matte_color;
986 clone_info->transparent_color=image_info->transparent_color;
987 clone_info->dither=image_info->dither;
988 clone_info->monochrome=image_info->monochrome;
989 clone_info->colors=image_info->colors;
990 clone_info->colorspace=image_info->colorspace;
991 clone_info->type=image_info->type;
992 clone_info->orientation=image_info->orientation;
993 clone_info->preview_type=image_info->preview_type;
994 clone_info->group=image_info->group;
995 clone_info->ping=image_info->ping;
996 clone_info->verbose=image_info->verbose;
997 if (image_info->view != (
char *) NULL)
998 (void) CloneString(&clone_info->view,image_info->view);
999 if (image_info->authenticate != (
char *) NULL)
1000 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
1001 (void) CloneImageOptions(clone_info,image_info);
1002 clone_info->progress_monitor=image_info->progress_monitor;
1003 clone_info->client_data=image_info->client_data;
1004 clone_info->cache=image_info->cache;
1005 if (image_info->cache != (
void *) NULL)
1006 clone_info->cache=ReferencePixelCache(image_info->cache);
1007 if (image_info->profile != (
void *) NULL)
1008 clone_info->profile=(
void *) CloneStringInfo((StringInfo *)
1009 image_info->profile);
1010 SetImageInfoFile(clone_info,image_info->file);
1011 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1012 clone_info->stream=image_info->stream;
1013 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
1014 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
1015 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
1016 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
1017 (void) CopyMagickString(clone_info->filename,image_info->filename,
1019 clone_info->subimage=image_info->scene;
1020 clone_info->subrange=image_info->number_scenes;
1021 clone_info->channel=image_info->channel;
1022 clone_info->debug=image_info->debug;
1023 clone_info->signature=image_info->signature;
1060MagickExport MagickBooleanType CopyImagePixels(Image *image,
1061 const Image *source_image,
const RectangleInfo *geometry,
1062 const OffsetInfo *offset,ExceptionInfo *exception)
1064#define CopyImageTag "Copy/Image"
1079 assert(image != (Image *) NULL);
1080 assert(source_image != (Image *) NULL);
1081 assert(geometry != (RectangleInfo *) NULL);
1082 assert(offset != (OffsetInfo *) NULL);
1083 if (IsEventLogging() != MagickFalse)
1084 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1085 if ((offset->x < 0) || (offset->y < 0) ||
1086 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1087 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1088 ThrowBinaryException(OptionError,
"GeometryDoesNotContainImage",
1090 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1091 return(MagickFalse);
1097 source_view=AcquireVirtualCacheView(source_image,exception);
1098 image_view=AcquireAuthenticCacheView(image,exception);
1099#if defined(MAGICKCORE_OPENMP_SUPPORT)
1100 #pragma omp parallel for schedule(static) shared(progress,status) \
1101 magick_number_threads(source_image,image,geometry->height,2)
1103 for (y=0; y < (ssize_t) geometry->height; y++)
1106 *magick_restrict source_indexes;
1112 *magick_restrict indexes;
1120 if (status == MagickFalse)
1122 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1123 geometry->width,1,exception);
1124 q=GetCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1125 geometry->width,1,exception);
1126 if ((p == (
const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1131 source_indexes=GetCacheViewVirtualIndexQueue(source_view);
1132 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1133 for (x=0; x < (ssize_t) geometry->width; x++)
1136 if (image->colorspace == CMYKColorspace)
1137 indexes[x]=source_indexes[x];
1141 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1143 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1148#if defined(MAGICKCORE_OPENMP_SUPPORT)
1152 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1153 if (proceed == MagickFalse)
1157 image_view=DestroyCacheView(image_view);
1158 source_view=DestroyCacheView(source_view);
1185MagickExport Image *DestroyImage(Image *image)
1193 assert(image != (Image *) NULL);
1194 assert(image->signature == MagickCoreSignature);
1195 if (IsEventLogging() != MagickFalse)
1196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1197 destroy=MagickFalse;
1198 LockSemaphoreInfo(image->semaphore);
1199 image->reference_count--;
1200 if (image->reference_count == 0)
1202 UnlockSemaphoreInfo(image->semaphore);
1203 if (destroy == MagickFalse)
1204 return((Image *) NULL);
1208 DestroyImagePixels(image);
1209 if (image->clip_mask != (Image *) NULL)
1210 image->clip_mask=DestroyImage(image->clip_mask);
1211 if (image->mask != (Image *) NULL)
1212 image->mask=DestroyImage(image->mask);
1213 if (image->montage != (
char *) NULL)
1214 image->montage=DestroyString(image->montage);
1215 if (image->directory != (
char *) NULL)
1216 image->directory=DestroyString(image->directory);
1217 if (image->colormap != (PixelPacket *) NULL)
1218 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1219 if (image->geometry != (
char *) NULL)
1220 image->geometry=DestroyString(image->geometry);
1221 DestroyImageProfiles(image);
1222 DestroyImageProperties(image);
1223 DestroyImageArtifacts(image);
1224 if (image->ascii85 != (Ascii85Info*) NULL)
1225 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1227 (void) ClearExceptionInfo(&image->exception,MagickTrue);
1229 DestroySemaphoreInfo(&image->semaphore);
1230 image->signature=(~MagickCoreSignature);
1231 image=(Image *) RelinquishMagickMemory(image);
1258MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1260 assert(image_info != (ImageInfo *) NULL);
1261 assert(image_info->signature == MagickCoreSignature);
1262 if (IsEventLogging() != MagickFalse)
1263 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1264 image_info->filename);
1265 if (image_info->size != (
char *) NULL)
1266 image_info->size=DestroyString(image_info->size);
1267 if (image_info->extract != (
char *) NULL)
1268 image_info->extract=DestroyString(image_info->extract);
1269 if (image_info->scenes != (
char *) NULL)
1270 image_info->scenes=DestroyString(image_info->scenes);
1271 if (image_info->page != (
char *) NULL)
1272 image_info->page=DestroyString(image_info->page);
1273 if (image_info->sampling_factor != (
char *) NULL)
1274 image_info->sampling_factor=DestroyString(
1275 image_info->sampling_factor);
1276 if (image_info->server_name != (
char *) NULL)
1277 image_info->server_name=DestroyString(
1278 image_info->server_name);
1279 if (image_info->font != (
char *) NULL)
1280 image_info->font=DestroyString(image_info->font);
1281 if (image_info->texture != (
char *) NULL)
1282 image_info->texture=DestroyString(image_info->texture);
1283 if (image_info->density != (
char *) NULL)
1284 image_info->density=DestroyString(image_info->density);
1285 if (image_info->view != (
char *) NULL)
1286 image_info->view=DestroyString(image_info->view);
1287 if (image_info->authenticate != (
char *) NULL)
1288 image_info->authenticate=DestroyString(
1289 image_info->authenticate);
1290 DestroyImageOptions(image_info);
1291 if (image_info->cache != (
void *) NULL)
1292 image_info->cache=DestroyPixelCache(image_info->cache);
1293 if (image_info->profile != (StringInfo *) NULL)
1294 image_info->profile=(
void *) DestroyStringInfo((StringInfo *)
1295 image_info->profile);
1296 image_info->signature=(~MagickCoreSignature);
1297 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1325MagickExport
void DisassociateImageStream(Image *image)
1327 assert(image != (Image *) NULL);
1328 assert(image->signature == MagickCoreSignature);
1329 if (IsEventLogging() != MagickFalse)
1330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1331 DisassociateBlob(image);
1356MagickExport Image *GetImageClipMask(
const Image *image,
1357 ExceptionInfo *exception)
1359 assert(image != (
const Image *) NULL);
1360 assert(image->signature == MagickCoreSignature);
1361 if (IsEventLogging() != MagickFalse)
1362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1363 if (image->clip_mask == (Image *) NULL)
1364 return((Image *) NULL);
1365 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1393MagickExport
void GetImageException(Image *image,ExceptionInfo *exception)
1398 assert(image != (Image *) NULL);
1399 assert(image->signature == MagickCoreSignature);
1400 assert(exception != (ExceptionInfo *) NULL);
1401 assert(exception->signature == MagickCoreSignature);
1402 if (IsEventLogging() != MagickFalse)
1403 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1404 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1406 if (next->exception.severity == UndefinedException)
1408 if (next->exception.severity > exception->severity)
1409 InheritException(exception,&next->exception);
1410 next->exception.severity=UndefinedException;
1436MagickExport
void GetImageInfo(ImageInfo *image_info)
1444 assert(image_info != (ImageInfo *) NULL);
1445 if (IsEventLogging() != MagickFalse)
1446 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1447 (void) memset(image_info,0,
sizeof(*image_info));
1448 image_info->adjoin=MagickTrue;
1449 image_info->interlace=NoInterlace;
1450 image_info->channel=DefaultChannels;
1451 image_info->quality=UndefinedCompressionQuality;
1452 image_info->antialias=MagickTrue;
1453 image_info->dither=MagickTrue;
1454 synchronize=GetEnvironmentValue(
"MAGICK_SYNCHRONIZE");
1455 if (synchronize != (
const char *) NULL)
1457 image_info->synchronize=IsStringTrue(synchronize);
1458 synchronize=DestroyString(synchronize);
1460 GetPixelPacketRGBA(BackgroundColorRGBA,&image_info->background_color);
1461 GetPixelPacketRGBA(BorderColorRGBA,&image_info->border_color);
1462 GetPixelPacketRGBA(MatteColorRGBA,&image_info->matte_color);
1463 GetPixelPacketRGBA(TransparentColorRGBA,&image_info->transparent_color);
1464 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1466 image_info->signature=MagickCoreSignature;
1491MagickExport FILE *GetImageInfoFile(
const ImageInfo *image_info)
1493 return(image_info->file);
1518MagickExport Image *GetImageMask(
const Image *image,ExceptionInfo *exception)
1520 assert(image != (
const Image *) NULL);
1521 assert(image->signature == MagickCoreSignature);
1522 if (IsEventLogging() != MagickFalse)
1523 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1524 if (image->mask == (Image *) NULL)
1525 return((Image *) NULL);
1526 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1552MagickExport
size_t GetImageChannels(Image *image)
1554 assert(image != (Image *) NULL);
1555 assert(image->signature == MagickCoreSignature);
1556 if (IsEventLogging() != MagickFalse)
1557 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1558 return(image->channels);
1583MagickExport ssize_t GetImageReferenceCount(Image *image)
1588 assert(image != (Image *) NULL);
1589 assert(image->signature == MagickCoreSignature);
1590 if (IsEventLogging() != MagickFalse)
1591 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1592 LockSemaphoreInfo(image->semaphore);
1593 reference_count=image->reference_count;
1594 UnlockSemaphoreInfo(image->semaphore);
1595 return(reference_count);
1622MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(
const Image *image)
1624 assert(image != (Image *) NULL);
1625 assert(image->signature == MagickCoreSignature);
1626 if (IsEventLogging() != MagickFalse)
1627 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1628 return(GetPixelCacheVirtualMethod(image));
1665static inline MagickBooleanType IsValidFormatSpecifier(
const char *start,
1669 specifier = end[-1];
1677 if ((specifier !=
'd') && (specifier !=
'x') && (specifier !=
'o'))
1678 return(MagickFalse);
1679 if ((length == 1) && (*start == specifier))
1688 if ((length >= 3) && (start[1] ==
'0'))
1689 return(MagickFalse);
1692 for ( ; i < (length-1); i++)
1693 if (isdigit((
int) ((
unsigned char) start[i])) == 0)
1694 return(MagickFalse);
1697 return(MagickFalse);
1700MagickExport
size_t InterpretImageFilename(
const ImageInfo *image_info,
1701 Image *image,
const char *format,
int value,
char *filename)
1705 pattern[MagickPathExtent];
1710 assert(format != (
const char *) NULL);
1711 assert(filename != (
char *) NULL);
1712 if (IsStringTrue(GetImageOption(image_info,
"filename:literal")) != MagickFalse)
1714 (void) CopyMagickString(filename,format,MagickPathExtent);
1715 return(strlen(filename));
1717 while ((*cursor !=
'\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1735 specifier_start=cursor;
1736 while (isdigit((
int) ((
unsigned char) *cursor)) != 0)
1738 if ((*cursor ==
'd') || (*cursor ==
'o') || (*cursor ==
'x'))
1741 *specifier_end = cursor+1;
1743 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1746 format_specifier[MagickPathExtent];
1749 length = cursor-specifier_start;
1754 (void) snprintf(format_specifier,
sizeof(format_specifier),
1755 "%%%.*s%c",(
int) length,specifier_start,*cursor);
1756 count=FormatLocaleString(pattern,
sizeof(pattern),format_specifier,
1758 if ((count <= 0) || ((p-filename+count) >= MagickPathExtent))
1760 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
1778 *end = strchr(cursor,
']'),
1779 *option = (
const char *) NULL;
1785 if (end == (
const char *) NULL)
1787 extent=(size_t) (end-cursor-1);
1788 if (extent >=
sizeof(pattern))
1790 (void) CopyMagickString(pattern,cursor+1,extent+1);
1791 pattern[extent]=
'\0';
1794 option=GetImageProperty(image,pattern);
1795 if (option == (
const char *) NULL)
1796 option=GetImageArtifact(image,pattern);
1798 if ((option == (
const char *) NULL) &&
1799 (image_info != (ImageInfo *) NULL))
1800 option=GetImageOption(image_info,pattern);
1801 if (option == (
const char *) NULL)
1803 option_length=strlen(option);
1804 if ((p-filename+option_length) >= MagickPathExtent)
1806 (void) CopyMagickString(p,option,MagickPathExtent-(p-filename));
1815 if ((p-filename+1) >= MagickPathExtent)
1820 return(strlen(filename));
1850MagickExport MagickBooleanType IsHighDynamicRangeImage(
const Image *image,
1851 ExceptionInfo *exception)
1853#if !defined(MAGICKCORE_HDRI_SUPPORT)
1856 return(MagickFalse);
1870 assert(image != (Image *) NULL);
1871 assert(image->signature == MagickCoreSignature);
1872 if (IsEventLogging() != MagickFalse)
1873 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1874 GetMagickPixelPacket(image,&zero);
1875 image_view=AcquireVirtualCacheView(image,exception);
1876#if defined(MAGICKCORE_OPENMP_SUPPORT)
1877 #pragma omp parallel for schedule(static) shared(hdri) \
1878 magick_number_threads(image,image,image->rows,2)
1880 for (y=0; y < (ssize_t) image->rows; y++)
1894 if (hdri != MagickFalse)
1896 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1897 if (p == (
const PixelPacket *) NULL)
1899 indexes=GetCacheViewVirtualIndexQueue(image_view);
1901 for (x=0; x < (ssize_t) image->columns; x++)
1903 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1904 if ((pixel.red < 0.0) || (pixel.red > (MagickRealType) QuantumRange) ||
1905 (pixel.red != (QuantumAny) pixel.red))
1907 if ((pixel.green < 0.0) ||
1908 (pixel.green > (MagickRealType) QuantumRange) ||
1909 (pixel.green != (QuantumAny) pixel.green))
1911 if ((pixel.blue < 0.0) || (pixel.blue > (MagickRealType) QuantumRange) ||
1912 (pixel.blue != (QuantumAny) pixel.blue))
1914 if (pixel.matte != MagickFalse)
1916 if ((pixel.opacity < 0.0) || (pixel.opacity > (MagickRealType) QuantumRange) ||
1917 (pixel.opacity != (QuantumAny) pixel.opacity))
1920 if (pixel.colorspace == CMYKColorspace)
1922 if ((pixel.index < 0.0) ||
1923 (pixel.index > (MagickRealType) QuantumRange) ||
1924 (pixel.index != (QuantumAny) pixel.index))
1927 if (hdri != MagickFalse)
1932 image_view=DestroyCacheView(image_view);
1960MagickExport MagickBooleanType IsImageObject(
const Image *image)
1965 assert(image != (Image *) NULL);
1966 if (IsEventLogging() != MagickFalse)
1967 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1968 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1969 if (p->signature != MagickCoreSignature)
1970 return(MagickFalse);
1997MagickExport MagickBooleanType IsTaintImage(
const Image *image)
2000 magick[MaxTextExtent],
2001 filename[MaxTextExtent];
2006 assert(image != (Image *) NULL);
2007 assert(image->signature == MagickCoreSignature);
2008 if (IsEventLogging() != MagickFalse)
2009 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2010 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2011 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2012 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2014 if (p->taint != MagickFalse)
2016 if (LocaleCompare(p->magick,magick) != 0)
2018 if (LocaleCompare(p->filename,filename) != 0)
2021 return(MagickFalse);
2050MagickExport MagickBooleanType ModifyImage(Image **image,
2051 ExceptionInfo *exception)
2056 assert(image != (Image **) NULL);
2057 assert(*image != (Image *) NULL);
2058 assert((*image)->signature == MagickCoreSignature);
2059 if (IsEventLogging() != MagickFalse)
2060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
2061 if (GetImageReferenceCount(*image) <= 1)
2063 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2064 LockSemaphoreInfo((*image)->semaphore);
2065 (*image)->reference_count--;
2066 UnlockSemaphoreInfo((*image)->semaphore);
2101MagickExport Image *NewMagickImage(
const ImageInfo *image_info,
2102 const size_t width,
const size_t height,
const MagickPixelPacket *background)
2119 assert(image_info != (
const ImageInfo *) NULL);
2120 assert(image_info->signature == MagickCoreSignature);
2121 assert(background != (
const MagickPixelPacket *) NULL);
2122 if (IsEventLogging() != MagickFalse)
2123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2124 image=AcquireImage(image_info);
2125 image->columns=width;
2127 image->colorspace=background->colorspace;
2128 image->matte=background->matte;
2129 image->fuzz=background->fuzz;
2130 image->depth=background->depth;
2132 exception=(&image->exception);
2133 image_view=AcquireAuthenticCacheView(image,exception);
2134#if defined(MAGICKCORE_OPENMP_SUPPORT)
2135 #pragma omp parallel for schedule(static) shared(status) \
2136 magick_number_threads(image,image,image->rows,2)
2138 for (y=0; y < (ssize_t) image->rows; y++)
2141 *magick_restrict indexes;
2149 if (status == MagickFalse)
2151 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2152 if (q == (PixelPacket *) NULL)
2157 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2158 for (x=0; x < (ssize_t) image->columns; x++)
2160 SetPixelPacket(image,background,q,indexes+x);
2163 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2166 image_view=DestroyCacheView(image_view);
2167 if (status == MagickFalse)
2168 image=DestroyImage(image);
2195MagickExport Image *ReferenceImage(Image *image)
2197 assert(image != (Image *) NULL);
2198 assert(image->signature == MagickCoreSignature);
2199 if (IsEventLogging() != MagickFalse)
2200 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2201 LockSemaphoreInfo(image->semaphore);
2202 image->reference_count++;
2203 UnlockSemaphoreInfo(image->semaphore);
2231MagickExport MagickBooleanType ResetImagePage(Image *image,
const char *page)
2239 assert(image != (Image *) NULL);
2240 assert(image->signature == MagickCoreSignature);
2241 if (IsEventLogging() != MagickFalse)
2242 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2243 flags=ParseAbsoluteGeometry(page,&geometry);
2244 if ((flags & WidthValue) != 0)
2246 if ((flags & HeightValue) == 0)
2247 geometry.height=geometry.width;
2248 image->page.width=geometry.width;
2249 image->page.height=geometry.height;
2251 if ((flags & AspectValue) != 0)
2253 if ((flags & XValue) != 0)
2254 image->page.x+=geometry.x;
2255 if ((flags & YValue) != 0)
2256 image->page.y+=geometry.y;
2260 if ((flags & XValue) != 0)
2262 image->page.x=geometry.x;
2263 if ((image->page.width == 0) && (geometry.x > 0))
2264 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2266 if ((flags & YValue) != 0)
2268 image->page.y=geometry.y;
2269 if ((image->page.height == 0) && (geometry.y > 0))
2270 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2302MagickExport MagickBooleanType ResetImagePixels(Image *image,
2303 ExceptionInfo *exception)
2320 assert(image != (Image *) NULL);
2321 assert(image->signature == MagickCoreSignature);
2322 if (IsEventLogging() != MagickFalse)
2323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2324 pixels=AcquirePixelCachePixels(image,&length,exception);
2325 if (pixels != (
void *) NULL)
2330 (void) memset((
void *) pixels,0,(
size_t) length);
2337 image_view=AcquireAuthenticCacheView(image,exception);
2338#if defined(MAGICKCORE_OPENMP_SUPPORT)
2339 #pragma omp parallel for schedule(static) shared(status) \
2340 magick_number_threads(image,image,image->rows,2)
2342 for (y=0; y < (ssize_t) image->rows; y++)
2345 *magick_restrict indexes;
2353 if (status == MagickFalse)
2355 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2356 if (q == (PixelPacket *) NULL)
2361 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2362 for (x=0; x < (ssize_t) image->columns; x++)
2364 (void) memset(q,0,
sizeof(PixelPacket));
2365 if ((image->storage_class == PseudoClass) ||
2366 (image->colorspace == CMYKColorspace))
2370 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2373 image_view=DestroyCacheView(image_view);
2401MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2424 assert(image != (Image *) NULL);
2425 assert(image->signature == MagickCoreSignature);
2426 if (IsEventLogging() != MagickFalse)
2427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2428 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2429 return(MagickFalse);
2430 if ((IsPixelGray(&image->background_color) == MagickFalse) &&
2431 (IsGrayColorspace(image->colorspace) != MagickFalse))
2432 (void) TransformImageColorspace(image,RGBColorspace);
2433 if ((image->background_color.opacity != OpaqueOpacity) &&
2434 (image->matte == MagickFalse))
2435 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
2436 GetMagickPixelPacket(image,&background);
2437 SetMagickPixelPacket(image,&image->background_color,(
const IndexPacket *)
2439 if (image->colorspace == CMYKColorspace)
2440 ConvertRGBToCMYK(&background);
2442 pixel.opacity=OpaqueOpacity;
2443 SetPixelPacket(image,&background,&pixel,&index);
2448 exception=(&image->exception);
2449 image_view=AcquireAuthenticCacheView(image,exception);
2450#if defined(MAGICKCORE_OPENMP_SUPPORT)
2451 #pragma omp parallel for schedule(static) shared(status) \
2452 magick_number_threads(image,image,image->rows,2)
2454 for (y=0; y < (ssize_t) image->rows; y++)
2462 if (status == MagickFalse)
2464 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2465 if (q == (PixelPacket *) NULL)
2470 for (x=0; x < (ssize_t) image->columns; x++)
2472 if (image->colorspace == CMYKColorspace)
2475 *magick_restrict indexes;
2477 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2478 for (x=0; x < (ssize_t) image->columns; x++)
2479 SetPixelIndex(indexes+x,index);
2481 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2484 image_view=DestroyCacheView(image_view);
2513MagickExport MagickBooleanType SetImageChannels(Image *image,
2514 const size_t channels)
2516 image->channels=channels;
2545MagickExport MagickBooleanType SetImageColor(Image *image,
2546 const MagickPixelPacket *color)
2560 assert(image != (Image *) NULL);
2561 assert(image->signature == MagickCoreSignature);
2562 assert(color != (
const MagickPixelPacket *) NULL);
2563 if (IsEventLogging() != MagickFalse)
2564 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2565 image->colorspace=color->colorspace;
2566 image->matte=color->matte;
2567 image->fuzz=color->fuzz;
2568 image->depth=color->depth;
2570 exception=(&image->exception);
2571 image_view=AcquireAuthenticCacheView(image,exception);
2572#if defined(MAGICKCORE_OPENMP_SUPPORT)
2573 #pragma omp parallel for schedule(static) shared(status) \
2574 magick_number_threads(image,image,image->rows,2)
2576 for (y=0; y < (ssize_t) image->rows; y++)
2579 *magick_restrict indexes;
2587 if (status == MagickFalse)
2589 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2590 if (q == (PixelPacket *) NULL)
2595 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2596 for (x=0; x < (ssize_t) image->columns; x++)
2598 SetPixelPacket(image,color,q,
2599 indexes == (IndexPacket *) NULL ? NULL : indexes+x);
2602 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2605 image_view=DestroyCacheView(image_view);
2635MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2636 const ClassType storage_class)
2638 assert(image != (Image *) NULL);
2639 assert(image->signature == MagickCoreSignature);
2640 if (IsEventLogging() != MagickFalse)
2641 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2642 image->storage_class=storage_class;
2643 return(SyncImagePixelCache(image,&image->exception));
2673MagickExport MagickBooleanType SetImageClipMask(Image *image,
2674 const Image *clip_mask)
2676 assert(image != (Image *) NULL);
2677 assert(image->signature == MagickCoreSignature);
2678 if (IsEventLogging() != MagickFalse)
2679 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2680 if (clip_mask != (
const Image *) NULL)
2681 if ((clip_mask->columns != image->columns) ||
2682 (clip_mask->rows != image->rows))
2683 ThrowBinaryImageException(ImageError,
"ImageSizeDiffers",image->filename);
2684 if (image->clip_mask != (Image *) NULL)
2685 image->clip_mask=DestroyImage(image->clip_mask);
2686 image->clip_mask=NewImageList();
2687 if (clip_mask == (Image *) NULL)
2689 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2690 return(MagickFalse);
2691 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2692 if (image->clip_mask == (Image *) NULL)
2693 return(MagickFalse);
2724MagickExport MagickBooleanType SetImageExtent(Image *image,
const size_t columns,
2727 if ((columns == 0) || (rows == 0))
2728 ThrowBinaryImageException(ImageError,
"NegativeOrZeroImageSize",
2730 image->columns=columns;
2732 if (image->depth == 0)
2735 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2736 ImageError,
"ImageDepthNotSupported",
"`%s'",image->filename);
2738 if (image->depth > (8*
sizeof(MagickSizeType)))
2740 image->depth=8*
sizeof(MagickSizeType);
2741 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2742 ImageError,
"ImageDepthNotSupported",
"`%s'",image->filename);
2744 return(SyncImagePixelCache(image,&image->exception));
2781MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2782 const unsigned int frames,ExceptionInfo *exception)
2785 extension[MaxTextExtent],
2786 filename[MaxTextExtent],
2787 magic[MaxTextExtent],
2789 subimage[MaxTextExtent];
2813 magick[2*MaxTextExtent];
2818 assert(image_info != (ImageInfo *) NULL);
2819 assert(image_info->signature == MagickCoreSignature);
2820 if (IsEventLogging() != MagickFalse)
2821 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2822 image_info->filename);
2824 GetPathComponent(image_info->filename,SubimagePath,subimage);
2825 if (*subimage !=
'\0')
2830 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2832 if (IsGeometry(subimage) != MagickFalse)
2833 (void) CloneString(&image_info->extract,subimage);
2841 (void) CloneString(&image_info->scenes,subimage);
2842 image_info->scene=StringToUnsignedLong(image_info->scenes);
2843 image_info->number_scenes=image_info->scene;
2844 p=image_info->scenes;
2845 for (q=(
char *) image_info->scenes; *q !=
'\0'; p++)
2847 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2849 first=(size_t) strtol(p,&q,10);
2851 while (isspace((
int) ((
unsigned char) *q)) != 0)
2854 last=(size_t) strtol(q+1,&q,10);
2857 if (first < image_info->scene)
2858 image_info->scene=first;
2859 if (last > image_info->number_scenes)
2860 image_info->number_scenes=last;
2863 image_info->number_scenes-=image_info->scene-1;
2864 image_info->subimage=image_info->scene;
2865 image_info->subrange=image_info->number_scenes;
2869 if (*image_info->magick ==
'\0')
2870 GetPathComponent(image_info->filename,ExtensionPath,extension);
2871 if (*extension !=
'\0')
2874 path[MaxTextExtent];
2879 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2880 GetPathComponent(path,ExtensionPath,extension);
2882 image_info->affirm=MagickFalse;
2883 sans_exception=AcquireExceptionInfo();
2884 if ((*extension !=
'\0') && (IsGlob(extension) == MagickFalse))
2893 *format_type_formats[] =
2917 (void) CopyMagickString(magic,extension,MaxTextExtent);
2922 format_type=UndefinedFormatType;
2924 while ((format_type == UndefinedFormatType) &&
2925 (format_type_formats[i] != (
char *) NULL))
2927 if ((*magic == *format_type_formats[i]) &&
2928 (LocaleCompare(magic,format_type_formats[i]) == 0))
2929 format_type=ExplicitFormatType;
2932 magick_info=GetMagickInfo(magic,sans_exception);
2933 if ((magick_info != (
const MagickInfo *) NULL) &&
2934 (magick_info->format_type != UndefinedFormatType))
2935 format_type=magick_info->format_type;
2936 if (format_type == UndefinedFormatType)
2937 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2939 if (format_type == ExplicitFormatType)
2941 image_info->affirm=MagickTrue;
2942 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2944 if (LocaleCompare(magic,
"RGB") == 0)
2945 image_info->affirm=MagickFalse;
2951 GetPathComponent(image_info->filename,MagickPath,magic);
2954 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
2955 magick_info=GetMagickInfo(magic,sans_exception);
2956 if ((magick_info != (
const MagickInfo *) NULL) &&
2957 (magick_info->format_type == ExplicitFormatType))
2958 image_info->affirm=MagickTrue;
2960 GetPathComponent(image_info->filename,CanonicalPath,filename);
2962 GetPathComponent(image_info->filename,SubcanonicalPath,filename);
2963 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2974 magick_info=GetMagickInfo(magic,sans_exception);
2975 delegate_info=GetDelegateInfo(magic,
"*",sans_exception);
2976 if (delegate_info == (
const DelegateInfo *) NULL)
2977 delegate_info=GetDelegateInfo(
"*",magic,sans_exception);
2978 if (((magick_info != (
const MagickInfo *) NULL) ||
2979 (delegate_info != (
const DelegateInfo *) NULL)) &&
2980 (IsMagickConflict(magic) == MagickFalse))
2982 image_info->affirm=MagickTrue;
2983 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2984 GetPathComponent(image_info->filename,CanonicalPath,filename);
2985 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2988 sans_exception=DestroyExceptionInfo(sans_exception);
2989 if ((magick_info == (
const MagickInfo *) NULL) ||
2990 (GetMagickEndianSupport(magick_info) == MagickFalse))
2991 image_info->endian=UndefinedEndian;
2992 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2997 (void) InterpretImageFilename(image_info,(Image *) NULL,
2998 image_info->filename,(
int) image_info->scene,filename);
2999 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3000 (strchr(filename,
'%') == (
char *) NULL))
3001 image_info->adjoin=MagickFalse;
3003 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3008 magick_info=GetMagickInfo(magic,exception);
3009 if (magick_info != (
const MagickInfo *) NULL)
3010 if (GetMagickAdjoin(magick_info) == MagickFalse)
3011 image_info->adjoin=MagickFalse;
3013 if (image_info->affirm != MagickFalse)
3020 image=AcquireImage(image_info);
3021 (void) CopyMagickString(image->filename,image_info->filename,
3023 sans_exception=AcquireExceptionInfo();
3024 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3025 sans_exception=DestroyExceptionInfo(sans_exception);
3026 if (status == MagickFalse)
3028 image=DestroyImage(image);
3029 return(MagickFalse);
3031 if ((IsBlobSeekable(image) == MagickFalse) ||
3032 (IsBlobExempt(image) != MagickFalse))
3038 status=ImageToFile(image,filename,exception);
3039 if (CloseBlob(image) == MagickFalse)
3041 if (status == MagickFalse)
3043 (void) RelinquishUniqueFileResource(filename);
3044 image=DestroyImage(image);
3045 return(MagickFalse);
3047 SetImageInfoFile(image_info,(FILE *) NULL);
3048 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3049 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3050 if (status == MagickFalse)
3052 (void) RelinquishUniqueFileResource(filename);
3053 image=DestroyImage(image);
3054 return(MagickFalse);
3056 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3057 image_info->temporary=MagickTrue;
3059 (void) memset(magick,0,
sizeof(magick));
3060 count=ReadBlob(image,2*MaxTextExtent,magick);
3061 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3062 (void) CloseBlob(image);
3063 image=DestroyImage(image);
3067 sans_exception=AcquireExceptionInfo();
3068 magic_info=GetMagicInfo(magick,(
size_t) count,sans_exception);
3069 if ((magic_info != (
const MagicInfo *) NULL) &&
3070 (GetMagicName(magic_info) != (
char *) NULL))
3072 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3074 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3075 if ((magick_info == (
const MagickInfo *) NULL) ||
3076 (GetMagickEndianSupport(magick_info) == MagickFalse))
3077 image_info->endian=UndefinedEndian;
3078 sans_exception=DestroyExceptionInfo(sans_exception);
3081 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3082 if ((magick_info == (
const MagickInfo *) NULL) ||
3083 (GetMagickEndianSupport(magick_info) == MagickFalse))
3084 image_info->endian=UndefinedEndian;
3085 sans_exception=DestroyExceptionInfo(sans_exception);
3117MagickExport
void SetImageInfoBlob(ImageInfo *image_info,
const void *blob,
3118 const size_t length)
3120 assert(image_info != (ImageInfo *) NULL);
3121 assert(image_info->signature == MagickCoreSignature);
3122 if (IsEventLogging() != MagickFalse)
3123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3124 image_info->filename);
3125 image_info->blob=(
void *) blob;
3126 image_info->length=length;
3153MagickExport
void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3155 assert(image_info != (ImageInfo *) NULL);
3156 assert(image_info->signature == MagickCoreSignature);
3157 if (IsEventLogging() != MagickFalse)
3158 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3159 image_info->filename);
3160 image_info->file=file;
3188MagickExport MagickBooleanType SetImageMask(Image *image,
const Image *mask)
3190 assert(image != (Image *) NULL);
3191 assert(image->signature == MagickCoreSignature);
3192 if (IsEventLogging() != MagickFalse)
3193 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3194 if (mask != (
const Image *) NULL)
3195 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3196 ThrowBinaryImageException(ImageError,
"ImageSizeDiffers",image->filename);
3197 if (image->mask != (Image *) NULL)
3198 image->mask=DestroyImage(image->mask);
3199 image->mask=NewImageList();
3200 if (mask == (Image *) NULL)
3202 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3203 return(MagickFalse);
3204 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3205 if (image->mask == (Image *) NULL)
3206 return(MagickFalse);
3235MagickExport MagickBooleanType SetImageOpacity(Image *image,
3236 const Quantum opacity)
3250 assert(image != (Image *) NULL);
3251 assert(image->signature == MagickCoreSignature);
3252 if (IsEventLogging() != MagickFalse)
3253 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3254 image->matte=MagickTrue;
3256 exception=(&image->exception);
3257 image_view=AcquireAuthenticCacheView(image,exception);
3258#if defined(MAGICKCORE_OPENMP_SUPPORT)
3259 #pragma omp parallel for schedule(static) shared(status) \
3260 magick_number_threads(image,image,image->rows,2)
3262 for (y=0; y < (ssize_t) image->rows; y++)
3270 if (status == MagickFalse)
3272 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3273 if (q == (PixelPacket *) NULL)
3278 for (x=0; x < (ssize_t) image->columns; x++)
3280 SetPixelOpacity(q,opacity);
3283 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3286 image_view=DestroyCacheView(image_view);
3317MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(
const Image *image,
3318 const VirtualPixelMethod virtual_pixel_method)
3320 assert(image != (
const Image *) NULL);
3321 assert(image->signature == MagickCoreSignature);
3322 if (IsEventLogging() != MagickFalse)
3323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3324 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3362static ssize_t SmushXGap(
const Image *smush_image,
const Image *images,
3363 const ssize_t offset,ExceptionInfo *exception)
3390 if (images->previous == (Image *) NULL)
3393 SetGeometry(smush_image,&right_geometry);
3394 GravityAdjustGeometry(right_image->columns,right_image->rows,
3395 right_image->gravity,&right_geometry);
3396 left_image=images->previous;
3397 SetGeometry(smush_image,&left_geometry);
3398 GravityAdjustGeometry(left_image->columns,left_image->rows,
3399 left_image->gravity,&left_geometry);
3400 gap=right_image->columns;
3401 left_view=AcquireVirtualCacheView(left_image,exception);
3402 right_view=AcquireVirtualCacheView(right_image,exception);
3403 for (y=0; y < (ssize_t) smush_image->rows; y++)
3405 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3407 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3408 if ((p == (
const PixelPacket *) NULL) ||
3409 (GetPixelOpacity(p) != TransparentOpacity) ||
3410 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3413 i=(ssize_t) left_image->columns-x-1;
3414 for (x=0; x < (ssize_t) right_image->columns; x++)
3416 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3418 if ((p == (
const PixelPacket *) NULL) ||
3419 (GetPixelOpacity(p) != TransparentOpacity) ||
3420 ((x+i) >= (ssize_t) gap))
3423 if ((x+i) < (ssize_t) gap)
3426 right_view=DestroyCacheView(right_view);
3427 left_view=DestroyCacheView(left_view);
3428 if (y < (ssize_t) smush_image->rows)
3430 return((ssize_t) gap-offset);
3433static ssize_t SmushYGap(
const Image *smush_image,
const Image *images,
3434 const ssize_t offset,ExceptionInfo *exception)
3461 if (images->previous == (Image *) NULL)
3463 bottom_image=images;
3464 SetGeometry(smush_image,&bottom_geometry);
3465 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3466 bottom_image->gravity,&bottom_geometry);
3467 top_image=images->previous;
3468 SetGeometry(smush_image,&top_geometry);
3469 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3471 gap=bottom_image->rows;
3472 top_view=AcquireVirtualCacheView(top_image,exception);
3473 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3474 for (x=0; x < (ssize_t) smush_image->columns; x++)
3476 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3478 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3479 if ((p == (
const PixelPacket *) NULL) ||
3480 (GetPixelOpacity(p) != TransparentOpacity) ||
3481 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3484 i=(ssize_t) top_image->rows-y-1;
3485 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3487 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3489 if ((p == (
const PixelPacket *) NULL) ||
3490 (GetPixelOpacity(p) != TransparentOpacity) ||
3491 ((y+i) >= (ssize_t) gap))
3494 if ((y+i) < (ssize_t) gap)
3497 bottom_view=DestroyCacheView(bottom_view);
3498 top_view=DestroyCacheView(top_view);
3499 if (x < (ssize_t) smush_image->columns)
3501 return((ssize_t) gap-offset);
3504MagickExport Image *SmushImages(
const Image *images,
3505 const MagickBooleanType stack,
const ssize_t offset,ExceptionInfo *exception)
3507#define SmushImageTag "Smush/Image"
3544 assert(images != (Image *) NULL);
3545 assert(images->signature == MagickCoreSignature);
3546 assert(exception != (ExceptionInfo *) NULL);
3547 assert(exception->signature == MagickCoreSignature);
3548 if (IsEventLogging() != MagickFalse)
3549 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3553 width=image->columns;
3555 next=GetNextImageInList(image);
3556 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3558 if (next->matte != MagickFalse)
3561 if (stack != MagickFalse)
3563 if (next->columns > width)
3564 width=next->columns;
3566 if (next->previous != (Image *) NULL)
3567 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3570 width+=next->columns;
3571 if (next->previous != (Image *) NULL)
3572 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3573 if (next->rows > height)
3579 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3580 if (smush_image == (Image *) NULL)
3581 return((Image *) NULL);
3582 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
3584 InheritException(exception,&smush_image->exception);
3585 smush_image=DestroyImage(smush_image);
3586 return((Image *) NULL);
3588 smush_image->matte=matte;
3589 (void) SetImageBackgroundColor(smush_image);
3593 smush_view=AcquireVirtualCacheView(smush_image,exception);
3594 for (n=0; n < (MagickOffsetType) number_images; n++)
3596 SetGeometry(smush_image,&geometry);
3597 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3598 if (stack != MagickFalse)
3600 x_offset-=geometry.x;
3601 y_offset-=SmushYGap(smush_image,image,offset,exception);
3605 x_offset-=SmushXGap(smush_image,image,offset,exception);
3606 y_offset-=geometry.y;
3608 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
3609 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3610 if (proceed == MagickFalse)
3612 if (stack == MagickFalse)
3614 x_offset+=(ssize_t) image->columns;
3620 y_offset+=(ssize_t) image->rows;
3622 image=GetNextImageInList(image);
3624 if (stack == MagickFalse)
3625 smush_image->columns=(size_t) x_offset;
3627 smush_image->rows=(size_t) y_offset;
3628 smush_view=DestroyCacheView(smush_view);
3629 if (status == MagickFalse)
3630 smush_image=DestroyImage(smush_image);
3631 return(smush_image);
3656MagickExport MagickBooleanType StripImage(Image *image)
3661 assert(image != (Image *) NULL);
3662 if (IsEventLogging() != MagickFalse)
3663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3664 DestroyImageProfiles(image);
3665 (void) DeleteImageProperty(image,
"comment");
3666 (void) DeleteImageProperty(image,
"date:create");
3667 (void) DeleteImageProperty(image,
"date:modify");
3668 status=SetImageArtifact(image,
"png:exclude-chunk",
3669 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3697static inline IndexPacket PushColormapIndex(Image *image,
3698 const size_t index,MagickBooleanType *range_exception)
3700 if (index < image->colors)
3701 return((IndexPacket) index);
3702 *range_exception=MagickTrue;
3703 return((IndexPacket) 0);
3706MagickExport MagickBooleanType SyncImage(Image *image)
3722 assert(image != (Image *) NULL);
3723 assert(image->signature == MagickCoreSignature);
3724 if (IsEventLogging() != MagickFalse)
3725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
3726 if (image->ping != MagickFalse)
3728 if (image->storage_class != PseudoClass)
3729 return(MagickFalse);
3730 assert(image->colormap != (PixelPacket *) NULL);
3731 range_exception=MagickFalse;
3734 exception=(&image->exception);
3735 image_view=AcquireAuthenticCacheView(image,exception);
3736#if defined(MAGICKCORE_OPENMP_SUPPORT)
3737 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3738 magick_number_threads(image,image,image->rows,2)
3740 for (y=0; y < (ssize_t) image->rows; y++)
3746 *magick_restrict indexes;
3754 if (status == MagickFalse)
3756 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3757 if (q == (PixelPacket *) NULL)
3762 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3763 for (x=0; x < (ssize_t) image->columns; x++)
3765 index=PushColormapIndex(image,(
size_t) GetPixelIndex(indexes+x),
3767 if (image->matte == MagickFalse)
3768 SetPixelRgb(q,image->colormap+(ssize_t) index)
3770 SetPixelRGBO(q,image->colormap+(ssize_t) index);
3773 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3776 image_view=DestroyCacheView(image_view);
3778 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3779 (void) ThrowMagickException(&image->exception,GetMagickModule(),
3780 CorruptImageWarning,
"InvalidColormapIndex",
"`%s'",image->filename);
3812MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3818 assert(image_info != (
const ImageInfo *) NULL);
3819 assert(image_info->signature == MagickCoreSignature);
3820 assert(images != (Image *) NULL);
3821 assert(images->signature == MagickCoreSignature);
3822 if (IsEventLogging() != MagickFalse)
3823 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
3825 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3826 (
void) SyncImageSettings(image_info,image);
3827 (void) DeleteImageOption(image_info,
"page");
3831MagickExport MagickBooleanType SyncImageSettings(
const ImageInfo *image_info,
3835 property[MaxTextExtent];
3853 assert(image_info != (
const ImageInfo *) NULL);
3854 assert(image_info->signature == MagickCoreSignature);
3855 assert(image != (Image *) NULL);
3856 assert(image->signature == MagickCoreSignature);
3857 if (IsEventLogging() != MagickFalse)
3858 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3859 option=GetImageOption(image_info,
"background");
3860 if (option != (
const char *) NULL)
3861 (void) QueryColorDatabase(option,&image->background_color,
3863 option=GetImageOption(image_info,
"bias");
3864 if (option != (
const char *) NULL)
3865 image->bias=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
3866 option=GetImageOption(image_info,
"black-point-compensation");
3867 if (option != (
const char *) NULL)
3868 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3869 MagickBooleanOptions,MagickFalse,option);
3870 option=GetImageOption(image_info,
"blue-primary");
3871 if (option != (
const char *) NULL)
3873 flags=ParseGeometry(option,&geometry_info);
3874 if ((flags & RhoValue) != 0)
3875 image->chromaticity.blue_primary.x=geometry_info.rho;
3876 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3877 if ((flags & SigmaValue) != 0)
3878 image->chromaticity.blue_primary.y=geometry_info.sigma;
3880 option=GetImageOption(image_info,
"bordercolor");
3881 if (option != (
const char *) NULL)
3882 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
3883 option=GetImageOption(image_info,
"colors");
3884 if (option != (
const char *) NULL)
3885 image->colors=StringToUnsignedLong(option);
3886 option=GetImageOption(image_info,
"compose");
3887 if (option != (
const char *) NULL)
3888 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3889 MagickFalse,option);
3890 option=GetImageOption(image_info,
"compress");
3891 if (option != (
const char *) NULL)
3892 image->compression=(CompressionType) ParseCommandOption(
3893 MagickCompressOptions,MagickFalse,option);
3894 option=GetImageOption(image_info,
"debug");
3895 if (option != (
const char *) NULL)
3896 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3897 MagickFalse,option);
3898 option=GetImageOption(image_info,
"density");
3899 if (option != (
const char *) NULL)
3907 flags=ParseGeometry(option,&geometry_info);
3908 if ((flags & RhoValue) != 0)
3909 image->x_resolution=geometry_info.rho;
3910 image->y_resolution=image->x_resolution;
3911 if ((flags & SigmaValue) != 0)
3912 image->y_resolution=geometry_info.sigma;
3914 option=GetImageOption(image_info,
"depth");
3915 if (option != (
const char *) NULL)
3916 image->depth=StringToUnsignedLong(option);
3917 option=GetImageOption(image_info,
"endian");
3918 if (option != (
const char *) NULL)
3919 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3920 MagickFalse,option);
3921 option=GetImageOption(image_info,
"filter");
3922 if (option != (
const char *) NULL)
3923 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3924 MagickFalse,option);
3925 option=GetImageOption(image_info,
"fuzz");
3926 if (option != (
const char *) NULL)
3927 image->fuzz=StringToDoubleInterval(option,(
double) QuantumRange+1.0);
3928 option=GetImageOption(image_info,
"gravity");
3929 if (option != (
const char *) NULL)
3930 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3931 MagickFalse,option);
3932 option=GetImageOption(image_info,
"green-primary");
3933 if (option != (
const char *) NULL)
3935 flags=ParseGeometry(option,&geometry_info);
3936 if ((flags & RhoValue) != 0)
3937 image->chromaticity.green_primary.x=geometry_info.rho;
3938 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3939 if ((flags & SigmaValue) != 0)
3940 image->chromaticity.green_primary.y=geometry_info.sigma;
3942 option=GetImageOption(image_info,
"intensity");
3943 if (option != (
const char *) NULL)
3944 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3945 MagickPixelIntensityOptions,MagickFalse,option);
3946 option=GetImageOption(image_info,
"intent");
3947 if (option != (
const char *) NULL)
3948 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3949 MagickIntentOptions,MagickFalse,option);
3950 option=GetImageOption(image_info,
"interlace");
3951 if (option != (
const char *) NULL)
3952 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3953 MagickFalse,option);
3954 option=GetImageOption(image_info,
"interpolate");
3955 if (option != (
const char *) NULL)
3956 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
3957 MagickInterpolateOptions,MagickFalse,option);
3958 option=GetImageOption(image_info,
"loop");
3959 if (option != (
const char *) NULL)
3960 image->iterations=StringToUnsignedLong(option);
3961 option=GetImageOption(image_info,
"mattecolor");
3962 if (option != (
const char *) NULL)
3963 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
3964 option=GetImageOption(image_info,
"orient");
3965 if (option != (
const char *) NULL)
3966 image->orientation=(OrientationType) ParseCommandOption(
3967 MagickOrientationOptions,MagickFalse,option);
3968 option=GetImageOption(image_info,
"page");
3969 if (option != (
const char *) NULL)
3974 geometry=GetPageGeometry(option);
3975 flags=ParseAbsoluteGeometry(geometry,&image->page);
3976 geometry=DestroyString(geometry);
3978 option=GetImageOption(image_info,
"quality");
3979 if (option != (
const char *) NULL)
3980 image->quality=StringToUnsignedLong(option);
3981 option=GetImageOption(image_info,
"red-primary");
3982 if (option != (
const char *) NULL)
3984 flags=ParseGeometry(option,&geometry_info);
3985 if ((flags & RhoValue) != 0)
3986 image->chromaticity.red_primary.x=geometry_info.rho;
3987 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3988 if ((flags & SigmaValue) != 0)
3989 image->chromaticity.red_primary.y=geometry_info.sigma;
3991 if (image_info->quality != UndefinedCompressionQuality)
3992 image->quality=image_info->quality;
3993 option=GetImageOption(image_info,
"scene");
3994 if (option != (
const char *) NULL)
3995 image->scene=StringToUnsignedLong(option);
3996 option=GetImageOption(image_info,
"taint");
3997 if (option != (
const char *) NULL)
3998 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3999 MagickFalse,option);
4000 option=GetImageOption(image_info,
"tile-offset");
4001 if (option != (
const char *) NULL)
4006 geometry=GetPageGeometry(option);
4007 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4008 geometry=DestroyString(geometry);
4010 option=GetImageOption(image_info,
"transparent-color");
4011 if (option != (
const char *) NULL)
4012 (void) QueryColorDatabase(option,&image->transparent_color,
4014 option=GetImageOption(image_info,
"type");
4015 if (option != (
const char *) NULL)
4016 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4018 option=GetImageOption(image_info,
"units");
4019 units=image_info->units;
4020 if (option != (
const char *) NULL)
4021 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4022 MagickFalse,option);
4023 if (units != UndefinedResolution)
4025 if (image->units != units)
4026 switch (image->units)
4028 case PixelsPerInchResolution:
4030 if (units == PixelsPerCentimeterResolution)
4032 image->x_resolution/=2.54;
4033 image->y_resolution/=2.54;
4037 case PixelsPerCentimeterResolution:
4039 if (units == PixelsPerInchResolution)
4041 image->x_resolution=(double) ((
size_t) (100.0*2.54*
4042 image->x_resolution+0.5))/100.0;
4043 image->y_resolution=(double) ((
size_t) (100.0*2.54*
4044 image->y_resolution+0.5))/100.0;
4052 option=GetImageOption(image_info,
"density");
4053 if (option != (
const char *) NULL)
4055 flags=ParseGeometry(option,&geometry_info);
4056 if ((flags & RhoValue) != 0)
4057 image->x_resolution=geometry_info.rho;
4058 image->y_resolution=image->x_resolution;
4059 if ((flags & SigmaValue) != 0)
4060 image->y_resolution=geometry_info.sigma;
4063 option=GetImageOption(image_info,
"white-point");
4064 if (option != (
const char *) NULL)
4066 flags=ParseGeometry(option,&geometry_info);
4067 if ((flags & RhoValue) != 0)
4068 image->chromaticity.white_point.x=geometry_info.rho;
4069 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4070 if ((flags & SigmaValue) != 0)
4071 image->chromaticity.white_point.y=geometry_info.sigma;
4073 ResetImageOptionIterator(image_info);
4074 for (option=GetNextImageOption(image_info); option != (
const char *) NULL; )
4076 value=GetImageOption(image_info,option);
4077 if (value != (
const char *) NULL)
4079 (void) FormatLocaleString(property,MaxTextExtent,
"%s",option);
4080 (void) SetImageArtifact(image,property,value);
4082 option=GetNextImageOption(image_info);