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,
136 const void *pixels,ExceptionInfo *exception)
153 assert(map != (
const char *) NULL);
154 assert(pixels != (
void *) NULL);
155 assert(exception != (ExceptionInfo *) NULL);
156 assert(exception->signature == MagickCoreSignature);
157 if (IsEventLogging() != MagickFalse)
158 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
159 image=AcquireImage((ImageInfo *) NULL);
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)
277MagickExport Image *PingImage(
const ImageInfo *image_info,
278 ExceptionInfo *exception)
286 assert(image_info != (ImageInfo *) NULL);
287 assert(image_info->signature == MagickCoreSignature);
288 assert(exception != (ExceptionInfo *) NULL);
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);
329MagickExport Image *PingImages(
const ImageInfo *image_info,
330 ExceptionInfo *exception)
333 filename[MaxTextExtent];
345 assert(image_info != (ImageInfo *) NULL);
346 assert(image_info->signature == MagickCoreSignature);
347 assert(exception != (ExceptionInfo *) NULL);
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 *module,
422 const char *coder,
const PolicyRights rights,ExceptionInfo *exception)
424 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
427 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
428 "NotAuthorized",
"`%s'",coder);
431 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
434 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
435 "NotAuthorized",
"`%s'",module);
441MagickExport Image *ReadImage(
const ImageInfo *image_info,
442 ExceptionInfo *exception)
445 filename[MaxTextExtent],
446 magick[MaxTextExtent],
447 magick_filename[MaxTextExtent];
481 assert(image_info != (ImageInfo *) NULL);
482 assert(image_info->signature == MagickCoreSignature);
483 assert(image_info->filename != (
char *) NULL);
484 assert(exception != (ExceptionInfo *) NULL);
485 if (IsEventLogging() != MagickFalse)
486 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
487 image_info->filename);
488 read_info=CloneImageInfo(image_info);
489 (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
490 (void) SetImageInfo(read_info,0,exception);
491 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
492 (void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
496 sans_exception=AcquireExceptionInfo();
497 magick_info=GetMagickInfo(read_info->magick,sans_exception);
498 if (sans_exception->severity == PolicyError)
499 magick_info=GetMagickInfo(read_info->magick,exception);
500 sans_exception=DestroyExceptionInfo(sans_exception);
501 if ((magick_info != (
const MagickInfo *) NULL) &&
502 (GetMagickRawSupport(magick_info) != MagickFalse))
504 if (GetMagickEndianSupport(magick_info) == MagickFalse)
505 read_info->endian=UndefinedEndian;
507 if (image_info->endian == UndefinedEndian)
513 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
517 if ((magick_info != (
const MagickInfo *) NULL) &&
518 (GetMagickSeekableStream(magick_info) != MagickFalse))
523 image=AcquireImage(read_info);
524 (void) CopyMagickString(image->filename,read_info->filename,
526 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
527 if (status == MagickFalse)
529 read_info=DestroyImageInfo(read_info);
530 image=DestroyImage(image);
531 return((Image *) NULL);
533 if (IsBlobSeekable(image) == MagickFalse)
538 *read_info->filename=
'\0';
539 status=ImageToFile(image,read_info->filename,exception);
540 if (status == MagickFalse)
542 (void) CloseBlob(image);
543 read_info=DestroyImageInfo(read_info);
544 image=DestroyImage(image);
545 return((Image *) NULL);
547 read_info->temporary=MagickTrue;
549 (void) CloseBlob(image);
550 image=DestroyImage(image);
552 image=NewImageList();
553 if ((magick_info == (
const MagickInfo *) NULL) ||
554 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
556 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
557 if (delegate_info == (
const DelegateInfo *) NULL)
559 (void) SetImageInfo(read_info,0,exception);
560 (void) CopyMagickString(read_info->filename,filename,MaxTextExtent);
561 magick_info=GetMagickInfo(read_info->magick,exception);
564 if ((magick_info != (
const MagickInfo *) NULL) &&
565 (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL))
570 thread_support=GetMagickThreadSupport(magick_info);
571 if ((thread_support & DecoderThreadSupport) == 0)
572 LockSemaphoreInfo(magick_info->semaphore);
573 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
574 ReadPolicyRights,exception);
575 image=(Image *) NULL;
576 if (status != MagickFalse)
577 image=GetImageDecoder(magick_info)(read_info,exception);
578 if ((thread_support & DecoderThreadSupport) == 0)
579 UnlockSemaphoreInfo(magick_info->semaphore);
586 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
587 if (delegate_info == (
const DelegateInfo *) NULL)
589 (void) ThrowMagickException(exception,GetMagickModule(),
590 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
591 read_info->filename);
592 if (read_info->temporary != MagickFalse)
593 (void) RelinquishUniqueFileResource(read_info->filename);
594 read_info=DestroyImageInfo(read_info);
595 return((Image *) NULL);
600 image=AcquireImage(read_info);
601 if (image == (Image *) NULL)
603 read_info=DestroyImageInfo(read_info);
604 return((Image *) NULL);
606 (void) CopyMagickString(image->filename,read_info->filename,
608 *read_info->filename=
'\0';
609 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
610 LockSemaphoreInfo(delegate_info->semaphore);
611 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
613 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
614 UnlockSemaphoreInfo(delegate_info->semaphore);
615 image=DestroyImageList(image);
616 read_info->temporary=MagickTrue;
617 if (status != MagickFalse)
618 (void) SetImageInfo(read_info,0,exception);
619 magick_info=GetMagickInfo(read_info->magick,exception);
620 if ((magick_info == (
const MagickInfo *) NULL) ||
621 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
623 if (IsPathAccessible(read_info->filename) != MagickFalse)
624 (void) ThrowMagickException(exception,GetMagickModule(),
625 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
628 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
629 read_info->filename);
630 read_info=DestroyImageInfo(read_info);
631 return((Image *) NULL);
636 thread_support=GetMagickThreadSupport(magick_info);
637 if ((thread_support & DecoderThreadSupport) == 0)
638 LockSemaphoreInfo(magick_info->semaphore);
639 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
640 ReadPolicyRights,exception);
641 image=(Image *) NULL;
642 if (status != MagickFalse)
643 image=(Image *) (GetImageDecoder(magick_info))(read_info,exception);
644 if ((thread_support & DecoderThreadSupport) == 0)
645 UnlockSemaphoreInfo(magick_info->semaphore);
647 if (read_info->temporary != MagickFalse)
649 (void) RelinquishUniqueFileResource(read_info->filename);
650 read_info->temporary=MagickFalse;
651 if (image != (Image *) NULL)
652 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
654 if (image == (Image *) NULL)
656 read_info=DestroyImageInfo(read_info);
659 if (exception->severity >= ErrorException)
660 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
661 "Coder (%s) generated an image despite an error (%d), "
662 "notify the developers",image->magick,exception->severity);
663 if (IsBlobTemporary(image) != MagickFalse)
664 (void) RelinquishUniqueFileResource(read_info->filename);
665 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
666 (GetImageListLength(image) != 1))
671 clones=CloneImages(image,read_info->scenes,exception);
672 image=DestroyImageList(image);
673 if (clones != (Image *) NULL)
674 image=GetFirstImageInList(clones);
675 if (image == (Image *) NULL)
677 read_info=DestroyImageInfo(read_info);
681 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
684 magick_path[MaxTextExtent],
686 timestamp[MaxTextExtent];
698 *source_date_epoch = (
const char *) NULL;
700 static MagickBooleanType
701 epoch_initialized = MagickFalse;
703 next->taint=MagickFalse;
704 GetPathComponent(magick_filename,MagickPath,magick_path);
705 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
706 (void) CopyMagickString(next->magick,magick,MaxTextExtent);
707 (void) CopyMagickString(next->magick_filename,magick_filename,
709 if (IsBlobTemporary(image) != MagickFalse)
710 (void) CopyMagickString(next->filename,filename,MaxTextExtent);
711 if (next->magick_columns == 0)
712 next->magick_columns=next->columns;
713 if (next->magick_rows == 0)
714 next->magick_rows=next->rows;
715 (void) GetImageProperty(next,
"exif:*");
716 (void) GetImageProperty(next,
"icc:*");
717 (void) GetImageProperty(next,
"iptc:*");
718 (void) GetImageProperty(next,
"xmp:*");
719 value=GetImageProperty(next,
"exif:Orientation");
720 if (value == (
char *) NULL)
721 value=GetImageProperty(next,
"tiff:Orientation");
722 if (value != (
char *) NULL)
724 next->orientation=(OrientationType) StringToLong(value);
725 (void) DeleteImageProperty(next,
"tiff:Orientation");
726 (void) DeleteImageProperty(next,
"exif:Orientation");
728 value=GetImageProperty(next,
"exif:XResolution");
729 if (value != (
char *) NULL)
731 geometry_info.rho=next->x_resolution;
732 geometry_info.sigma=1.0;
733 (void) ParseGeometry(value,&geometry_info);
734 if (geometry_info.sigma != 0)
735 next->x_resolution=geometry_info.rho/geometry_info.sigma;
736 if (strchr(value,
',') != (
char *) NULL)
737 next->x_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
738 (void) DeleteImageProperty(next,
"exif:XResolution");
740 value=GetImageProperty(next,
"exif:YResolution");
741 if (value != (
char *) NULL)
743 geometry_info.rho=next->y_resolution;
744 geometry_info.sigma=1.0;
745 (void) ParseGeometry(value,&geometry_info);
746 if (geometry_info.sigma != 0)
747 next->y_resolution=geometry_info.rho/geometry_info.sigma;
748 if (strchr(value,
',') != (
char *) NULL)
749 next->y_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
750 (void) DeleteImageProperty(next,
"exif:YResolution");
752 value=GetImageProperty(next,
"exif:ResolutionUnit");
753 if (value == (
char *) NULL)
754 value=GetImageProperty(next,
"tiff:ResolutionUnit");
755 if (value != (
char *) NULL)
757 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
759 if (option_type >= 0)
760 next->units=(ResolutionType) option_type;
761 (void) DeleteImageProperty(next,
"exif:ResolutionUnit");
762 (void) DeleteImageProperty(next,
"tiff:ResolutionUnit");
764 if (next->page.width == 0)
765 next->page.width=next->columns;
766 if (next->page.height == 0)
767 next->page.height=next->rows;
768 option=GetImageOption(read_info,
"caption");
769 if (option != (
const char *) NULL)
771 property=InterpretImageProperties(read_info,next,option);
772 (void) SetImageProperty(next,
"caption",property);
773 property=DestroyString(property);
775 option=GetImageOption(read_info,
"comment");
776 if (option != (
const char *) NULL)
778 property=InterpretImageProperties(read_info,next,option);
779 (void) SetImageProperty(next,
"comment",property);
780 property=DestroyString(property);
782 option=GetImageOption(read_info,
"label");
783 if (option != (
const char *) NULL)
785 property=InterpretImageProperties(read_info,next,option);
786 (void) SetImageProperty(next,
"label",property);
787 property=DestroyString(property);
789 if (LocaleCompare(next->magick,
"TEXT") == 0)
790 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
791 if ((read_info->extract != (
char *) NULL) &&
792 (read_info->stream == (StreamHandler) NULL))
797 SetGeometry(next,&geometry);
798 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
799 if ((next->columns != geometry.width) ||
800 (next->rows != geometry.height))
802 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
807 crop_image=CropImage(next,&geometry,exception);
808 if (crop_image != (Image *) NULL)
809 ReplaceImageInList(&next,crop_image);
812 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
814 (void) ParseRegionGeometry(next,read_info->extract,&geometry,
816 if ((geometry.width != 0) && (geometry.height != 0))
818 Image *resize_image=ResizeImage(next,geometry.width,
819 geometry.height,next->filter,next->blur,exception);
820 if (resize_image != (Image *) NULL)
821 ReplaceImageInList(&next,resize_image);
826 profile=GetImageProfile(next,
"icc");
827 if (profile == (
const StringInfo *) NULL)
828 profile=GetImageProfile(next,
"icm");
829 if (profile != (
const StringInfo *) NULL)
831 next->color_profile.length=GetStringInfoLength(profile);
832 next->color_profile.info=GetStringInfoDatum(profile);
834 profile=GetImageProfile(next,
"iptc");
835 if (profile == (
const StringInfo *) NULL)
836 profile=GetImageProfile(next,
"8bim");
837 if (profile != (
const StringInfo *) NULL)
839 next->iptc_profile.length=GetStringInfoLength(profile);
840 next->iptc_profile.info=GetStringInfoDatum(profile);
842 if (epoch_initialized == MagickFalse)
844 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
845 epoch_initialized=MagickTrue;
847 if (source_date_epoch == (
const char *) NULL)
849 (void) FormatMagickTime(image->timestamp,MaxTextExtent,timestamp);
850 (void) SetImageProperty(next,
"date:timestamp",timestamp);
851 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
852 MaxTextExtent,timestamp);
853 (void) SetImageProperty(next,
"date:modify",timestamp);
854 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
855 MaxTextExtent,timestamp);
856 (void) SetImageProperty(next,
"date:create",timestamp);
858 option=GetImageOption(image_info,
"delay");
859 if (option != (
const char *) NULL)
864 flags=ParseGeometry(option,&geometry_info);
865 if ((flags & GreaterValue) != 0)
867 if (next->delay > (
size_t) floor(geometry_info.rho+0.5))
868 next->delay=(size_t) floor(geometry_info.rho+0.5);
871 if ((flags & LessValue) != 0)
873 if (next->delay < (
size_t) floor(geometry_info.rho+0.5))
874 next->delay=(size_t) floor(geometry_info.rho+0.5);
877 next->delay=(size_t) floor(geometry_info.rho+0.5);
878 if ((flags & SigmaValue) != 0)
879 next->ticks_per_second=CastDoubleToLong(floor(
880 geometry_info.sigma+0.5));
882 option=GetImageOption(image_info,
"dispose");
883 if (option != (
const char *) NULL)
885 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
887 if (option_type >= 0)
888 next->dispose=(DisposeType) option_type;
890 if (read_info->verbose != MagickFalse)
891 (void) IdentifyImage(next,stderr,MagickFalse);
894 read_info=DestroyImageInfo(read_info);
895 if (GetBlobError(image) != MagickFalse)
896 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
897 return(GetFirstImageInList(image));
924MagickExport Image *ReadImages(
const ImageInfo *image_info,
925 ExceptionInfo *exception)
928 filename[MaxTextExtent];
940 assert(image_info != (ImageInfo *) NULL);
941 assert(image_info->signature == MagickCoreSignature);
942 assert(exception != (ExceptionInfo *) NULL);
943 if (IsEventLogging() != MagickFalse)
944 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
945 image_info->filename);
946 read_info=CloneImageInfo(image_info);
947 *read_info->magick=
'\0';
948 (void) InterpretImageFilename(read_info,(Image *) NULL,read_info->filename,
949 (
int) read_info->scene,filename);
950 if (LocaleCompare(filename,read_info->filename) != 0)
962 sans=AcquireExceptionInfo();
963 (void) SetImageInfo(read_info,0,sans);
964 sans=DestroyExceptionInfo(sans);
965 if (read_info->number_scenes == 0)
967 read_info=DestroyImageInfo(read_info);
968 return(ReadImage(image_info,exception));
970 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
971 images=NewImageList();
972 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
973 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
975 (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(
int)
976 scene,read_info->filename);
977 image=ReadImage(read_info,exception);
978 if (image == (Image *) NULL)
980 AppendImageToList(&images,image);
982 read_info=DestroyImageInfo(read_info);
985 image=ReadImage(read_info,exception);
986 read_info=DestroyImageInfo(read_info);
1020MagickExport Image *ReadInlineImage(
const ImageInfo *image_info,
1021 const char *content,ExceptionInfo *exception)
1041 image=NewImageList();
1042 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1044 ThrowReaderException(CorruptImageError,
"CorruptImage");
1045 blob=Base64Decode(++p,&length);
1048 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1049 ThrowReaderException(CorruptImageError,
"CorruptImage");
1051 read_info=CloneImageInfo(image_info);
1052 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1054 *read_info->filename=
'\0';
1055 *read_info->magick=
'\0';
1056 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1068 if (LocaleNCompare(++p,
"x-",2) == 0)
1070 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1071 q=read_info->filename+5;
1072 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1076 image=BlobToImage(read_info,blob,length,exception);
1077 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1078 read_info=DestroyImageInfo(read_info);
1110MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1114 filename[MaxTextExtent];
1142 assert(image_info != (ImageInfo *) NULL);
1143 assert(image_info->signature == MagickCoreSignature);
1144 assert(image != (Image *) NULL);
1145 assert(image->signature == MagickCoreSignature);
1146 if (IsEventLogging() != MagickFalse)
1147 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1148 image_info->filename);
1149 exception=(&image->exception);
1150 sans_exception=AcquireExceptionInfo();
1151 write_info=CloneImageInfo(image_info);
1152 (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
1153 (void) SetImageInfo(write_info,1,sans_exception);
1154 if (*write_info->magick ==
'\0')
1155 (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
1156 if (LocaleCompare(write_info->magick,
"clipmask") == 0)
1158 if (image->clip_mask == (Image *) NULL)
1160 (void) ThrowMagickException(exception,GetMagickModule(),
1161 OptionError,
"NoClipPathDefined",
"`%s'",image->filename);
1162 write_info=DestroyImageInfo(write_info);
1163 return(MagickFalse);
1165 image=image->clip_mask;
1166 (void) SetImageInfo(write_info,1,sans_exception);
1168 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1169 (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
1173 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1174 if (sans_exception->severity == PolicyError)
1175 magick_info=GetMagickInfo(write_info->magick,exception);
1176 sans_exception=DestroyExceptionInfo(sans_exception);
1177 if (magick_info != (
const MagickInfo *) NULL)
1179 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1180 image->endian=UndefinedEndian;
1182 if ((image_info->endian == UndefinedEndian) &&
1183 (GetMagickRawSupport(magick_info) != MagickFalse))
1189 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1192 (void) SyncImageProfiles(image);
1193 DisassociateImageStream(image);
1194 option=GetImageOption(image_info,
"delegate:bimodal");
1195 if ((option != (
const char *) NULL) &&
1196 (IsMagickTrue(option) != MagickFalse) &&
1197 (write_info->page == (
char *) NULL) &&
1198 (GetPreviousImageInList(image) == (Image *) NULL) &&
1199 (GetNextImageInList(image) == (Image *) NULL) &&
1200 (IsTaintImage(image) == MagickFalse))
1202 delegate_info=GetDelegateInfo(image->magick,write_info->magick,
1204 if ((delegate_info != (
const DelegateInfo *) NULL) &&
1205 (GetDelegateMode(delegate_info) == 0) &&
1206 (IsPathAccessible(image->magick_filename) != MagickFalse))
1211 (void) CopyMagickString(image->filename,image->magick_filename,
1213 status=InvokeDelegate(write_info,image,image->magick,
1214 write_info->magick,exception);
1215 write_info=DestroyImageInfo(write_info);
1216 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1221 temporary=MagickFalse;
1222 if ((magick_info != (
const MagickInfo *) NULL) &&
1223 (GetMagickSeekableStream(magick_info) != MagickFalse))
1226 filename[MaxTextExtent];
1228 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1229 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1230 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1231 if (status != MagickFalse)
1233 if (IsBlobSeekable(image) == MagickFalse)
1238 write_info->adjoin=MagickTrue;
1239 (void) CopyMagickString(write_info->filename,image->filename,
1241 (void) AcquireUniqueFilename(image->filename);
1242 temporary=MagickTrue;
1244 if (CloseBlob(image) == MagickFalse)
1248 if ((magick_info != (
const MagickInfo *) NULL) &&
1249 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1254 thread_support=GetMagickThreadSupport(magick_info);
1255 if ((thread_support & EncoderThreadSupport) == 0)
1256 LockSemaphoreInfo(magick_info->semaphore);
1257 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1258 WritePolicyRights,exception);
1259 if (status != MagickFalse)
1260 status=GetImageEncoder(magick_info)(write_info,image);
1261 if ((thread_support & EncoderThreadSupport) == 0)
1262 UnlockSemaphoreInfo(magick_info->semaphore);
1266 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,
1268 if (delegate_info != (DelegateInfo *) NULL)
1273 *write_info->filename=
'\0';
1274 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1275 LockSemaphoreInfo(delegate_info->semaphore);
1276 status=InvokeDelegate(write_info,image,(
char *) NULL,
1277 write_info->magick,exception);
1278 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1279 UnlockSemaphoreInfo(delegate_info->semaphore);
1280 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1284 sans_exception=AcquireExceptionInfo();
1285 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1286 if (sans_exception->severity == PolicyError)
1287 magick_info=GetMagickInfo(write_info->magick,exception);
1288 sans_exception=DestroyExceptionInfo(sans_exception);
1289 if ((write_info->affirm == MagickFalse) &&
1290 (magick_info == (
const MagickInfo *) NULL))
1292 (void) CopyMagickString(write_info->magick,image->magick,
1294 magick_info=GetMagickInfo(write_info->magick,exception);
1296 if ((magick_info == (
const MagickInfo *) NULL) ||
1297 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1300 extension[MaxTextExtent];
1302 GetPathComponent(image->filename,ExtensionPath,extension);
1303 if (*extension !=
'\0')
1304 magick_info=GetMagickInfo(extension,exception);
1306 magick_info=GetMagickInfo(image->magick,exception);
1307 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1309 if ((magick_info == (
const MagickInfo *) NULL) ||
1310 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1312 magick_info=GetMagickInfo(image->magick,exception);
1313 if ((magick_info == (
const MagickInfo *) NULL) ||
1314 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1315 (void) ThrowMagickException(exception,GetMagickModule(),
1316 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1317 "`%s'",write_info->magick);
1319 (
void) ThrowMagickException(exception,GetMagickModule(),
1320 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1321 "`%s'",write_info->magick);
1323 if ((magick_info != (
const MagickInfo *) NULL) &&
1324 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1329 thread_support=GetMagickThreadSupport(magick_info);
1330 if ((thread_support & EncoderThreadSupport) == 0)
1331 LockSemaphoreInfo(magick_info->semaphore);
1332 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1333 WritePolicyRights,exception);
1334 if (status != MagickFalse)
1335 status=GetImageEncoder(magick_info)(write_info,image);
1336 if ((thread_support & EncoderThreadSupport) == 0)
1337 UnlockSemaphoreInfo(magick_info->semaphore);
1341 if (temporary != MagickFalse)
1346 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1347 if (status != MagickFalse)
1349 (void) RelinquishUniqueFileResource(write_info->filename);
1350 status=ImageToFile(image,write_info->filename,exception);
1352 if (CloseBlob(image) == MagickFalse)
1354 (void) RelinquishUniqueFileResource(image->filename);
1355 (void) CopyMagickString(image->filename,write_info->filename,
1358 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1359 (write_info->verbose != MagickFalse))
1360 (void) IdentifyImage(image,stderr,MagickFalse);
1361 write_info=DestroyImageInfo(write_info);
1362 if (GetBlobError(image) != MagickFalse)
1363 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1403MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1404 Image *images,
const char *filename,ExceptionInfo *exception)
1406#define WriteImageTag "Write/Image"
1420 MagickProgressMonitor
1432 assert(image_info != (
const ImageInfo *) NULL);
1433 assert(image_info->signature == MagickCoreSignature);
1434 assert(images != (Image *) NULL);
1435 assert(images->signature == MagickCoreSignature);
1436 assert(exception != (ExceptionInfo *) NULL);
1437 if (IsEventLogging() != MagickFalse)
1438 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1439 write_info=CloneImageInfo(image_info);
1440 *write_info->magick=
'\0';
1441 images=GetFirstImageInList(images);
1442 if (images == (Image *) NULL)
1443 return(MagickFalse);
1444 if (filename != (
const char *) NULL)
1445 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1446 (
void) CopyMagickString(p->filename,filename,MaxTextExtent);
1447 (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
1448 sans_exception=AcquireExceptionInfo();
1449 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1451 sans_exception=DestroyExceptionInfo(sans_exception);
1452 if (*write_info->magick ==
'\0')
1453 (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
1455 for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1457 if (p->scene >= GetNextImageInList(p)->scene)
1465 i=(ssize_t) images->scene;
1466 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1467 p->scene=(
size_t) i++;
1475 progress_monitor=(MagickProgressMonitor) NULL;
1477 number_images=GetImageListLength(images);
1478 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1480 if (number_images != 1)
1481 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1483 status&=WriteImage(write_info,p);
1484 GetImageException(p,exception);
1485 if (number_images != 1)
1486 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1487 if (write_info->adjoin != MagickFalse)
1489 if (number_images != 1)
1491 proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
1492 if (proceed == MagickFalse)
1496 write_info=DestroyImageInfo(write_info);
1497 return(status != 0 ? MagickTrue : MagickFalse);