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/cache-private.h"
50#include "magick/client.h"
51#include "magick/coder.h"
52#include "magick/colorspace-private.h"
53#include "magick/constitute.h"
54#include "magick/delegate.h"
55#include "magick/geometry.h"
56#include "magick/identify.h"
57#include "magick/image-private.h"
58#include "magick/list.h"
59#include "magick/magick.h"
60#include "magick/memory_.h"
61#include "magick/monitor.h"
62#include "magick/monitor-private.h"
63#include "magick/option.h"
64#include "magick/pixel.h"
65#include "magick/policy.h"
66#include "magick/profile.h"
67#include "magick/property.h"
68#include "magick/quantum.h"
69#include "magick/resize.h"
70#include "magick/resource_.h"
71#include "magick/semaphore.h"
72#include "magick/statistic.h"
73#include "magick/stream.h"
74#include "magick/string_.h"
75#include "magick/string-private.h"
76#include "magick/timer.h"
77#include "magick/token.h"
78#include "magick/transform.h"
79#include "magick/utility.h"
84#define MaxReadRecursionDepth 100
135MagickExport Image *ConstituteImage(
const size_t columns,
136 const size_t rows,
const char *map,
const StorageType storage,
137 const void *pixels,ExceptionInfo *exception)
154 assert(map != (
const char *) NULL);
155 assert(pixels != (
void *) NULL);
156 assert(exception != (ExceptionInfo *) NULL);
157 assert(exception->signature == MagickCoreSignature);
158 if (IsEventLogging() != MagickFalse)
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
160 image=AcquireImage((ImageInfo *) NULL);
161 if (image == (Image *) NULL)
162 return((Image *) NULL);
165 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
166 case DoublePixel: image->depth=8*
sizeof(double);
break;
167 case FloatPixel: image->depth=8*
sizeof(float);
break;
168 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
169 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
173 for (i=0; i < (ssize_t) length; i++)
182 image->matte=MagickTrue;
194 image->colorspace=CMYKColorspace;
200 image->colorspace=GRAYColorspace;
206 image->colorspace=GRAYColorspace;
211 status=SetImageExtent(image,columns,rows);
212 if (status == MagickFalse)
214 InheritException(exception,&image->exception);
215 image=DestroyImage(image);
217 status=ResetImagePixels(image,exception);
218 if (status == MagickFalse)
220 InheritException(exception,&image->exception);
221 image=DestroyImage(image);
223 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels);
224 if (status == MagickFalse)
226 InheritException(exception,&image->exception);
227 image=DestroyImage(image);
261#if defined(__cplusplus) || defined(c_plusplus)
265static size_t PingStream(
const Image *magick_unused(image),
266 const void *magick_unused(pixels),
const size_t columns)
268 magick_unreferenced(image);
269 magick_unreferenced(pixels);
274#if defined(__cplusplus) || defined(c_plusplus)
278MagickExport Image *PingImage(
const ImageInfo *image_info,
279 ExceptionInfo *exception)
287 assert(image_info != (ImageInfo *) NULL);
288 assert(image_info->signature == MagickCoreSignature);
289 assert(exception != (ExceptionInfo *) NULL);
290 if (IsEventLogging() != MagickFalse)
291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
292 image_info->filename);
293 ping_info=CloneImageInfo(image_info);
294 ping_info->ping=MagickTrue;
295 image=ReadStream(ping_info,&PingStream,exception);
296 if (image != (Image *) NULL)
298 ResetTimer(&image->timer);
299 if (ping_info->verbose != MagickFalse)
300 (void) IdentifyImage(image,stdout,MagickFalse);
302 ping_info=DestroyImageInfo(ping_info);
330MagickExport Image *PingImages(
const ImageInfo *image_info,
331 ExceptionInfo *exception)
334 filename[MaxTextExtent];
346 assert(image_info != (ImageInfo *) NULL);
347 assert(image_info->signature == MagickCoreSignature);
348 assert(exception != (ExceptionInfo *) NULL);
349 if (IsEventLogging() != MagickFalse)
350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
351 image_info->filename);
352 (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
353 (
int) image_info->scene,filename);
354 if (LocaleCompare(filename,image_info->filename) != 0)
366 read_info=CloneImageInfo(image_info);
367 sans=AcquireExceptionInfo();
368 (void) SetImageInfo(read_info,0,sans);
369 sans=DestroyExceptionInfo(sans);
370 if (read_info->number_scenes == 0)
372 read_info=DestroyImageInfo(read_info);
373 return(PingImage(image_info,exception));
375 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
376 images=NewImageList();
377 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
378 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
380 (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(
int)
381 scene,read_info->filename);
382 image=PingImage(read_info,exception);
383 if (image == (Image *) NULL)
385 AppendImageToList(&images,image);
387 read_info=DestroyImageInfo(read_info);
390 return(PingImage(image_info,exception));
422static MagickBooleanType IsCoderAuthorized(
const char *module,
423 const char *coder,
const PolicyRights rights,ExceptionInfo *exception)
425 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
428 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
429 "NotAuthorized",
"`%s'",coder);
432 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
435 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
436 "NotAuthorized",
"`%s'",module);
442MagickExport Image *ReadImage(
const ImageInfo *image_info,
443 ExceptionInfo *exception)
446 filename[MaxTextExtent],
447 magick[MaxTextExtent],
448 magick_filename[MaxTextExtent];
482 assert(image_info != (ImageInfo *) NULL);
483 assert(image_info->signature == MagickCoreSignature);
484 assert(image_info->filename != (
char *) NULL);
485 assert(exception != (ExceptionInfo *) NULL);
486 if (IsEventLogging() != MagickFalse)
487 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
488 image_info->filename);
489 read_info=CloneImageInfo(image_info);
490 (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
491 (void) SetImageInfo(read_info,0,exception);
492 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
493 (void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
497 sans_exception=AcquireExceptionInfo();
498 magick_info=GetMagickInfo(read_info->magick,sans_exception);
499 if (sans_exception->severity == PolicyError)
500 magick_info=GetMagickInfo(read_info->magick,exception);
501 sans_exception=DestroyExceptionInfo(sans_exception);
502 if ((magick_info != (
const MagickInfo *) NULL) &&
503 (GetMagickRawSupport(magick_info) != MagickFalse))
505 if (GetMagickEndianSupport(magick_info) == MagickFalse)
506 read_info->endian=UndefinedEndian;
508 if (image_info->endian == UndefinedEndian)
514 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
518 if ((magick_info != (
const MagickInfo *) NULL) &&
519 (GetMagickSeekableStream(magick_info) != MagickFalse))
524 image=AcquireImage(read_info);
525 (void) CopyMagickString(image->filename,read_info->filename,
527 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
528 if (status == MagickFalse)
530 read_info=DestroyImageInfo(read_info);
531 image=DestroyImage(image);
532 return((Image *) NULL);
534 if (IsBlobSeekable(image) == MagickFalse)
539 *read_info->filename=
'\0';
540 status=ImageToFile(image,read_info->filename,exception);
541 if (status == MagickFalse)
543 (void) CloseBlob(image);
544 read_info=DestroyImageInfo(read_info);
545 image=DestroyImage(image);
546 return((Image *) NULL);
548 read_info->temporary=MagickTrue;
550 (void) CloseBlob(image);
551 image=DestroyImage(image);
553 image=NewImageList();
554 if ((magick_info == (
const MagickInfo *) NULL) ||
555 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
557 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
558 if (delegate_info == (
const DelegateInfo *) NULL)
560 (void) SetImageInfo(read_info,0,exception);
561 (void) CopyMagickString(read_info->filename,filename,MaxTextExtent);
562 magick_info=GetMagickInfo(read_info->magick,exception);
565 if ((magick_info != (
const MagickInfo *) NULL) &&
566 (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL))
571 thread_support=GetMagickThreadSupport(magick_info);
572 if ((thread_support & DecoderThreadSupport) == 0)
573 LockSemaphoreInfo(magick_info->semaphore);
574 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
575 ReadPolicyRights,exception);
576 image=(Image *) NULL;
577 if (status != MagickFalse)
578 image=GetImageDecoder(magick_info)(read_info,exception);
579 if ((thread_support & DecoderThreadSupport) == 0)
580 UnlockSemaphoreInfo(magick_info->semaphore);
587 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
588 if (delegate_info == (
const DelegateInfo *) NULL)
590 (void) ThrowMagickException(exception,GetMagickModule(),
591 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
592 read_info->filename);
593 if (read_info->temporary != MagickFalse)
594 (void) RelinquishUniqueFileResource(read_info->filename);
595 read_info=DestroyImageInfo(read_info);
596 return((Image *) NULL);
601 image=AcquireImage(read_info);
602 if (image == (Image *) NULL)
604 read_info=DestroyImageInfo(read_info);
605 return((Image *) NULL);
607 (void) CopyMagickString(image->filename,read_info->filename,
609 *read_info->filename=
'\0';
610 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
611 LockSemaphoreInfo(delegate_info->semaphore);
612 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
614 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
615 UnlockSemaphoreInfo(delegate_info->semaphore);
616 image=DestroyImageList(image);
617 read_info->temporary=MagickTrue;
618 if (status != MagickFalse)
619 (void) SetImageInfo(read_info,0,exception);
620 magick_info=GetMagickInfo(read_info->magick,exception);
621 if ((magick_info == (
const MagickInfo *) NULL) ||
622 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
624 if (IsPathAccessible(read_info->filename) != MagickFalse)
625 (void) ThrowMagickException(exception,GetMagickModule(),
626 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
629 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
630 read_info->filename);
631 read_info=DestroyImageInfo(read_info);
632 return((Image *) NULL);
637 thread_support=GetMagickThreadSupport(magick_info);
638 if ((thread_support & DecoderThreadSupport) == 0)
639 LockSemaphoreInfo(magick_info->semaphore);
640 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
641 ReadPolicyRights,exception);
642 image=(Image *) NULL;
643 if (status != MagickFalse)
644 image=(Image *) (GetImageDecoder(magick_info))(read_info,exception);
645 if ((thread_support & DecoderThreadSupport) == 0)
646 UnlockSemaphoreInfo(magick_info->semaphore);
648 if (read_info->temporary != MagickFalse)
650 (void) RelinquishUniqueFileResource(read_info->filename);
651 read_info->temporary=MagickFalse;
652 if (image != (Image *) NULL)
653 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
655 if (image == (Image *) NULL)
657 read_info=DestroyImageInfo(read_info);
660 if (exception->severity >= ErrorException)
661 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
662 "Coder (%s) generated an image despite an error (%d), "
663 "notify the developers",image->magick,exception->severity);
664 if (IsBlobTemporary(image) != MagickFalse)
665 (void) RelinquishUniqueFileResource(read_info->filename);
666 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
667 (GetImageListLength(image) != 1))
672 clones=CloneImages(image,read_info->scenes,exception);
673 image=DestroyImageList(image);
674 if (clones != (Image *) NULL)
675 image=GetFirstImageInList(clones);
676 if (image == (Image *) NULL)
678 read_info=DestroyImageInfo(read_info);
682 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
685 magick_path[MaxTextExtent],
687 timestamp[MaxTextExtent];
699 *source_date_epoch = (
const char *) NULL;
701 static MagickBooleanType
702 epoch_initialized = MagickFalse;
704 next->taint=MagickFalse;
705 GetPathComponent(magick_filename,MagickPath,magick_path);
706 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
707 (void) CopyMagickString(next->magick,magick,MaxTextExtent);
708 (void) CopyMagickString(next->magick_filename,magick_filename,
710 if (IsBlobTemporary(image) != MagickFalse)
711 (void) CopyMagickString(next->filename,filename,MaxTextExtent);
712 if (next->magick_columns == 0)
713 next->magick_columns=next->columns;
714 if (next->magick_rows == 0)
715 next->magick_rows=next->rows;
716 (void) GetImageProperty(next,
"exif:*");
717 (void) GetImageProperty(next,
"icc:*");
718 (void) GetImageProperty(next,
"iptc:*");
719 (void) GetImageProperty(next,
"xmp:*");
720 value=GetImageProperty(next,
"exif:Orientation");
721 if (value == (
char *) NULL)
722 value=GetImageProperty(next,
"tiff:Orientation");
723 if (value != (
char *) NULL)
725 next->orientation=(OrientationType) StringToLong(value);
726 (void) DeleteImageProperty(next,
"tiff:Orientation");
727 (void) DeleteImageProperty(next,
"exif:Orientation");
729 value=GetImageProperty(next,
"exif:XResolution");
730 if (value != (
char *) NULL)
732 geometry_info.rho=next->x_resolution;
733 geometry_info.sigma=1.0;
734 (void) ParseGeometry(value,&geometry_info);
735 if (geometry_info.sigma != 0)
736 next->x_resolution=geometry_info.rho/geometry_info.sigma;
737 if (strchr(value,
',') != (
char *) NULL)
738 next->x_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
739 (void) DeleteImageProperty(next,
"exif:XResolution");
741 value=GetImageProperty(next,
"exif:YResolution");
742 if (value != (
char *) NULL)
744 geometry_info.rho=next->y_resolution;
745 geometry_info.sigma=1.0;
746 (void) ParseGeometry(value,&geometry_info);
747 if (geometry_info.sigma != 0)
748 next->y_resolution=geometry_info.rho/geometry_info.sigma;
749 if (strchr(value,
',') != (
char *) NULL)
750 next->y_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
751 (void) DeleteImageProperty(next,
"exif:YResolution");
753 value=GetImageProperty(next,
"exif:ResolutionUnit");
754 if (value == (
char *) NULL)
755 value=GetImageProperty(next,
"tiff:ResolutionUnit");
756 if (value != (
char *) NULL)
758 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
760 if (option_type >= 0)
761 next->units=(ResolutionType) option_type;
762 (void) DeleteImageProperty(next,
"exif:ResolutionUnit");
763 (void) DeleteImageProperty(next,
"tiff:ResolutionUnit");
765 if (next->page.width == 0)
766 next->page.width=next->columns;
767 if (next->page.height == 0)
768 next->page.height=next->rows;
769 option=GetImageOption(read_info,
"caption");
770 if (option != (
const char *) NULL)
772 property=InterpretImageProperties(read_info,next,option);
773 (void) SetImageProperty(next,
"caption",property);
774 property=DestroyString(property);
776 option=GetImageOption(read_info,
"comment");
777 if (option != (
const char *) NULL)
779 property=InterpretImageProperties(read_info,next,option);
780 (void) SetImageProperty(next,
"comment",property);
781 property=DestroyString(property);
783 option=GetImageOption(read_info,
"label");
784 if (option != (
const char *) NULL)
786 property=InterpretImageProperties(read_info,next,option);
787 (void) SetImageProperty(next,
"label",property);
788 property=DestroyString(property);
790 if (LocaleCompare(next->magick,
"TEXT") == 0)
791 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
792 if ((read_info->extract != (
char *) NULL) &&
793 (read_info->stream == (StreamHandler) NULL))
798 SetGeometry(next,&geometry);
799 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
800 if ((next->columns != geometry.width) ||
801 (next->rows != geometry.height))
803 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
808 crop_image=CropImage(next,&geometry,exception);
809 if (crop_image != (Image *) NULL)
810 ReplaceImageInList(&next,crop_image);
813 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
815 (void) ParseRegionGeometry(next,read_info->extract,&geometry,
817 if ((geometry.width != 0) && (geometry.height != 0))
819 Image *resize_image=ResizeImage(next,geometry.width,
820 geometry.height,next->filter,next->blur,exception);
821 if (resize_image != (Image *) NULL)
822 ReplaceImageInList(&next,resize_image);
827 profile=GetImageProfile(next,
"icc");
828 if (profile == (
const StringInfo *) NULL)
829 profile=GetImageProfile(next,
"icm");
830 if (profile != (
const StringInfo *) NULL)
832 next->color_profile.length=GetStringInfoLength(profile);
833 next->color_profile.info=GetStringInfoDatum(profile);
835 profile=GetImageProfile(next,
"iptc");
836 if (profile == (
const StringInfo *) NULL)
837 profile=GetImageProfile(next,
"8bim");
838 if (profile != (
const StringInfo *) NULL)
840 next->iptc_profile.length=GetStringInfoLength(profile);
841 next->iptc_profile.info=GetStringInfoDatum(profile);
843 if (epoch_initialized == MagickFalse)
845 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
846 epoch_initialized=MagickTrue;
848 if (source_date_epoch == (
const char *) NULL)
850 (void) FormatMagickTime(image->timestamp,MaxTextExtent,timestamp);
851 (void) SetImageProperty(next,
"date:timestamp",timestamp);
852 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
853 MaxTextExtent,timestamp);
854 (void) SetImageProperty(next,
"date:modify",timestamp);
855 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
856 MaxTextExtent,timestamp);
857 (void) SetImageProperty(next,
"date:create",timestamp);
859 option=GetImageOption(image_info,
"delay");
860 if (option != (
const char *) NULL)
865 flags=ParseGeometry(option,&geometry_info);
866 if ((flags & GreaterValue) != 0)
868 if (next->delay > (
size_t) floor(geometry_info.rho+0.5))
869 next->delay=(size_t) floor(geometry_info.rho+0.5);
872 if ((flags & LessValue) != 0)
874 if (next->delay < (
size_t) floor(geometry_info.rho+0.5))
875 next->delay=(size_t) floor(geometry_info.rho+0.5);
878 next->delay=(size_t) floor(geometry_info.rho+0.5);
879 if ((flags & SigmaValue) != 0)
880 next->ticks_per_second=CastDoubleToLong(floor(
881 geometry_info.sigma+0.5));
883 option=GetImageOption(image_info,
"dispose");
884 if (option != (
const char *) NULL)
886 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
888 if (option_type >= 0)
889 next->dispose=(DisposeType) option_type;
891 if (read_info->verbose != MagickFalse)
892 (void) IdentifyImage(next,stderr,MagickFalse);
895 read_info=DestroyImageInfo(read_info);
896 if (GetBlobError(image) != MagickFalse)
897 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
898 return(GetFirstImageInList(image));
925MagickExport Image *ReadImages(
const ImageInfo *image_info,
926 ExceptionInfo *exception)
929 filename[MaxTextExtent];
941 assert(image_info != (ImageInfo *) NULL);
942 assert(image_info->signature == MagickCoreSignature);
943 assert(exception != (ExceptionInfo *) NULL);
944 if (IsEventLogging() != MagickFalse)
945 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
946 image_info->filename);
947 read_info=CloneImageInfo(image_info);
948 *read_info->magick=
'\0';
949 (void) InterpretImageFilename(read_info,(Image *) NULL,read_info->filename,
950 (
int) read_info->scene,filename);
951 if (LocaleCompare(filename,read_info->filename) != 0)
963 sans=AcquireExceptionInfo();
964 (void) SetImageInfo(read_info,0,sans);
965 sans=DestroyExceptionInfo(sans);
966 if (read_info->number_scenes == 0)
968 read_info=DestroyImageInfo(read_info);
969 return(ReadImage(image_info,exception));
971 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
972 images=NewImageList();
973 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
974 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
976 (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(
int)
977 scene,read_info->filename);
978 image=ReadImage(read_info,exception);
979 if (image == (Image *) NULL)
981 AppendImageToList(&images,image);
983 read_info=DestroyImageInfo(read_info);
986 image=ReadImage(read_info,exception);
987 read_info=DestroyImageInfo(read_info);
1021MagickExport Image *ReadInlineImage(
const ImageInfo *image_info,
1022 const char *content,ExceptionInfo *exception)
1042 image=NewImageList();
1043 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1045 ThrowReaderException(CorruptImageError,
"CorruptImage");
1046 blob=Base64Decode(++p,&length);
1049 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1050 ThrowReaderException(CorruptImageError,
"CorruptImage");
1052 read_info=CloneImageInfo(image_info);
1053 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1055 *read_info->filename=
'\0';
1056 *read_info->magick=
'\0';
1057 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1069 if (LocaleNCompare(++p,
"x-",2) == 0)
1071 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1072 q=read_info->filename+5;
1073 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1077 image=BlobToImage(read_info,blob,length,exception);
1078 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1079 read_info=DestroyImageInfo(read_info);
1111MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1115 filename[MaxTextExtent];
1143 assert(image_info != (ImageInfo *) NULL);
1144 assert(image_info->signature == MagickCoreSignature);
1145 assert(image != (Image *) NULL);
1146 assert(image->signature == MagickCoreSignature);
1147 if (IsEventLogging() != MagickFalse)
1148 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1149 image_info->filename);
1150 exception=(&image->exception);
1151 sans_exception=AcquireExceptionInfo();
1152 write_info=CloneImageInfo(image_info);
1153 (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
1154 (void) SetImageInfo(write_info,1,sans_exception);
1155 if (*write_info->magick ==
'\0')
1156 (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
1157 if (LocaleCompare(write_info->magick,
"clipmask") == 0)
1159 if (image->clip_mask == (Image *) NULL)
1161 (void) ThrowMagickException(exception,GetMagickModule(),
1162 OptionError,
"NoClipPathDefined",
"`%s'",image->filename);
1163 write_info=DestroyImageInfo(write_info);
1164 return(MagickFalse);
1166 image=image->clip_mask;
1167 (void) SetImageInfo(write_info,1,sans_exception);
1169 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1170 (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
1174 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1175 if (sans_exception->severity == PolicyError)
1176 magick_info=GetMagickInfo(write_info->magick,exception);
1177 sans_exception=DestroyExceptionInfo(sans_exception);
1178 if (magick_info != (
const MagickInfo *) NULL)
1180 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1181 image->endian=UndefinedEndian;
1183 if ((image_info->endian == UndefinedEndian) &&
1184 (GetMagickRawSupport(magick_info) != MagickFalse))
1190 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1193 if (SyncImagePixelCache(image,exception) == MagickFalse)
1194 return(MagickFalse);
1195 if (SyncImageProfiles(image) == MagickFalse)
1196 return(MagickFalse);
1197 DisassociateImageStream(image);
1198 option=GetImageOption(image_info,
"delegate:bimodal");
1199 if ((option != (
const char *) NULL) &&
1200 (IsMagickTrue(option) != MagickFalse) &&
1201 (write_info->page == (
char *) NULL) &&
1202 (GetPreviousImageInList(image) == (Image *) NULL) &&
1203 (GetNextImageInList(image) == (Image *) NULL) &&
1204 (IsTaintImage(image) == MagickFalse))
1206 delegate_info=GetDelegateInfo(image->magick,write_info->magick,
1208 if ((delegate_info != (
const DelegateInfo *) NULL) &&
1209 (GetDelegateMode(delegate_info) == 0) &&
1210 (IsPathAccessible(image->magick_filename) != MagickFalse))
1215 (void) CopyMagickString(image->filename,image->magick_filename,
1217 status=InvokeDelegate(write_info,image,image->magick,
1218 write_info->magick,exception);
1219 write_info=DestroyImageInfo(write_info);
1220 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1225 temporary=MagickFalse;
1226 if ((magick_info != (
const MagickInfo *) NULL) &&
1227 (GetMagickSeekableStream(magick_info) != MagickFalse))
1230 filename[MaxTextExtent];
1232 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1233 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1234 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1235 if (status != MagickFalse)
1237 if (IsBlobSeekable(image) == MagickFalse)
1242 write_info->adjoin=MagickTrue;
1243 (void) CopyMagickString(write_info->filename,image->filename,
1245 (void) AcquireUniqueFilename(image->filename);
1246 temporary=MagickTrue;
1248 if (CloseBlob(image) == MagickFalse)
1252 if ((magick_info != (
const MagickInfo *) NULL) &&
1253 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1258 thread_support=GetMagickThreadSupport(magick_info);
1259 if ((thread_support & EncoderThreadSupport) == 0)
1260 LockSemaphoreInfo(magick_info->semaphore);
1261 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1262 WritePolicyRights,exception);
1263 if (status != MagickFalse)
1264 status=GetImageEncoder(magick_info)(write_info,image);
1265 if ((thread_support & EncoderThreadSupport) == 0)
1266 UnlockSemaphoreInfo(magick_info->semaphore);
1270 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,
1272 if (delegate_info != (DelegateInfo *) NULL)
1277 *write_info->filename=
'\0';
1278 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1279 LockSemaphoreInfo(delegate_info->semaphore);
1280 status=InvokeDelegate(write_info,image,(
char *) NULL,
1281 write_info->magick,exception);
1282 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1283 UnlockSemaphoreInfo(delegate_info->semaphore);
1284 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1288 sans_exception=AcquireExceptionInfo();
1289 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1290 if (sans_exception->severity == PolicyError)
1291 magick_info=GetMagickInfo(write_info->magick,exception);
1292 sans_exception=DestroyExceptionInfo(sans_exception);
1293 if ((write_info->affirm == MagickFalse) &&
1294 (magick_info == (
const MagickInfo *) NULL))
1296 (void) CopyMagickString(write_info->magick,image->magick,
1298 magick_info=GetMagickInfo(write_info->magick,exception);
1300 if ((magick_info == (
const MagickInfo *) NULL) ||
1301 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1304 extension[MaxTextExtent];
1306 GetPathComponent(image->filename,ExtensionPath,extension);
1307 if (*extension !=
'\0')
1308 magick_info=GetMagickInfo(extension,exception);
1310 magick_info=GetMagickInfo(image->magick,exception);
1311 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1313 if ((magick_info == (
const MagickInfo *) NULL) ||
1314 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1316 magick_info=GetMagickInfo(image->magick,exception);
1317 if ((magick_info == (
const MagickInfo *) NULL) ||
1318 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1319 (void) ThrowMagickException(exception,GetMagickModule(),
1320 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1321 "`%s'",write_info->magick);
1323 (
void) ThrowMagickException(exception,GetMagickModule(),
1324 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1325 "`%s'",write_info->magick);
1327 if ((magick_info != (
const MagickInfo *) NULL) &&
1328 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1333 thread_support=GetMagickThreadSupport(magick_info);
1334 if ((thread_support & EncoderThreadSupport) == 0)
1335 LockSemaphoreInfo(magick_info->semaphore);
1336 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1337 WritePolicyRights,exception);
1338 if (status != MagickFalse)
1339 status=GetImageEncoder(magick_info)(write_info,image);
1340 if ((thread_support & EncoderThreadSupport) == 0)
1341 UnlockSemaphoreInfo(magick_info->semaphore);
1345 if (temporary != MagickFalse)
1350 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1351 if (status != MagickFalse)
1353 (void) RelinquishUniqueFileResource(write_info->filename);
1354 status=ImageToFile(image,write_info->filename,exception);
1356 if (CloseBlob(image) == MagickFalse)
1358 (void) RelinquishUniqueFileResource(image->filename);
1359 (void) CopyMagickString(image->filename,write_info->filename,
1362 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1363 (write_info->verbose != MagickFalse))
1364 (void) IdentifyImage(image,stderr,MagickFalse);
1365 write_info=DestroyImageInfo(write_info);
1366 if (GetBlobError(image) != MagickFalse)
1367 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1407MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1408 Image *images,
const char *filename,ExceptionInfo *exception)
1410#define WriteImageTag "Write/Image"
1424 MagickProgressMonitor
1436 assert(image_info != (
const ImageInfo *) NULL);
1437 assert(image_info->signature == MagickCoreSignature);
1438 assert(images != (Image *) NULL);
1439 assert(images->signature == MagickCoreSignature);
1440 assert(exception != (ExceptionInfo *) NULL);
1441 if (IsEventLogging() != MagickFalse)
1442 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1443 write_info=CloneImageInfo(image_info);
1444 *write_info->magick=
'\0';
1445 images=GetFirstImageInList(images);
1446 if (images == (Image *) NULL)
1447 return(MagickFalse);
1448 if (filename != (
const char *) NULL)
1449 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1450 (
void) CopyMagickString(p->filename,filename,MaxTextExtent);
1451 (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
1452 sans_exception=AcquireExceptionInfo();
1453 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1455 sans_exception=DestroyExceptionInfo(sans_exception);
1456 if (*write_info->magick ==
'\0')
1457 (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
1459 for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1461 if (p->scene >= GetNextImageInList(p)->scene)
1469 i=(ssize_t) images->scene;
1470 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1471 p->scene=(
size_t) i++;
1479 progress_monitor=(MagickProgressMonitor) NULL;
1481 number_images=GetImageListLength(images);
1482 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1484 if (number_images != 1)
1485 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1487 status&=WriteImage(write_info,p);
1488 GetImageException(p,exception);
1489 if (number_images != 1)
1490 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1491 if (write_info->adjoin != MagickFalse)
1493 if (number_images != 1)
1495 proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
1496 if (proceed == MagickFalse)
1500 write_info=DestroyImageInfo(write_info);
1501 return(status != 0 ? MagickTrue : MagickFalse);