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
134 MagickExport
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)
264 static 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));
421 static 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 if (clones != (
Image *) NULL)
665 image=DestroyImageList(image);
666 image=GetFirstImageInList(clones);
669 for (next=image; next != (
Image *) NULL; next=GetNextImageInList(next))
672 magick_path[MaxTextExtent],
674 timestamp[MaxTextExtent];
686 *source_date_epoch = (
const char *) NULL;
688 static MagickBooleanType
689 epoch_initialized = MagickFalse;
691 next->taint=MagickFalse;
692 GetPathComponent(magick_filename,MagickPath,magick_path);
693 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
694 (void) CopyMagickString(next->magick,magick,MaxTextExtent);
695 (void) CopyMagickString(next->magick_filename,magick_filename,
697 if (IsBlobTemporary(image) != MagickFalse)
698 (
void) CopyMagickString(next->filename,filename,MaxTextExtent);
699 if (next->magick_columns == 0)
700 next->magick_columns=next->columns;
701 if (next->magick_rows == 0)
702 next->magick_rows=next->rows;
703 (void) GetImageProperty(next,
"exif:*");
704 (void) GetImageProperty(next,
"icc:*");
705 (void) GetImageProperty(next,
"iptc:*");
706 (void) GetImageProperty(next,
"xmp:*");
707 value=GetImageProperty(next,
"exif:Orientation");
708 if (value == (
char *) NULL)
709 value=GetImageProperty(next,
"tiff:Orientation");
710 if (value != (
char *) NULL)
712 next->orientation=(OrientationType) StringToLong(value);
713 (void) DeleteImageProperty(next,
"tiff:Orientation");
714 (void) DeleteImageProperty(next,
"exif:Orientation");
716 value=GetImageProperty(next,
"exif:XResolution");
717 if (value != (
char *) NULL)
719 geometry_info.rho=next->x_resolution;
720 geometry_info.sigma=1.0;
721 (void) ParseGeometry(value,&geometry_info);
722 if (geometry_info.sigma != 0)
723 next->x_resolution=geometry_info.rho/geometry_info.sigma;
724 if (strchr(value,
',') != (
char *) NULL)
725 next->x_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
726 (void) DeleteImageProperty(next,
"exif:XResolution");
728 value=GetImageProperty(next,
"exif:YResolution");
729 if (value != (
char *) NULL)
731 geometry_info.rho=next->y_resolution;
732 geometry_info.sigma=1.0;
733 (void) ParseGeometry(value,&geometry_info);
734 if (geometry_info.sigma != 0)
735 next->y_resolution=geometry_info.rho/geometry_info.sigma;
736 if (strchr(value,
',') != (
char *) NULL)
737 next->y_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
738 (void) DeleteImageProperty(next,
"exif:YResolution");
740 value=GetImageProperty(next,
"exif:ResolutionUnit");
741 if (value == (
char *) NULL)
742 value=GetImageProperty(next,
"tiff:ResolutionUnit");
743 if (value != (
char *) NULL)
745 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
747 if (option_type >= 0)
748 next->units=(ResolutionType) option_type;
749 (void) DeleteImageProperty(next,
"exif:ResolutionUnit");
750 (void) DeleteImageProperty(next,
"tiff:ResolutionUnit");
752 if (next->page.width == 0)
753 next->page.width=next->columns;
754 if (next->page.height == 0)
755 next->page.height=next->rows;
756 option=GetImageOption(read_info,
"caption");
757 if (option != (
const char *) NULL)
759 property=InterpretImageProperties(read_info,next,option);
760 (void) SetImageProperty(next,
"caption",property);
761 property=DestroyString(property);
763 option=GetImageOption(read_info,
"comment");
764 if (option != (
const char *) NULL)
766 property=InterpretImageProperties(read_info,next,option);
767 (void) SetImageProperty(next,
"comment",property);
768 property=DestroyString(property);
770 option=GetImageOption(read_info,
"label");
771 if (option != (
const char *) NULL)
773 property=InterpretImageProperties(read_info,next,option);
774 (void) SetImageProperty(next,
"label",property);
775 property=DestroyString(property);
777 if (LocaleCompare(next->magick,
"TEXT") == 0)
778 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
779 if ((read_info->extract != (
char *) NULL) &&
780 (read_info->stream == (StreamHandler) NULL))
785 SetGeometry(next,&geometry);
786 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
787 if ((next->columns != geometry.width) ||
788 (next->rows != geometry.height))
790 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
795 crop_image=CropImage(next,&geometry,exception);
796 if (crop_image != (
Image *) NULL)
797 ReplaceImageInList(&next,crop_image);
800 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
802 (void) ParseRegionGeometry(next,read_info->extract,&geometry,
804 if ((geometry.width != 0) && (geometry.height != 0))
806 Image *resize_image=ResizeImage(next,geometry.width,
807 geometry.height,next->filter,next->blur,exception);
808 if (resize_image != (
Image *) NULL)
809 ReplaceImageInList(&next,resize_image);
814 profile=GetImageProfile(next,
"icc");
816 profile=GetImageProfile(next,
"icm");
819 next->color_profile.length=GetStringInfoLength(profile);
820 next->color_profile.info=GetStringInfoDatum(profile);
822 profile=GetImageProfile(next,
"iptc");
824 profile=GetImageProfile(next,
"8bim");
827 next->iptc_profile.length=GetStringInfoLength(profile);
828 next->iptc_profile.info=GetStringInfoDatum(profile);
830 if (epoch_initialized == MagickFalse)
832 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
833 epoch_initialized=MagickTrue;
835 if (source_date_epoch == (
const char *) NULL)
837 (void) FormatMagickTime(image->timestamp,MaxTextExtent,timestamp);
838 (void) SetImageProperty(next,
"date:timestamp",timestamp);
839 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
840 MaxTextExtent,timestamp);
841 (void) SetImageProperty(next,
"date:modify",timestamp);
842 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
843 MaxTextExtent,timestamp);
844 (void) SetImageProperty(next,
"date:create",timestamp);
846 option=GetImageOption(image_info,
"delay");
847 if (option != (
const char *) NULL)
852 flags=ParseGeometry(option,&geometry_info);
853 if ((flags & GreaterValue) != 0)
855 if (next->delay > (
size_t) floor(geometry_info.rho+0.5))
856 next->delay=(size_t) floor(geometry_info.rho+0.5);
859 if ((flags & LessValue) != 0)
861 if (next->delay < (
size_t) floor(geometry_info.rho+0.5))
862 next->delay=(
size_t) floor(geometry_info.rho+0.5);
865 next->delay=(size_t) floor(geometry_info.rho+0.5);
866 if ((flags & SigmaValue) != 0)
867 next->ticks_per_second=CastDoubleToLong(floor(
868 geometry_info.sigma+0.5));
870 option=GetImageOption(image_info,
"dispose");
871 if (option != (
const char *) NULL)
873 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
875 if (option_type >= 0)
876 next->dispose=(DisposeType) option_type;
878 if (read_info->verbose != MagickFalse)
879 (void) IdentifyImage(next,stderr,MagickFalse);
882 read_info=DestroyImageInfo(read_info);
883 if (GetBlobError(image) != MagickFalse)
884 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
885 return(GetFirstImageInList(image));
916 filename[MaxTextExtent];
928 assert(image_info != (
ImageInfo *) NULL);
929 assert(image_info->signature == MagickCoreSignature);
931 if (IsEventLogging() != MagickFalse)
932 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
933 image_info->filename);
934 read_info=CloneImageInfo(image_info);
935 *read_info->magick=
'\0';
936 (void) InterpretImageFilename(read_info,(
Image *) NULL,read_info->filename,
937 (int) read_info->scene,filename);
938 if (LocaleCompare(filename,read_info->filename) != 0)
950 sans=AcquireExceptionInfo();
951 (void) SetImageInfo(read_info,0,sans);
952 sans=DestroyExceptionInfo(sans);
953 if (read_info->number_scenes == 0)
955 read_info=DestroyImageInfo(read_info);
956 return(ReadImage(image_info,exception));
958 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
959 images=NewImageList();
960 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
961 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
963 (void) InterpretImageFilename(image_info,(
Image *) NULL,filename,(int)
964 scene,read_info->filename);
965 image=ReadImage(read_info,exception);
966 if (image == (
Image *) NULL)
968 AppendImageToList(&images,image);
970 read_info=DestroyImageInfo(read_info);
973 image=ReadImage(read_info,exception);
974 read_info=DestroyImageInfo(read_info);
1029 image=NewImageList();
1030 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1032 ThrowReaderException(CorruptImageError,
"CorruptImage");
1033 blob=Base64Decode(++p,&length);
1036 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1037 ThrowReaderException(CorruptImageError,
"CorruptImage");
1039 read_info=CloneImageInfo(image_info);
1040 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1042 *read_info->filename=
'\0';
1043 *read_info->magick=
'\0';
1044 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1056 if (LocaleNCompare(++p,
"x-",2) == 0)
1058 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1059 q=read_info->filename+5;
1060 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1064 image=BlobToImage(read_info,blob,length,exception);
1065 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1066 read_info=DestroyImageInfo(read_info);
1098 MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1102 filename[MaxTextExtent];
1130 assert(image_info != (
ImageInfo *) NULL);
1131 assert(image_info->signature == MagickCoreSignature);
1132 assert(image != (
Image *) NULL);
1133 assert(image->signature == MagickCoreSignature);
1134 if (IsEventLogging() != MagickFalse)
1135 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1136 image_info->filename);
1137 exception=(&image->exception);
1138 sans_exception=AcquireExceptionInfo();
1139 write_info=CloneImageInfo(image_info);
1140 (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
1141 (void) SetImageInfo(write_info,1,sans_exception);
1142 if (*write_info->magick ==
'\0')
1143 (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
1144 if (LocaleCompare(write_info->magick,
"clipmask") == 0)
1146 if (image->clip_mask == (
Image *) NULL)
1148 (void) ThrowMagickException(exception,GetMagickModule(),
1149 OptionError,
"NoClipPathDefined",
"`%s'",image->filename);
1150 write_info=DestroyImageInfo(write_info);
1151 return(MagickFalse);
1153 image=image->clip_mask;
1154 (void) SetImageInfo(write_info,1,sans_exception);
1156 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1157 (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
1161 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1162 if (sans_exception->severity == PolicyError)
1163 magick_info=GetMagickInfo(write_info->magick,exception);
1164 sans_exception=DestroyExceptionInfo(sans_exception);
1165 if (magick_info != (
const MagickInfo *) NULL)
1167 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1168 image->endian=UndefinedEndian;
1170 if ((image_info->endian == UndefinedEndian) &&
1171 (GetMagickRawSupport(magick_info) != MagickFalse))
1177 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1180 (void) SyncImageProfiles(image);
1181 DisassociateImageStream(image);
1182 option=GetImageOption(image_info,
"delegate:bimodal");
1183 if ((option != (
const char *) NULL) &&
1184 (IsMagickTrue(option) != MagickFalse) &&
1185 (write_info->page == (
char *) NULL) &&
1186 (GetPreviousImageInList(image) == (
Image *) NULL) &&
1187 (GetNextImageInList(image) == (
Image *) NULL) &&
1188 (IsTaintImage(image) == MagickFalse))
1190 delegate_info=GetDelegateInfo(image->magick,write_info->magick,
1193 (GetDelegateMode(delegate_info) == 0) &&
1194 (IsPathAccessible(image->magick_filename) != MagickFalse))
1199 (void) CopyMagickString(image->filename,image->magick_filename,
1201 status=InvokeDelegate(write_info,image,image->magick,
1202 write_info->magick,exception);
1203 write_info=DestroyImageInfo(write_info);
1204 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1209 temporary=MagickFalse;
1210 if ((magick_info != (
const MagickInfo *) NULL) &&
1211 (GetMagickSeekableStream(magick_info) != MagickFalse))
1214 filename[MaxTextExtent];
1216 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1217 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1218 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1219 if (status != MagickFalse)
1221 if (IsBlobSeekable(image) == MagickFalse)
1226 write_info->adjoin=MagickTrue;
1227 (void) CopyMagickString(write_info->filename,image->filename,
1229 (void) AcquireUniqueFilename(image->filename);
1230 temporary=MagickTrue;
1232 if (CloseBlob(image) == MagickFalse)
1236 if ((magick_info != (
const MagickInfo *) NULL) &&
1237 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1242 thread_support=GetMagickThreadSupport(magick_info);
1243 if ((thread_support & EncoderThreadSupport) == 0)
1244 LockSemaphoreInfo(magick_info->semaphore);
1245 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,exception);
1246 if (status != MagickFalse)
1247 status=GetImageEncoder(magick_info)(write_info,image);
1248 if ((thread_support & EncoderThreadSupport) == 0)
1249 UnlockSemaphoreInfo(magick_info->semaphore);
1253 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,
1260 *write_info->filename=
'\0';
1261 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1262 LockSemaphoreInfo(delegate_info->semaphore);
1263 status=InvokeDelegate(write_info,image,(
char *) NULL,
1264 write_info->magick,exception);
1265 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1266 UnlockSemaphoreInfo(delegate_info->semaphore);
1267 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1271 sans_exception=AcquireExceptionInfo();
1272 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1273 if (sans_exception->severity == PolicyError)
1274 magick_info=GetMagickInfo(write_info->magick,exception);
1275 sans_exception=DestroyExceptionInfo(sans_exception);
1276 if ((write_info->affirm == MagickFalse) &&
1279 (void) CopyMagickString(write_info->magick,image->magick,
1281 magick_info=GetMagickInfo(write_info->magick,exception);
1283 if ((magick_info == (
const MagickInfo *) NULL) ||
1284 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1287 extension[MaxTextExtent];
1289 GetPathComponent(image->filename,ExtensionPath,extension);
1290 if (*extension !=
'\0')
1291 magick_info=GetMagickInfo(extension,exception);
1293 magick_info=GetMagickInfo(image->magick,exception);
1294 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1296 if ((magick_info == (
const MagickInfo *) NULL) ||
1297 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1299 magick_info=GetMagickInfo(image->magick,exception);
1300 if ((magick_info == (
const MagickInfo *) NULL) ||
1301 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1302 (void) ThrowMagickException(exception,GetMagickModule(),
1303 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1304 "`%s'",write_info->magick);
1306 (
void) ThrowMagickException(exception,GetMagickModule(),
1307 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1308 "`%s'",write_info->magick);
1310 if ((magick_info != (
const MagickInfo *) NULL) &&
1311 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1316 thread_support=GetMagickThreadSupport(magick_info);
1317 if ((thread_support & EncoderThreadSupport) == 0)
1318 LockSemaphoreInfo(magick_info->semaphore);
1319 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,
1321 if (status != MagickFalse)
1322 status=GetImageEncoder(magick_info)(write_info,image);
1323 if ((thread_support & EncoderThreadSupport) == 0)
1324 UnlockSemaphoreInfo(magick_info->semaphore);
1328 if (temporary != MagickFalse)
1333 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1334 if (status != MagickFalse)
1336 (void) RelinquishUniqueFileResource(write_info->filename);
1337 status=ImageToFile(image,write_info->filename,exception);
1339 if (CloseBlob(image) == MagickFalse)
1341 (void) RelinquishUniqueFileResource(image->filename);
1342 (void) CopyMagickString(image->filename,write_info->filename,
1345 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1346 (write_info->verbose != MagickFalse))
1347 (
void) IdentifyImage(image,stderr,MagickFalse);
1348 write_info=DestroyImageInfo(write_info);
1349 if (GetBlobError(image) != MagickFalse)
1350 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1390 MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1393 #define WriteImageTag "Write/Image"
1407 MagickProgressMonitor
1419 assert(image_info != (
const ImageInfo *) NULL);
1420 assert(image_info->signature == MagickCoreSignature);
1421 assert(images != (
Image *) NULL);
1422 assert(images->signature == MagickCoreSignature);
1424 if (IsEventLogging() != MagickFalse)
1425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1426 write_info=CloneImageInfo(image_info);
1427 *write_info->magick=
'\0';
1428 images=GetFirstImageInList(images);
1429 if (images == (
Image *) NULL)
1430 return(MagickFalse);
1431 if (filename != (
const char *) NULL)
1432 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1433 (
void) CopyMagickString(p->filename,filename,MaxTextExtent);
1434 (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
1435 sans_exception=AcquireExceptionInfo();
1436 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1438 sans_exception=DestroyExceptionInfo(sans_exception);
1439 if (*write_info->magick ==
'\0')
1440 (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
1442 for ( ; GetNextImageInList(p) != (
Image *) NULL; p=GetNextImageInList(p))
1447 next=GetNextImageInList(p);
1448 if (next == (
Image *) NULL)
1450 if (p->scene >= next->scene)
1458 i=(ssize_t) images->scene;
1459 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1460 p->scene=(
size_t) i++;
1468 progress_monitor=(MagickProgressMonitor) NULL;
1470 number_images=GetImageListLength(images);
1471 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1473 if (number_images != 1)
1474 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1476 status&=WriteImage(write_info,p);
1477 GetImageException(p,exception);
1478 if (number_images != 1)
1479 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1480 if (write_info->adjoin != MagickFalse)
1482 if (number_images != 1)
1484 proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
1485 if (proceed == MagickFalse)
1489 write_info=DestroyImageInfo(write_info);
1490 return(status != 0 ? MagickTrue : MagickFalse);