42#include "magick/studio.h"
43#include "magick/attribute.h"
44#include "magick/blob.h"
45#include "magick/blob-private.h"
46#include "magick/exception.h"
47#include "magick/exception-private.h"
48#include "magick/cache.h"
49#include "magick/client.h"
50#include "magick/coder.h"
51#include "magick/colorspace-private.h"
52#include "magick/constitute.h"
53#include "magick/delegate.h"
54#include "magick/geometry.h"
55#include "magick/identify.h"
56#include "magick/image-private.h"
57#include "magick/list.h"
58#include "magick/magick.h"
59#include "magick/memory_.h"
60#include "magick/monitor.h"
61#include "magick/monitor-private.h"
62#include "magick/option.h"
63#include "magick/pixel.h"
64#include "magick/policy.h"
65#include "magick/profile.h"
66#include "magick/property.h"
67#include "magick/quantum.h"
68#include "magick/resize.h"
69#include "magick/resource_.h"
70#include "magick/semaphore.h"
71#include "magick/statistic.h"
72#include "magick/stream.h"
73#include "magick/string_.h"
74#include "magick/string-private.h"
75#include "magick/timer.h"
76#include "magick/token.h"
77#include "magick/transform.h"
78#include "magick/utility.h"
83#define MaxReadRecursionDepth 100
134MagickExport
Image *ConstituteImage(
const size_t columns,
135 const size_t rows,
const char *map,
const StorageType storage,
153 assert(map != (
const char *) NULL);
154 assert(pixels != (
void *) NULL);
156 assert(exception->signature == MagickCoreSignature);
157 if (IsEventLogging() != MagickFalse)
158 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
160 if (image == (
Image *) NULL)
161 return((
Image *) NULL);
164 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
165 case DoublePixel: image->depth=8*
sizeof(double);
break;
166 case FloatPixel: image->depth=8*
sizeof(float);
break;
167 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
168 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
172 for (i=0; i < (ssize_t) length; i++)
181 image->matte=MagickTrue;
193 image->colorspace=CMYKColorspace;
199 image->colorspace=GRAYColorspace;
205 image->colorspace=GRAYColorspace;
210 status=SetImageExtent(image,columns,rows);
211 if (status == MagickFalse)
213 InheritException(exception,&image->exception);
214 image=DestroyImage(image);
216 status=ResetImagePixels(image,exception);
217 if (status == MagickFalse)
219 InheritException(exception,&image->exception);
220 image=DestroyImage(image);
222 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels);
223 if (status == MagickFalse)
225 InheritException(exception,&image->exception);
226 image=DestroyImage(image);
260#if defined(__cplusplus) || defined(c_plusplus)
264static size_t PingStream(
const Image *magick_unused(image),
265 const void *magick_unused(pixels),
const size_t columns)
267 magick_unreferenced(image);
268 magick_unreferenced(pixels);
273#if defined(__cplusplus) || defined(c_plusplus)
286 assert(image_info != (
ImageInfo *) NULL);
287 assert(image_info->signature == MagickCoreSignature);
289 if (IsEventLogging() != MagickFalse)
290 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
291 image_info->filename);
292 ping_info=CloneImageInfo(image_info);
293 ping_info->ping=MagickTrue;
294 image=ReadStream(ping_info,&PingStream,exception);
295 if (image != (
Image *) NULL)
297 ResetTimer(&image->timer);
298 if (ping_info->verbose != MagickFalse)
299 (void) IdentifyImage(image,stdout,MagickFalse);
301 ping_info=DestroyImageInfo(ping_info);
333 filename[MaxTextExtent];
345 assert(image_info != (
ImageInfo *) NULL);
346 assert(image_info->signature == MagickCoreSignature);
348 if (IsEventLogging() != MagickFalse)
349 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
350 image_info->filename);
351 (void) InterpretImageFilename(image_info,(
Image *) NULL,image_info->filename,
352 (
int) image_info->scene,filename);
353 if (LocaleCompare(filename,image_info->filename) != 0)
365 read_info=CloneImageInfo(image_info);
366 sans=AcquireExceptionInfo();
367 (void) SetImageInfo(read_info,0,sans);
368 sans=DestroyExceptionInfo(sans);
369 if (read_info->number_scenes == 0)
371 read_info=DestroyImageInfo(read_info);
372 return(PingImage(image_info,exception));
374 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
375 images=NewImageList();
376 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
377 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
379 (void) InterpretImageFilename(image_info,(
Image *) NULL,filename,(
int)
380 scene,read_info->filename);
381 image=PingImage(read_info,exception);
382 if (image == (
Image *) NULL)
384 AppendImageToList(&images,image);
386 read_info=DestroyImageInfo(read_info);
389 return(PingImage(image_info,exception));
421static MagickBooleanType IsCoderAuthorized(
const char *coder,
424 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
427 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
428 "NotAuthorized",
"`%s'",coder);
438 filename[MaxTextExtent],
439 magick[MaxTextExtent],
440 magick_filename[MaxTextExtent];
474 assert(image_info != (
ImageInfo *) NULL);
475 assert(image_info->signature == MagickCoreSignature);
476 assert(image_info->filename != (
char *) NULL);
478 if (IsEventLogging() != MagickFalse)
479 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
480 image_info->filename);
481 read_info=CloneImageInfo(image_info);
482 (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
483 (void) SetImageInfo(read_info,0,exception);
484 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
485 (void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
489 sans_exception=AcquireExceptionInfo();
490 magick_info=GetMagickInfo(read_info->magick,sans_exception);
491 if (sans_exception->severity == PolicyError)
492 magick_info=GetMagickInfo(read_info->magick,exception);
493 sans_exception=DestroyExceptionInfo(sans_exception);
494 if ((magick_info != (
const MagickInfo *) NULL) &&
495 (GetMagickRawSupport(magick_info) != MagickFalse))
497 if (GetMagickEndianSupport(magick_info) == MagickFalse)
498 read_info->endian=UndefinedEndian;
500 if (image_info->endian == UndefinedEndian)
506 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
510 if ((magick_info != (
const MagickInfo *) NULL) &&
511 (GetMagickSeekableStream(magick_info) != MagickFalse))
516 image=AcquireImage(read_info);
517 (void) CopyMagickString(image->filename,read_info->filename,
519 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
520 if (status == MagickFalse)
522 read_info=DestroyImageInfo(read_info);
523 image=DestroyImage(image);
524 return((
Image *) NULL);
526 if (IsBlobSeekable(image) == MagickFalse)
531 *read_info->filename=
'\0';
532 status=ImageToFile(image,read_info->filename,exception);
533 if (status == MagickFalse)
535 (void) CloseBlob(image);
536 read_info=DestroyImageInfo(read_info);
537 image=DestroyImage(image);
538 return((
Image *) NULL);
540 read_info->temporary=MagickTrue;
542 (void) CloseBlob(image);
543 image=DestroyImage(image);
545 image=NewImageList();
546 if ((magick_info == (
const MagickInfo *) NULL) ||
547 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
549 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
552 (void) SetImageInfo(read_info,0,exception);
553 (void) CopyMagickString(read_info->filename,filename,MaxTextExtent);
554 magick_info=GetMagickInfo(read_info->magick,exception);
557 if ((magick_info != (
const MagickInfo *) NULL) &&
558 (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL))
563 thread_support=GetMagickThreadSupport(magick_info);
564 if ((thread_support & DecoderThreadSupport) == 0)
565 LockSemaphoreInfo(magick_info->semaphore);
566 status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
567 image=(
Image *) NULL;
568 if (status != MagickFalse)
569 image=GetImageDecoder(magick_info)(read_info,exception);
570 if ((thread_support & DecoderThreadSupport) == 0)
571 UnlockSemaphoreInfo(magick_info->semaphore);
578 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
581 (void) ThrowMagickException(exception,GetMagickModule(),
582 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
584 if (read_info->temporary != MagickFalse)
585 (void) RelinquishUniqueFileResource(read_info->filename);
586 read_info=DestroyImageInfo(read_info);
587 return((
Image *) NULL);
592 image=AcquireImage(read_info);
593 if (image == (
Image *) NULL)
595 read_info=DestroyImageInfo(read_info);
596 return((
Image *) NULL);
598 (void) CopyMagickString(image->filename,read_info->filename,
600 *read_info->filename=
'\0';
601 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
602 LockSemaphoreInfo(delegate_info->semaphore);
603 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
605 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
606 UnlockSemaphoreInfo(delegate_info->semaphore);
607 image=DestroyImageList(image);
608 read_info->temporary=MagickTrue;
609 if (status != MagickFalse)
610 (void) SetImageInfo(read_info,0,exception);
611 magick_info=GetMagickInfo(read_info->magick,exception);
612 if ((magick_info == (
const MagickInfo *) NULL) ||
613 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
615 if (IsPathAccessible(read_info->filename) != MagickFalse)
616 (void) ThrowMagickException(exception,GetMagickModule(),
617 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
620 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
621 read_info->filename);
622 read_info=DestroyImageInfo(read_info);
623 return((
Image *) NULL);
628 thread_support=GetMagickThreadSupport(magick_info);
629 if ((thread_support & DecoderThreadSupport) == 0)
630 LockSemaphoreInfo(magick_info->semaphore);
631 status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
632 image=(
Image *) NULL;
633 if (status != MagickFalse)
634 image=(
Image *) (GetImageDecoder(magick_info))(read_info,exception);
635 if ((thread_support & DecoderThreadSupport) == 0)
636 UnlockSemaphoreInfo(magick_info->semaphore);
638 if (read_info->temporary != MagickFalse)
640 (void) RelinquishUniqueFileResource(read_info->filename);
641 read_info->temporary=MagickFalse;
642 if (image != (
Image *) NULL)
643 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
645 if (image == (
Image *) NULL)
647 read_info=DestroyImageInfo(read_info);
650 if (exception->severity >= ErrorException)
651 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
652 "Coder (%s) generated an image despite an error (%d), "
653 "notify the developers",image->magick,exception->severity);
654 if (IsBlobTemporary(image) != MagickFalse)
655 (void) RelinquishUniqueFileResource(read_info->filename);
656 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
657 (GetImageListLength(image) != 1))
662 clones=CloneImages(image,read_info->scenes,exception);
663 image=DestroyImageList(image);
664 if (clones != (
Image *) NULL)
665 image=GetFirstImageInList(clones);
666 if (image == (
Image *) NULL)
668 read_info=DestroyImageInfo(read_info);
672 for (next=image; next != (
Image *) NULL; next=GetNextImageInList(next))
675 magick_path[MaxTextExtent],
677 timestamp[MaxTextExtent];
689 *source_date_epoch = (
const char *) NULL;
691 static MagickBooleanType
692 epoch_initialized = MagickFalse;
694 next->taint=MagickFalse;
695 GetPathComponent(magick_filename,MagickPath,magick_path);
696 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
697 (void) CopyMagickString(next->magick,magick,MaxTextExtent);
698 (void) CopyMagickString(next->magick_filename,magick_filename,
700 if (IsBlobTemporary(image) != MagickFalse)
701 (void) CopyMagickString(next->filename,filename,MaxTextExtent);
702 if (next->magick_columns == 0)
703 next->magick_columns=next->columns;
704 if (next->magick_rows == 0)
705 next->magick_rows=next->rows;
706 (void) GetImageProperty(next,
"exif:*");
707 (void) GetImageProperty(next,
"icc:*");
708 (void) GetImageProperty(next,
"iptc:*");
709 (void) GetImageProperty(next,
"xmp:*");
710 value=GetImageProperty(next,
"exif:Orientation");
711 if (value == (
char *) NULL)
712 value=GetImageProperty(next,
"tiff:Orientation");
713 if (value != (
char *) NULL)
715 next->orientation=(OrientationType) StringToLong(value);
716 (void) DeleteImageProperty(next,
"tiff:Orientation");
717 (void) DeleteImageProperty(next,
"exif:Orientation");
719 value=GetImageProperty(next,
"exif:XResolution");
720 if (value != (
char *) NULL)
722 geometry_info.rho=next->x_resolution;
723 geometry_info.sigma=1.0;
724 (void) ParseGeometry(value,&geometry_info);
725 if (geometry_info.sigma != 0)
726 next->x_resolution=geometry_info.rho/geometry_info.sigma;
727 if (strchr(value,
',') != (
char *) NULL)
728 next->x_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
729 (void) DeleteImageProperty(next,
"exif:XResolution");
731 value=GetImageProperty(next,
"exif:YResolution");
732 if (value != (
char *) NULL)
734 geometry_info.rho=next->y_resolution;
735 geometry_info.sigma=1.0;
736 (void) ParseGeometry(value,&geometry_info);
737 if (geometry_info.sigma != 0)
738 next->y_resolution=geometry_info.rho/geometry_info.sigma;
739 if (strchr(value,
',') != (
char *) NULL)
740 next->y_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
741 (void) DeleteImageProperty(next,
"exif:YResolution");
743 value=GetImageProperty(next,
"exif:ResolutionUnit");
744 if (value == (
char *) NULL)
745 value=GetImageProperty(next,
"tiff:ResolutionUnit");
746 if (value != (
char *) NULL)
748 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
750 if (option_type >= 0)
751 next->units=(ResolutionType) option_type;
752 (void) DeleteImageProperty(next,
"exif:ResolutionUnit");
753 (void) DeleteImageProperty(next,
"tiff:ResolutionUnit");
755 if (next->page.width == 0)
756 next->page.width=next->columns;
757 if (next->page.height == 0)
758 next->page.height=next->rows;
759 option=GetImageOption(read_info,
"caption");
760 if (option != (
const char *) NULL)
762 property=InterpretImageProperties(read_info,next,option);
763 (void) SetImageProperty(next,
"caption",property);
764 property=DestroyString(property);
766 option=GetImageOption(read_info,
"comment");
767 if (option != (
const char *) NULL)
769 property=InterpretImageProperties(read_info,next,option);
770 (void) SetImageProperty(next,
"comment",property);
771 property=DestroyString(property);
773 option=GetImageOption(read_info,
"label");
774 if (option != (
const char *) NULL)
776 property=InterpretImageProperties(read_info,next,option);
777 (void) SetImageProperty(next,
"label",property);
778 property=DestroyString(property);
780 if (LocaleCompare(next->magick,
"TEXT") == 0)
781 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
782 if ((read_info->extract != (
char *) NULL) &&
783 (read_info->stream == (StreamHandler) NULL))
788 SetGeometry(next,&geometry);
789 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
790 if ((next->columns != geometry.width) ||
791 (next->rows != geometry.height))
793 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
798 crop_image=CropImage(next,&geometry,exception);
799 if (crop_image != (
Image *) NULL)
800 ReplaceImageInList(&next,crop_image);
803 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
805 (void) ParseRegionGeometry(next,read_info->extract,&geometry,
807 if ((geometry.width != 0) && (geometry.height != 0))
809 Image *resize_image=ResizeImage(next,geometry.width,
810 geometry.height,next->filter,next->blur,exception);
811 if (resize_image != (
Image *) NULL)
812 ReplaceImageInList(&next,resize_image);
817 profile=GetImageProfile(next,
"icc");
819 profile=GetImageProfile(next,
"icm");
822 next->color_profile.length=GetStringInfoLength(profile);
823 next->color_profile.info=GetStringInfoDatum(profile);
825 profile=GetImageProfile(next,
"iptc");
827 profile=GetImageProfile(next,
"8bim");
830 next->iptc_profile.length=GetStringInfoLength(profile);
831 next->iptc_profile.info=GetStringInfoDatum(profile);
833 if (epoch_initialized == MagickFalse)
835 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
836 epoch_initialized=MagickTrue;
838 if (source_date_epoch == (
const char *) NULL)
840 (void) FormatMagickTime(image->timestamp,MaxTextExtent,timestamp);
841 (void) SetImageProperty(next,
"date:timestamp",timestamp);
842 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
843 MaxTextExtent,timestamp);
844 (void) SetImageProperty(next,
"date:modify",timestamp);
845 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
846 MaxTextExtent,timestamp);
847 (void) SetImageProperty(next,
"date:create",timestamp);
849 option=GetImageOption(image_info,
"delay");
850 if (option != (
const char *) NULL)
855 flags=ParseGeometry(option,&geometry_info);
856 if ((flags & GreaterValue) != 0)
858 if (next->delay > (
size_t) floor(geometry_info.rho+0.5))
859 next->delay=(size_t) floor(geometry_info.rho+0.5);
862 if ((flags & LessValue) != 0)
864 if (next->delay < (
size_t) floor(geometry_info.rho+0.5))
865 next->delay=(size_t) floor(geometry_info.rho+0.5);
868 next->delay=(size_t) floor(geometry_info.rho+0.5);
869 if ((flags & SigmaValue) != 0)
870 next->ticks_per_second=CastDoubleToLong(floor(
871 geometry_info.sigma+0.5));
873 option=GetImageOption(image_info,
"dispose");
874 if (option != (
const char *) NULL)
876 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
878 if (option_type >= 0)
879 next->dispose=(DisposeType) option_type;
881 if (read_info->verbose != MagickFalse)
882 (void) IdentifyImage(next,stderr,MagickFalse);
885 read_info=DestroyImageInfo(read_info);
886 if (GetBlobError(image) != MagickFalse)
887 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
888 return(GetFirstImageInList(image));
919 filename[MaxTextExtent];
931 assert(image_info != (
ImageInfo *) NULL);
932 assert(image_info->signature == MagickCoreSignature);
934 if (IsEventLogging() != MagickFalse)
935 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
936 image_info->filename);
937 read_info=CloneImageInfo(image_info);
938 *read_info->magick=
'\0';
939 (void) InterpretImageFilename(read_info,(
Image *) NULL,read_info->filename,
940 (
int) read_info->scene,filename);
941 if (LocaleCompare(filename,read_info->filename) != 0)
953 sans=AcquireExceptionInfo();
954 (void) SetImageInfo(read_info,0,sans);
955 sans=DestroyExceptionInfo(sans);
956 if (read_info->number_scenes == 0)
958 read_info=DestroyImageInfo(read_info);
959 return(ReadImage(image_info,exception));
961 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
962 images=NewImageList();
963 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
964 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
966 (void) InterpretImageFilename(image_info,(
Image *) NULL,filename,(
int)
967 scene,read_info->filename);
968 image=ReadImage(read_info,exception);
969 if (image == (
Image *) NULL)
971 AppendImageToList(&images,image);
973 read_info=DestroyImageInfo(read_info);
976 image=ReadImage(read_info,exception);
977 read_info=DestroyImageInfo(read_info);
1032 image=NewImageList();
1033 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1035 ThrowReaderException(CorruptImageError,
"CorruptImage");
1036 blob=Base64Decode(++p,&length);
1039 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1040 ThrowReaderException(CorruptImageError,
"CorruptImage");
1042 read_info=CloneImageInfo(image_info);
1043 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1045 *read_info->filename=
'\0';
1046 *read_info->magick=
'\0';
1047 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1059 if (LocaleNCompare(++p,
"x-",2) == 0)
1061 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1062 q=read_info->filename+5;
1063 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1067 image=BlobToImage(read_info,blob,length,exception);
1068 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1069 read_info=DestroyImageInfo(read_info);
1101MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1105 filename[MaxTextExtent];
1133 assert(image_info != (
ImageInfo *) NULL);
1134 assert(image_info->signature == MagickCoreSignature);
1135 assert(image != (
Image *) NULL);
1136 assert(image->signature == MagickCoreSignature);
1137 if (IsEventLogging() != MagickFalse)
1138 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1139 image_info->filename);
1140 exception=(&image->exception);
1141 sans_exception=AcquireExceptionInfo();
1142 write_info=CloneImageInfo(image_info);
1143 (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
1144 (void) SetImageInfo(write_info,1,sans_exception);
1145 if (*write_info->magick ==
'\0')
1146 (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
1147 if (LocaleCompare(write_info->magick,
"clipmask") == 0)
1149 if (image->clip_mask == (
Image *) NULL)
1151 (void) ThrowMagickException(exception,GetMagickModule(),
1152 OptionError,
"NoClipPathDefined",
"`%s'",image->filename);
1153 write_info=DestroyImageInfo(write_info);
1154 return(MagickFalse);
1156 image=image->clip_mask;
1157 (void) SetImageInfo(write_info,1,sans_exception);
1159 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1160 (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
1164 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1165 if (sans_exception->severity == PolicyError)
1166 magick_info=GetMagickInfo(write_info->magick,exception);
1167 sans_exception=DestroyExceptionInfo(sans_exception);
1168 if (magick_info != (
const MagickInfo *) NULL)
1170 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1171 image->endian=UndefinedEndian;
1173 if ((image_info->endian == UndefinedEndian) &&
1174 (GetMagickRawSupport(magick_info) != MagickFalse))
1180 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1183 (void) SyncImageProfiles(image);
1184 DisassociateImageStream(image);
1185 option=GetImageOption(image_info,
"delegate:bimodal");
1186 if ((option != (
const char *) NULL) &&
1187 (IsMagickTrue(option) != MagickFalse) &&
1188 (write_info->page == (
char *) NULL) &&
1189 (GetPreviousImageInList(image) == (
Image *) NULL) &&
1190 (GetNextImageInList(image) == (
Image *) NULL) &&
1191 (IsTaintImage(image) == MagickFalse))
1193 delegate_info=GetDelegateInfo(image->magick,write_info->magick,
1196 (GetDelegateMode(delegate_info) == 0) &&
1197 (IsPathAccessible(image->magick_filename) != MagickFalse))
1202 (void) CopyMagickString(image->filename,image->magick_filename,
1204 status=InvokeDelegate(write_info,image,image->magick,
1205 write_info->magick,exception);
1206 write_info=DestroyImageInfo(write_info);
1207 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1212 temporary=MagickFalse;
1213 if ((magick_info != (
const MagickInfo *) NULL) &&
1214 (GetMagickSeekableStream(magick_info) != MagickFalse))
1217 filename[MaxTextExtent];
1219 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1220 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1221 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1222 if (status != MagickFalse)
1224 if (IsBlobSeekable(image) == MagickFalse)
1229 write_info->adjoin=MagickTrue;
1230 (void) CopyMagickString(write_info->filename,image->filename,
1232 (void) AcquireUniqueFilename(image->filename);
1233 temporary=MagickTrue;
1235 if (CloseBlob(image) == MagickFalse)
1239 if ((magick_info != (
const MagickInfo *) NULL) &&
1240 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1245 thread_support=GetMagickThreadSupport(magick_info);
1246 if ((thread_support & EncoderThreadSupport) == 0)
1247 LockSemaphoreInfo(magick_info->semaphore);
1248 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,exception);
1249 if (status != MagickFalse)
1250 status=GetImageEncoder(magick_info)(write_info,image);
1251 if ((thread_support & EncoderThreadSupport) == 0)
1252 UnlockSemaphoreInfo(magick_info->semaphore);
1256 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,
1263 *write_info->filename=
'\0';
1264 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1265 LockSemaphoreInfo(delegate_info->semaphore);
1266 status=InvokeDelegate(write_info,image,(
char *) NULL,
1267 write_info->magick,exception);
1268 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1269 UnlockSemaphoreInfo(delegate_info->semaphore);
1270 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1274 sans_exception=AcquireExceptionInfo();
1275 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1276 if (sans_exception->severity == PolicyError)
1277 magick_info=GetMagickInfo(write_info->magick,exception);
1278 sans_exception=DestroyExceptionInfo(sans_exception);
1279 if ((write_info->affirm == MagickFalse) &&
1282 (void) CopyMagickString(write_info->magick,image->magick,
1284 magick_info=GetMagickInfo(write_info->magick,exception);
1286 if ((magick_info == (
const MagickInfo *) NULL) ||
1287 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1290 extension[MaxTextExtent];
1292 GetPathComponent(image->filename,ExtensionPath,extension);
1293 if (*extension !=
'\0')
1294 magick_info=GetMagickInfo(extension,exception);
1296 magick_info=GetMagickInfo(image->magick,exception);
1297 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1299 if ((magick_info == (
const MagickInfo *) NULL) ||
1300 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1302 magick_info=GetMagickInfo(image->magick,exception);
1303 if ((magick_info == (
const MagickInfo *) NULL) ||
1304 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1305 (void) ThrowMagickException(exception,GetMagickModule(),
1306 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1307 "`%s'",write_info->magick);
1309 (
void) ThrowMagickException(exception,GetMagickModule(),
1310 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1311 "`%s'",write_info->magick);
1313 if ((magick_info != (
const MagickInfo *) NULL) &&
1314 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1319 thread_support=GetMagickThreadSupport(magick_info);
1320 if ((thread_support & EncoderThreadSupport) == 0)
1321 LockSemaphoreInfo(magick_info->semaphore);
1322 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,
1324 if (status != MagickFalse)
1325 status=GetImageEncoder(magick_info)(write_info,image);
1326 if ((thread_support & EncoderThreadSupport) == 0)
1327 UnlockSemaphoreInfo(magick_info->semaphore);
1331 if (temporary != MagickFalse)
1336 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1337 if (status != MagickFalse)
1339 (void) RelinquishUniqueFileResource(write_info->filename);
1340 status=ImageToFile(image,write_info->filename,exception);
1342 if (CloseBlob(image) == MagickFalse)
1344 (void) RelinquishUniqueFileResource(image->filename);
1345 (void) CopyMagickString(image->filename,write_info->filename,
1348 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1349 (write_info->verbose != MagickFalse))
1350 (void) IdentifyImage(image,stderr,MagickFalse);
1351 write_info=DestroyImageInfo(write_info);
1352 if (GetBlobError(image) != MagickFalse)
1353 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1393MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1396#define WriteImageTag "Write/Image"
1410 MagickProgressMonitor
1422 assert(image_info != (
const ImageInfo *) NULL);
1423 assert(image_info->signature == MagickCoreSignature);
1424 assert(images != (
Image *) NULL);
1425 assert(images->signature == MagickCoreSignature);
1427 if (IsEventLogging() != MagickFalse)
1428 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1429 write_info=CloneImageInfo(image_info);
1430 *write_info->magick=
'\0';
1431 images=GetFirstImageInList(images);
1432 if (images == (
Image *) NULL)
1433 return(MagickFalse);
1434 if (filename != (
const char *) NULL)
1435 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1436 (
void) CopyMagickString(p->filename,filename,MaxTextExtent);
1437 (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
1438 sans_exception=AcquireExceptionInfo();
1439 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1441 sans_exception=DestroyExceptionInfo(sans_exception);
1442 if (*write_info->magick ==
'\0')
1443 (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
1445 for ( ; GetNextImageInList(p) != (
Image *) NULL; p=GetNextImageInList(p))
1447 if (p->scene >= GetNextImageInList(p)->scene)
1455 i=(ssize_t) images->scene;
1456 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1457 p->scene=(
size_t) i++;
1465 progress_monitor=(MagickProgressMonitor) NULL;
1467 number_images=GetImageListLength(images);
1468 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1470 if (number_images != 1)
1471 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1473 status&=WriteImage(write_info,p);
1474 GetImageException(p,exception);
1475 if (number_images != 1)
1476 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1477 if (write_info->adjoin != MagickFalse)
1479 if (number_images != 1)
1481 proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
1482 if (proceed == MagickFalse)
1486 write_info=DestroyImageInfo(write_info);
1487 return(status != 0 ? MagickTrue : MagickFalse);