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"
129 MagickExport
Image *ConstituteImage(
const size_t columns,
130 const size_t rows,
const char *map,
const StorageType storage,
148 assert(map != (
const char *) NULL);
149 assert(pixels != (
void *) NULL);
151 assert(exception->signature == MagickCoreSignature);
152 if (IsEventLogging() != MagickFalse)
153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
155 if (image == (
Image *) NULL)
156 return((
Image *) NULL);
159 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
160 case DoublePixel: image->depth=8*
sizeof(double);
break;
161 case FloatPixel: image->depth=8*
sizeof(float);
break;
162 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
163 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
167 for (i=0; i < (ssize_t) length; i++)
176 image->matte=MagickTrue;
188 image->colorspace=CMYKColorspace;
194 image->colorspace=GRAYColorspace;
200 image->colorspace=GRAYColorspace;
205 status=SetImageExtent(image,columns,rows);
206 if (status == MagickFalse)
208 InheritException(exception,&image->exception);
209 image=DestroyImage(image);
211 status=ResetImagePixels(image,exception);
212 if (status == MagickFalse)
214 InheritException(exception,&image->exception);
215 image=DestroyImage(image);
217 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels);
218 if (status == MagickFalse)
220 InheritException(exception,&image->exception);
221 image=DestroyImage(image);
255 #if defined(__cplusplus) || defined(c_plusplus)
259 static size_t PingStream(
const Image *magick_unused(image),
260 const void *magick_unused(pixels),
const size_t columns)
262 magick_unreferenced(image);
263 magick_unreferenced(pixels);
268 #if defined(__cplusplus) || defined(c_plusplus)
281 assert(image_info != (
ImageInfo *) NULL);
282 assert(image_info->signature == MagickCoreSignature);
284 if (IsEventLogging() != MagickFalse)
285 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
286 image_info->filename);
287 ping_info=CloneImageInfo(image_info);
288 ping_info->ping=MagickTrue;
289 image=ReadStream(ping_info,&PingStream,exception);
290 if (image != (
Image *) NULL)
292 ResetTimer(&image->timer);
293 if (ping_info->verbose != MagickFalse)
294 (void) IdentifyImage(image,stdout,MagickFalse);
296 ping_info=DestroyImageInfo(ping_info);
328 filename[MaxTextExtent];
340 assert(image_info != (
ImageInfo *) NULL);
341 assert(image_info->signature == MagickCoreSignature);
343 if (IsEventLogging() != MagickFalse)
344 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
345 image_info->filename);
346 (void) InterpretImageFilename(image_info,(
Image *) NULL,image_info->filename,
347 (int) image_info->scene,filename);
348 if (LocaleCompare(filename,image_info->filename) != 0)
360 read_info=CloneImageInfo(image_info);
361 sans=AcquireExceptionInfo();
362 (void) SetImageInfo(read_info,0,sans);
363 sans=DestroyExceptionInfo(sans);
364 if (read_info->number_scenes == 0)
366 read_info=DestroyImageInfo(read_info);
367 return(PingImage(image_info,exception));
369 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
370 images=NewImageList();
371 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
372 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
374 (void) InterpretImageFilename(image_info,(
Image *) NULL,filename,(int)
375 scene,read_info->filename);
376 image=PingImage(read_info,exception);
377 if (image == (
Image *) NULL)
379 AppendImageToList(&images,image);
381 read_info=DestroyImageInfo(read_info);
384 return(PingImage(image_info,exception));
416 static MagickBooleanType IsCoderAuthorized(
const char *coder,
419 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
422 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
423 "NotAuthorized",
"`%s'",coder);
433 filename[MaxTextExtent],
434 magick[MaxTextExtent],
435 magick_filename[MaxTextExtent];
469 assert(image_info != (
ImageInfo *) NULL);
470 assert(image_info->signature == MagickCoreSignature);
471 assert(image_info->filename != (
char *) NULL);
473 if (IsEventLogging() != MagickFalse)
474 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
475 image_info->filename);
476 read_info=CloneImageInfo(image_info);
477 (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
478 (void) SetImageInfo(read_info,0,exception);
479 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
480 (void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
484 sans_exception=AcquireExceptionInfo();
485 magick_info=GetMagickInfo(read_info->magick,sans_exception);
486 if (sans_exception->severity == PolicyError)
487 magick_info=GetMagickInfo(read_info->magick,exception);
488 sans_exception=DestroyExceptionInfo(sans_exception);
489 if ((magick_info != (
const MagickInfo *) NULL) &&
490 (GetMagickRawSupport(magick_info) != MagickFalse))
492 if (GetMagickEndianSupport(magick_info) == MagickFalse)
493 read_info->endian=UndefinedEndian;
495 if (image_info->endian == UndefinedEndian)
501 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
505 if ((magick_info != (
const MagickInfo *) NULL) &&
506 (GetMagickSeekableStream(magick_info) != MagickFalse))
511 image=AcquireImage(read_info);
512 (void) CopyMagickString(image->filename,read_info->filename,
514 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
515 if (status == MagickFalse)
517 read_info=DestroyImageInfo(read_info);
518 image=DestroyImage(image);
519 return((
Image *) NULL);
521 if (IsBlobSeekable(image) == MagickFalse)
526 *read_info->filename=
'\0';
527 status=ImageToFile(image,read_info->filename,exception);
528 if (status == MagickFalse)
530 (void) CloseBlob(image);
531 read_info=DestroyImageInfo(read_info);
532 image=DestroyImage(image);
533 return((
Image *) NULL);
535 read_info->temporary=MagickTrue;
537 (void) CloseBlob(image);
538 image=DestroyImage(image);
540 image=NewImageList();
541 if ((magick_info == (
const MagickInfo *) NULL) ||
542 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
544 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
547 (void) SetImageInfo(read_info,0,exception);
548 (void) CopyMagickString(read_info->filename,filename,MaxTextExtent);
549 magick_info=GetMagickInfo(read_info->magick,exception);
552 if ((magick_info != (
const MagickInfo *) NULL) &&
553 (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL))
558 thread_support=GetMagickThreadSupport(magick_info);
559 if ((thread_support & DecoderThreadSupport) == 0)
560 LockSemaphoreInfo(magick_info->semaphore);
561 status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
562 image=(
Image *) NULL;
563 if (status != MagickFalse)
564 image=GetImageDecoder(magick_info)(read_info,exception);
565 if ((thread_support & DecoderThreadSupport) == 0)
566 UnlockSemaphoreInfo(magick_info->semaphore);
573 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
576 (void) ThrowMagickException(exception,GetMagickModule(),
577 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
579 if (read_info->temporary != MagickFalse)
580 (void) RelinquishUniqueFileResource(read_info->filename);
581 read_info=DestroyImageInfo(read_info);
582 return((
Image *) NULL);
587 image=AcquireImage(read_info);
588 if (image == (
Image *) NULL)
590 read_info=DestroyImageInfo(read_info);
591 return((
Image *) NULL);
593 (void) CopyMagickString(image->filename,read_info->filename,
595 *read_info->filename=
'\0';
596 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
597 LockSemaphoreInfo(delegate_info->semaphore);
598 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
600 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
601 UnlockSemaphoreInfo(delegate_info->semaphore);
602 image=DestroyImageList(image);
603 read_info->temporary=MagickTrue;
604 if (status != MagickFalse)
605 (void) SetImageInfo(read_info,0,exception);
606 magick_info=GetMagickInfo(read_info->magick,exception);
607 if ((magick_info == (
const MagickInfo *) NULL) ||
608 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
610 if (IsPathAccessible(read_info->filename) != MagickFalse)
611 (void) ThrowMagickException(exception,GetMagickModule(),
612 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
615 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
616 read_info->filename);
617 read_info=DestroyImageInfo(read_info);
618 return((
Image *) NULL);
623 thread_support=GetMagickThreadSupport(magick_info);
624 if ((thread_support & DecoderThreadSupport) == 0)
625 LockSemaphoreInfo(magick_info->semaphore);
626 status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
627 image=(
Image *) NULL;
628 if (status != MagickFalse)
629 image=(
Image *) (GetImageDecoder(magick_info))(read_info,exception);
630 if ((thread_support & DecoderThreadSupport) == 0)
631 UnlockSemaphoreInfo(magick_info->semaphore);
633 if (read_info->temporary != MagickFalse)
635 (void) RelinquishUniqueFileResource(read_info->filename);
636 read_info->temporary=MagickFalse;
637 if (image != (
Image *) NULL)
638 (
void) CopyMagickString(image->filename,filename,MaxTextExtent);
640 if (image == (
Image *) NULL)
642 read_info=DestroyImageInfo(read_info);
645 if (exception->severity >= ErrorException)
646 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
647 "Coder (%s) generated an image despite an error (%d), "
648 "notify the developers",image->magick,exception->severity);
649 if (IsBlobTemporary(image) != MagickFalse)
650 (
void) RelinquishUniqueFileResource(read_info->filename);
651 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
652 (GetImageListLength(image) != 1))
657 clones=CloneImages(image,read_info->scenes,exception);
658 if (clones != (
Image *) NULL)
660 image=DestroyImageList(image);
661 image=GetFirstImageInList(clones);
664 for (next=image; next != (
Image *) NULL; next=GetNextImageInList(next))
667 magick_path[MaxTextExtent],
669 timestamp[MaxTextExtent];
681 *source_date_epoch = (
const char *) NULL;
683 static MagickBooleanType
684 epoch_initalized = MagickFalse;
686 next->taint=MagickFalse;
687 GetPathComponent(magick_filename,MagickPath,magick_path);
688 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
689 (void) CopyMagickString(next->magick,magick,MaxTextExtent);
690 (void) CopyMagickString(next->magick_filename,magick_filename,
692 if (IsBlobTemporary(image) != MagickFalse)
693 (
void) CopyMagickString(next->filename,filename,MaxTextExtent);
694 if (next->magick_columns == 0)
695 next->magick_columns=next->columns;
696 if (next->magick_rows == 0)
697 next->magick_rows=next->rows;
698 (void) GetImageProperty(next,
"exif:*");
699 (void) GetImageProperty(next,
"icc:*");
700 (void) GetImageProperty(next,
"iptc:*");
701 (void) GetImageProperty(next,
"xmp:*");
702 value=GetImageProperty(next,
"exif:Orientation");
703 if (value == (
char *) NULL)
704 value=GetImageProperty(next,
"tiff:Orientation");
705 if (value != (
char *) NULL)
707 next->orientation=(OrientationType) StringToLong(value);
708 (void) DeleteImageProperty(next,
"tiff:Orientation");
709 (void) DeleteImageProperty(next,
"exif:Orientation");
711 value=GetImageProperty(next,
"exif:XResolution");
712 if (value != (
char *) NULL)
714 geometry_info.rho=next->x_resolution;
715 geometry_info.sigma=1.0;
716 (void) ParseGeometry(value,&geometry_info);
717 if (geometry_info.sigma != 0)
718 next->x_resolution=geometry_info.rho/geometry_info.sigma;
719 if (strchr(value,
',') != (
char *) NULL)
720 next->x_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
721 (void) DeleteImageProperty(next,
"exif:XResolution");
723 value=GetImageProperty(next,
"exif:YResolution");
724 if (value != (
char *) NULL)
726 geometry_info.rho=next->y_resolution;
727 geometry_info.sigma=1.0;
728 (void) ParseGeometry(value,&geometry_info);
729 if (geometry_info.sigma != 0)
730 next->y_resolution=geometry_info.rho/geometry_info.sigma;
731 if (strchr(value,
',') != (
char *) NULL)
732 next->y_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
733 (void) DeleteImageProperty(next,
"exif:YResolution");
735 value=GetImageProperty(next,
"exif:ResolutionUnit");
736 if (value == (
char *) NULL)
737 value=GetImageProperty(next,
"tiff:ResolutionUnit");
738 if (value != (
char *) NULL)
740 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
742 if (option_type >= 0)
743 next->units=(ResolutionType) option_type;
744 (void) DeleteImageProperty(next,
"exif:ResolutionUnit");
745 (void) DeleteImageProperty(next,
"tiff:ResolutionUnit");
747 if (next->page.width == 0)
748 next->page.width=next->columns;
749 if (next->page.height == 0)
750 next->page.height=next->rows;
751 option=GetImageOption(read_info,
"caption");
752 if (option != (
const char *) NULL)
754 property=InterpretImageProperties(read_info,next,option);
755 (void) SetImageProperty(next,
"caption",property);
756 property=DestroyString(property);
758 option=GetImageOption(read_info,
"comment");
759 if (option != (
const char *) NULL)
761 property=InterpretImageProperties(read_info,next,option);
762 (void) SetImageProperty(next,
"comment",property);
763 property=DestroyString(property);
765 option=GetImageOption(read_info,
"label");
766 if (option != (
const char *) NULL)
768 property=InterpretImageProperties(read_info,next,option);
769 (void) SetImageProperty(next,
"label",property);
770 property=DestroyString(property);
772 if (LocaleCompare(next->magick,
"TEXT") == 0)
773 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
774 if ((read_info->extract != (
char *) NULL) &&
775 (read_info->stream == (StreamHandler) NULL))
780 SetGeometry(next,&geometry);
781 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
782 if ((next->columns != geometry.width) ||
783 (next->rows != geometry.height))
785 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
790 crop_image=CropImage(next,&geometry,exception);
791 if (crop_image != (
Image *) NULL)
792 ReplaceImageInList(&next,crop_image);
795 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
797 (void) ParseRegionGeometry(next,read_info->extract,&geometry,
799 if ((geometry.width != 0) && (geometry.height != 0))
801 Image *resize_image=ResizeImage(next,geometry.width,
802 geometry.height,next->filter,next->blur,exception);
803 if (resize_image != (
Image *) NULL)
804 ReplaceImageInList(&next,resize_image);
809 profile=GetImageProfile(next,
"icc");
811 profile=GetImageProfile(next,
"icm");
814 next->color_profile.length=GetStringInfoLength(profile);
815 next->color_profile.info=GetStringInfoDatum(profile);
817 profile=GetImageProfile(next,
"iptc");
819 profile=GetImageProfile(next,
"8bim");
822 next->iptc_profile.length=GetStringInfoLength(profile);
823 next->iptc_profile.info=GetStringInfoDatum(profile);
825 if (epoch_initalized == MagickFalse)
827 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
828 epoch_initalized=MagickTrue;
830 if (source_date_epoch == (
const char *) NULL)
832 (void) FormatMagickTime(image->timestamp,MaxTextExtent,timestamp);
833 (void) SetImageProperty(next,
"date:timestamp",timestamp);
834 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
835 MaxTextExtent,timestamp);
836 (void) SetImageProperty(next,
"date:modify",timestamp);
837 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
838 MaxTextExtent,timestamp);
839 (void) SetImageProperty(next,
"date:create",timestamp);
841 option=GetImageOption(image_info,
"delay");
842 if (option != (
const char *) NULL)
847 flags=ParseGeometry(option,&geometry_info);
848 if ((flags & GreaterValue) != 0)
850 if (next->delay > (
size_t) floor(geometry_info.rho+0.5))
851 next->delay=(size_t) floor(geometry_info.rho+0.5);
854 if ((flags & LessValue) != 0)
856 if (next->delay < (
size_t) floor(geometry_info.rho+0.5))
857 next->delay=(
size_t) floor(geometry_info.rho+0.5);
860 next->delay=(size_t) floor(geometry_info.rho+0.5);
861 if ((flags & SigmaValue) != 0)
862 next->ticks_per_second=CastDoubleToLong(floor(
863 geometry_info.sigma+0.5));
865 option=GetImageOption(image_info,
"dispose");
866 if (option != (
const char *) NULL)
868 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
870 if (option_type >= 0)
871 next->dispose=(DisposeType) option_type;
873 if (read_info->verbose != MagickFalse)
874 (void) IdentifyImage(next,stderr,MagickFalse);
877 read_info=DestroyImageInfo(read_info);
878 if (GetBlobError(image) != MagickFalse)
879 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
880 return(GetFirstImageInList(image));
911 filename[MaxTextExtent];
923 assert(image_info != (
ImageInfo *) NULL);
924 assert(image_info->signature == MagickCoreSignature);
926 if (IsEventLogging() != MagickFalse)
927 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
928 image_info->filename);
929 read_info=CloneImageInfo(image_info);
930 *read_info->magick=
'\0';
931 (void) InterpretImageFilename(read_info,(
Image *) NULL,read_info->filename,
932 (int) read_info->scene,filename);
933 if (LocaleCompare(filename,read_info->filename) != 0)
945 sans=AcquireExceptionInfo();
946 (void) SetImageInfo(read_info,0,sans);
947 sans=DestroyExceptionInfo(sans);
948 if (read_info->number_scenes == 0)
950 read_info=DestroyImageInfo(read_info);
951 return(ReadImage(image_info,exception));
953 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
954 images=NewImageList();
955 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
956 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
958 (void) InterpretImageFilename(image_info,(
Image *) NULL,filename,(int)
959 scene,read_info->filename);
960 image=ReadImage(read_info,exception);
961 if (image == (
Image *) NULL)
963 AppendImageToList(&images,image);
965 read_info=DestroyImageInfo(read_info);
968 image=ReadImage(read_info,exception);
969 read_info=DestroyImageInfo(read_info);
1024 image=NewImageList();
1025 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1027 ThrowReaderException(CorruptImageError,
"CorruptImage");
1028 blob=Base64Decode(++p,&length);
1031 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1032 ThrowReaderException(CorruptImageError,
"CorruptImage");
1034 read_info=CloneImageInfo(image_info);
1035 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1037 *read_info->filename=
'\0';
1038 *read_info->magick=
'\0';
1039 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1051 if (LocaleNCompare(++p,
"x-",2) == 0)
1053 (void) strcpy(read_info->filename,
"data.");
1054 q=read_info->filename+5;
1055 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1059 image=BlobToImage(read_info,blob,length,exception);
1060 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1061 read_info=DestroyImageInfo(read_info);
1093 MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1097 filename[MaxTextExtent];
1125 assert(image_info != (
ImageInfo *) NULL);
1126 assert(image_info->signature == MagickCoreSignature);
1127 assert(image != (
Image *) NULL);
1128 assert(image->signature == MagickCoreSignature);
1129 if (IsEventLogging() != MagickFalse)
1130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1131 image_info->filename);
1132 exception=(&image->exception);
1133 sans_exception=AcquireExceptionInfo();
1134 write_info=CloneImageInfo(image_info);
1135 (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
1136 (void) SetImageInfo(write_info,1,sans_exception);
1137 if (*write_info->magick ==
'\0')
1138 (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
1139 if (LocaleCompare(write_info->magick,
"clipmask") == 0)
1141 if (image->clip_mask == (
Image *) NULL)
1143 (void) ThrowMagickException(exception,GetMagickModule(),
1144 OptionError,
"NoClipPathDefined",
"`%s'",image->filename);
1145 write_info=DestroyImageInfo(write_info);
1146 return(MagickFalse);
1148 image=image->clip_mask;
1149 (void) SetImageInfo(write_info,1,sans_exception);
1151 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1152 (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
1156 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1157 if (sans_exception->severity == PolicyError)
1158 magick_info=GetMagickInfo(write_info->magick,exception);
1159 sans_exception=DestroyExceptionInfo(sans_exception);
1160 if (magick_info != (
const MagickInfo *) NULL)
1162 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1163 image->endian=UndefinedEndian;
1165 if ((image_info->endian == UndefinedEndian) &&
1166 (GetMagickRawSupport(magick_info) != MagickFalse))
1172 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1175 (void) SyncImageProfiles(image);
1176 DisassociateImageStream(image);
1177 option=GetImageOption(image_info,
"delegate:bimodal");
1178 if ((option != (
const char *) NULL) &&
1179 (IsMagickTrue(option) != MagickFalse) &&
1180 (write_info->page == (
char *) NULL) &&
1181 (GetPreviousImageInList(image) == (
Image *) NULL) &&
1182 (GetNextImageInList(image) == (
Image *) NULL) &&
1183 (IsTaintImage(image) == MagickFalse))
1185 delegate_info=GetDelegateInfo(image->magick,write_info->magick,
1188 (GetDelegateMode(delegate_info) == 0) &&
1189 (IsPathAccessible(image->magick_filename) != MagickFalse))
1194 (void) CopyMagickString(image->filename,image->magick_filename,
1196 status=InvokeDelegate(write_info,image,image->magick,
1197 write_info->magick,exception);
1198 write_info=DestroyImageInfo(write_info);
1199 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1204 temporary=MagickFalse;
1205 if ((magick_info != (
const MagickInfo *) NULL) &&
1206 (GetMagickSeekableStream(magick_info) != MagickFalse))
1209 filename[MaxTextExtent];
1211 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1212 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1213 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1214 if (status != MagickFalse)
1216 if (IsBlobSeekable(image) == MagickFalse)
1221 write_info->adjoin=MagickTrue;
1222 (void) CopyMagickString(write_info->filename,image->filename,
1224 (void) AcquireUniqueFilename(image->filename);
1225 temporary=MagickTrue;
1227 (void) CloseBlob(image);
1230 if ((magick_info != (
const MagickInfo *) NULL) &&
1231 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1236 thread_support=GetMagickThreadSupport(magick_info);
1237 if ((thread_support & EncoderThreadSupport) == 0)
1238 LockSemaphoreInfo(magick_info->semaphore);
1239 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,exception);
1240 if (status != MagickFalse)
1241 status=GetImageEncoder(magick_info)(write_info,image);
1242 if ((thread_support & EncoderThreadSupport) == 0)
1243 UnlockSemaphoreInfo(magick_info->semaphore);
1247 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,
1254 *write_info->filename=
'\0';
1255 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1256 LockSemaphoreInfo(delegate_info->semaphore);
1257 status=InvokeDelegate(write_info,image,(
char *) NULL,
1258 write_info->magick,exception);
1259 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1260 UnlockSemaphoreInfo(delegate_info->semaphore);
1261 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1265 sans_exception=AcquireExceptionInfo();
1266 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1267 if (sans_exception->severity == PolicyError)
1268 magick_info=GetMagickInfo(write_info->magick,exception);
1269 sans_exception=DestroyExceptionInfo(sans_exception);
1270 if ((write_info->affirm == MagickFalse) &&
1273 (void) CopyMagickString(write_info->magick,image->magick,
1275 magick_info=GetMagickInfo(write_info->magick,exception);
1277 if ((magick_info == (
const MagickInfo *) NULL) ||
1278 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1281 extension[MaxTextExtent];
1283 GetPathComponent(image->filename,ExtensionPath,extension);
1284 if (*extension !=
'\0')
1285 magick_info=GetMagickInfo(extension,exception);
1287 magick_info=GetMagickInfo(image->magick,exception);
1288 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1290 if ((magick_info == (
const MagickInfo *) NULL) ||
1291 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1293 magick_info=GetMagickInfo(image->magick,exception);
1294 if ((magick_info == (
const MagickInfo *) NULL) ||
1295 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1296 (void) ThrowMagickException(exception,GetMagickModule(),
1297 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1298 "`%s'",write_info->magick);
1300 (
void) ThrowMagickException(exception,GetMagickModule(),
1301 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1302 "`%s'",write_info->magick);
1304 if ((magick_info != (
const MagickInfo *) NULL) &&
1305 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1310 thread_support=GetMagickThreadSupport(magick_info);
1311 if ((thread_support & EncoderThreadSupport) == 0)
1312 LockSemaphoreInfo(magick_info->semaphore);
1313 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,
1315 if (status != MagickFalse)
1316 status=GetImageEncoder(magick_info)(write_info,image);
1317 if ((thread_support & EncoderThreadSupport) == 0)
1318 UnlockSemaphoreInfo(magick_info->semaphore);
1322 if (temporary != MagickFalse)
1327 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1328 if (status != MagickFalse)
1330 (void) RelinquishUniqueFileResource(write_info->filename);
1331 status=ImageToFile(image,write_info->filename,exception);
1333 (void) CloseBlob(image);
1334 (void) RelinquishUniqueFileResource(image->filename);
1335 (void) CopyMagickString(image->filename,write_info->filename,
1338 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1339 (write_info->verbose != MagickFalse))
1340 (
void) IdentifyImage(image,stderr,MagickFalse);
1341 write_info=DestroyImageInfo(write_info);
1342 if (GetBlobError(image) != MagickFalse)
1343 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1383 MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1386 #define WriteImageTag "Write/Image"
1400 MagickProgressMonitor
1412 assert(image_info != (
const ImageInfo *) NULL);
1413 assert(image_info->signature == MagickCoreSignature);
1414 assert(images != (
Image *) NULL);
1415 assert(images->signature == MagickCoreSignature);
1417 if (IsEventLogging() != MagickFalse)
1418 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1419 write_info=CloneImageInfo(image_info);
1420 *write_info->magick=
'\0';
1421 images=GetFirstImageInList(images);
1422 if (images == (
Image *) NULL)
1423 return(MagickFalse);
1424 if (filename != (
const char *) NULL)
1425 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1426 (
void) CopyMagickString(p->filename,filename,MaxTextExtent);
1427 (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
1428 sans_exception=AcquireExceptionInfo();
1429 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1431 sans_exception=DestroyExceptionInfo(sans_exception);
1432 if (*write_info->magick ==
'\0')
1433 (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
1435 for ( ; GetNextImageInList(p) != (
Image *) NULL; p=GetNextImageInList(p))
1440 next=GetNextImageInList(p);
1441 if (next == (
Image *) NULL)
1443 if (p->scene >= next->scene)
1451 i=(ssize_t) images->scene;
1452 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1453 p->scene=(
size_t) i++;
1461 progress_monitor=(MagickProgressMonitor) NULL;
1463 number_images=GetImageListLength(images);
1464 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1466 if (number_images != 1)
1467 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1469 status&=WriteImage(write_info,p);
1470 GetImageException(p,exception);
1471 if (number_images != 1)
1472 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1473 if (write_info->adjoin != MagickFalse)
1475 if (number_images != 1)
1477 proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
1478 if (proceed == MagickFalse)
1482 write_info=DestroyImageInfo(write_info);
1483 return(status != 0 ? MagickTrue : MagickFalse);