42#include "MagickCore/studio.h"
43#include "MagickCore/attribute.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/exception.h"
47#include "MagickCore/exception-private.h"
48#include "MagickCore/cache.h"
49#include "MagickCore/client.h"
50#include "MagickCore/coder-private.h"
51#include "MagickCore/colorspace-private.h"
52#include "MagickCore/constitute.h"
53#include "MagickCore/constitute-private.h"
54#include "MagickCore/delegate.h"
55#include "MagickCore/geometry.h"
56#include "MagickCore/identify.h"
57#include "MagickCore/image-private.h"
58#include "MagickCore/list.h"
59#include "MagickCore/magick.h"
60#include "MagickCore/memory_.h"
61#include "MagickCore/monitor.h"
62#include "MagickCore/monitor-private.h"
63#include "MagickCore/option.h"
64#include "MagickCore/pixel.h"
65#include "MagickCore/pixel-accessor.h"
66#include "MagickCore/policy.h"
67#include "MagickCore/profile.h"
68#include "MagickCore/profile-private.h"
69#include "MagickCore/property.h"
70#include "MagickCore/quantum.h"
71#include "MagickCore/resize.h"
72#include "MagickCore/resource_.h"
73#include "MagickCore/semaphore.h"
74#include "MagickCore/statistic.h"
75#include "MagickCore/stream.h"
76#include "MagickCore/string_.h"
77#include "MagickCore/string-private.h"
78#include "MagickCore/timer.h"
79#include "MagickCore/timer-private.h"
80#include "MagickCore/token.h"
81#include "MagickCore/transform.h"
82#include "MagickCore/utility.h"
83#include "MagickCore/utility-private.h"
88#define MaxReadRecursionDepth 100
164MagickExport
Image *ConstituteImage(
const size_t columns,
const size_t rows,
165 const char *map,
const StorageType storage,
const void *pixels,
183 assert(map != (
const char *) NULL);
184 assert(pixels != (
void *) NULL);
186 assert(exception->signature == MagickCoreSignature);
187 if (IsEventLogging() != MagickFalse)
188 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
189 image=AcquireImage((
ImageInfo *) NULL,exception);
190 if (image == (
Image *) NULL)
191 return((
Image *) NULL);
194 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
195 case DoublePixel: image->depth=8*
sizeof(double);
break;
196 case FloatPixel: image->depth=8*
sizeof(float);
break;
197 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
198 case LongLongPixel: image->depth=8*
sizeof(MagickSizeType);
break;
199 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
203 for (i=0; i < (ssize_t) length; i++)
212 image->alpha_trait=BlendPixelTrait;
224 image->colorspace=CMYKColorspace;
230 image->colorspace=GRAYColorspace;
236 image->colorspace=GRAYColorspace;
241 status=SetImageExtent(image,columns,rows,exception);
242 if (status == MagickFalse)
243 return(DestroyImageList(image));
244 status=ResetImagePixels(image,exception);
245 if (status == MagickFalse)
246 return(DestroyImageList(image));
247 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels,exception);
248 if (status == MagickFalse)
249 image=DestroyImage(image);
282#if defined(__cplusplus) || defined(c_plusplus)
286static size_t PingStream(
const Image *magick_unused(image),
287 const void *magick_unused(pixels),
const size_t columns)
289 magick_unreferenced(image);
290 magick_unreferenced(pixels);
294#if defined(__cplusplus) || defined(c_plusplus)
307 assert(image_info != (
ImageInfo *) NULL);
308 assert(image_info->signature == MagickCoreSignature);
310 if (IsEventLogging() != MagickFalse)
311 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
312 image_info->filename);
313 ping_info=CloneImageInfo(image_info);
314 ping_info->ping=MagickTrue;
315 image=ReadStream(ping_info,&PingStream,exception);
316 if (image != (
Image *) NULL)
318 ResetTimer(&image->timer);
319 if (ping_info->verbose != MagickFalse)
320 (void) IdentifyImage(image,stdout,MagickFalse,exception);
322 ping_info=DestroyImageInfo(ping_info);
353MagickExport
Image *PingImages(
ImageInfo *image_info,
const char *filename,
357 ping_filename[MagickPathExtent];
369 assert(image_info != (
ImageInfo *) NULL);
370 assert(image_info->signature == MagickCoreSignature);
372 if (IsEventLogging() != MagickFalse)
373 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
374 image_info->filename);
375 (void) SetImageOption(image_info,
"filename",filename);
376 (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
377 (void) InterpretImageFilename(image_info,(
Image *) NULL,image_info->filename,
378 (
int) image_info->scene,ping_filename,exception);
379 if (LocaleCompare(ping_filename,image_info->filename) != 0)
391 read_info=CloneImageInfo(image_info);
392 sans=AcquireExceptionInfo();
393 (void) SetImageInfo(read_info,0,sans);
394 sans=DestroyExceptionInfo(sans);
395 if (read_info->number_scenes == 0)
397 read_info=DestroyImageInfo(read_info);
398 return(PingImage(image_info,exception));
400 (void) CopyMagickString(ping_filename,read_info->filename,
402 images=NewImageList();
403 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
404 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
406 (void) InterpretImageFilename(image_info,(
Image *) NULL,ping_filename,
407 (
int) scene,read_info->filename,exception);
408 image=PingImage(read_info,exception);
409 if (image == (
Image *) NULL)
411 AppendImageToList(&images,image);
413 read_info=DestroyImageInfo(read_info);
416 return(PingImage(image_info,exception));
448static MagickBooleanType IsCoderAuthorized(
const char *coder,
451 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
454 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
455 "NotAuthorized",
"`%s'",coder);
461static void InitializeConstituteInfo(
const ImageInfo *image_info,
467 memset(constitute_info,0,
sizeof(*constitute_info));
468 constitute_info->sync_from_exif=MagickTrue;
469 constitute_info->sync_from_tiff=MagickTrue;
470 option=GetImageOption(image_info,
"exif:sync-image");
471 if (IsStringFalse(option) != MagickFalse)
472 constitute_info->sync_from_exif=MagickFalse;
473 option=GetImageOption(image_info,
"tiff:sync-image");
474 if (IsStringFalse(option) != MagickFalse)
475 constitute_info->sync_from_tiff=MagickFalse;
476 constitute_info->caption=GetImageOption(image_info,
"caption");
477 constitute_info->comment=GetImageOption(image_info,
"comment");
478 constitute_info->label=GetImageOption(image_info,
"label");
479 option=GetImageOption(image_info,
"delay");
480 if (option != (
const char *) NULL)
485 constitute_info->delay_flags=ParseGeometry(option,&geometry_info);
486 if (constitute_info->delay_flags != NoValue)
488 constitute_info->delay=floor(geometry_info.rho+0.5);
489 if ((constitute_info->delay_flags & SigmaValue) != 0)
490 constitute_info->ticks_per_second=CastDoubleToLong(floor(
491 geometry_info.sigma+0.5));
496static void SyncOrientationFromProperties(
Image *image,
502 orientation=(
const char *) NULL;
503 if (constitute_info->sync_from_exif != MagickFalse)
505 orientation=GetImageProperty(image,
"exif:Orientation",exception);
506 if (orientation != (
const char *) NULL)
508 image->orientation=(OrientationType) StringToLong(orientation);
509 (void) DeleteImageProperty(image,
"exif:Orientation");
512 if ((orientation == (
const char *) NULL) &&
513 (constitute_info->sync_from_tiff != MagickFalse))
515 orientation=GetImageProperty(image,
"tiff:Orientation",exception);
516 if (orientation != (
const char *) NULL)
518 image->orientation=(OrientationType) StringToLong(orientation);
519 (void) DeleteImageProperty(image,
"tiff:Orientation");
524static void SyncResolutionFromProperties(
Image *image,
535 resolution_x=(
const char *) NULL;
536 resolution_y=(
const char *) NULL;
537 resolution_units=(
const char *) NULL;
538 used_tiff=MagickFalse;
539 if (constitute_info->sync_from_exif != MagickFalse)
541 resolution_x=GetImageProperty(image,
"exif:XResolution",exception);
542 resolution_y=GetImageProperty(image,
"exif:YResolution",exception);
543 if ((resolution_x != (
const char *) NULL) &&
544 (resolution_y != (
const char *) NULL))
545 resolution_units=GetImageProperty(image,
"exif:ResolutionUnit",
548 if ((resolution_x == (
const char *) NULL) &&
549 (resolution_y == (
const char *) NULL) &&
550 (constitute_info->sync_from_tiff != MagickFalse))
552 resolution_x=GetImageProperty(image,
"tiff:XResolution",exception);
553 resolution_y=GetImageProperty(image,
"tiff:YResolution",exception);
554 if ((resolution_x != (
const char *) NULL) &&
555 (resolution_y != (
const char *) NULL))
557 used_tiff=MagickTrue;
558 resolution_units=GetImageProperty(image,
"tiff:ResolutionUnit",
562 if ((resolution_x != (
const char *) NULL) &&
563 (resolution_y != (
const char *) NULL))
571 geometry_info.rho=image->resolution.x;
572 geometry_info.sigma=1.0;
573 (void) ParseGeometry(resolution_x,&geometry_info);
574 if (geometry_info.sigma != 0)
575 image->resolution.x=geometry_info.rho/geometry_info.sigma;
576 if (strchr(resolution_x,
',') != (
char *) NULL)
577 image->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
578 geometry_info.rho=image->resolution.y;
579 geometry_info.sigma=1.0;
580 (void) ParseGeometry(resolution_y,&geometry_info);
581 if (geometry_info.sigma != 0)
582 image->resolution.y=geometry_info.rho/geometry_info.sigma;
583 if (strchr(resolution_y,
',') != (
char *) NULL)
584 image->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
585 if (resolution_units != (
char *) NULL)
587 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
589 if (option_type >= 0)
590 image->units=(ResolutionType) option_type;
592 if (used_tiff == MagickFalse)
594 (void) DeleteImageProperty(image,
"exif:XResolution");
595 (void) DeleteImageProperty(image,
"exif:YResolution");
596 (void) DeleteImageProperty(image,
"exif:ResolutionUnit");
600 (void) DeleteImageProperty(image,
"tiff:XResolution");
601 (void) DeleteImageProperty(image,
"tiff:YResolution");
602 (void) DeleteImageProperty(image,
"tiff:ResolutionUnit");
611 filename[MagickPathExtent],
612 magick[MagickPathExtent],
613 magick_filename[MagickPathExtent];
643 assert(image_info != (
ImageInfo *) NULL);
644 assert(image_info->signature == MagickCoreSignature);
645 assert(image_info->filename != (
char *) NULL);
646 if (IsEventLogging() != MagickFalse)
647 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
648 image_info->filename);
650 read_info=CloneImageInfo(image_info);
651 (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
652 (void) SetImageInfo(read_info,0,exception);
653 (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
654 (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
658 sans_exception=AcquireExceptionInfo();
659 magick_info=GetMagickInfo(read_info->magick,sans_exception);
660 if (sans_exception->severity == PolicyError)
661 InheritException(exception,sans_exception);
662 sans_exception=DestroyExceptionInfo(sans_exception);
665 if (GetMagickEndianSupport(magick_info) == MagickFalse)
666 read_info->endian=UndefinedEndian;
668 if ((image_info->endian == UndefinedEndian) &&
669 (GetMagickRawSupport(magick_info) != MagickFalse))
675 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
679 if ((magick_info != (
const MagickInfo *) NULL) &&
680 (GetMagickDecoderSeekableStream(magick_info) != MagickFalse))
682 image=AcquireImage(read_info,exception);
683 (void) CopyMagickString(image->filename,read_info->filename,
685 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
686 if (status == MagickFalse)
688 read_info=DestroyImageInfo(read_info);
689 image=DestroyImage(image);
690 return((
Image *) NULL);
692 if (IsBlobSeekable(image) == MagickFalse)
697 *read_info->filename=
'\0';
698 status=ImageToFile(image,read_info->filename,exception);
699 if (status == MagickFalse)
701 (void) CloseBlob(image);
702 read_info=DestroyImageInfo(read_info);
703 image=DestroyImage(image);
704 return((
Image *) NULL);
706 read_info->temporary=MagickTrue;
708 (void) CloseBlob(image);
709 image=DestroyImage(image);
711 image=NewImageList();
712 decoder=GetImageDecoder(magick_info);
713 if (decoder == (DecodeImageHandler *) NULL)
715 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
718 (void) SetImageInfo(read_info,0,exception);
719 (void) CopyMagickString(read_info->filename,filename,
721 magick_info=GetMagickInfo(read_info->magick,exception);
722 decoder=GetImageDecoder(magick_info);
725 if (decoder != (DecodeImageHandler *) NULL)
730 if ((magick_info != (
const MagickInfo *) NULL) &&
731 (GetMagickDecoderThreadSupport(magick_info) == MagickFalse))
732 LockSemaphoreInfo(magick_info->semaphore);
733 status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
734 image=(
Image *) NULL;
735 if (status != MagickFalse)
736 image=decoder(read_info,exception);
737 if ((magick_info != (
const MagickInfo *) NULL) &&
738 (GetMagickDecoderThreadSupport(magick_info) == MagickFalse))
739 UnlockSemaphoreInfo(magick_info->semaphore);
743 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
746 (void) ThrowMagickException(exception,GetMagickModule(),
747 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
749 if (read_info->temporary != MagickFalse)
750 (void) RelinquishUniqueFileResource(read_info->filename);
751 read_info=DestroyImageInfo(read_info);
752 return((
Image *) NULL);
757 image=AcquireImage(read_info,exception);
758 if (image == (
Image *) NULL)
760 read_info=DestroyImageInfo(read_info);
761 return((
Image *) NULL);
763 (void) CopyMagickString(image->filename,read_info->filename,
765 *read_info->filename=
'\0';
766 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
767 LockSemaphoreInfo(delegate_info->semaphore);
768 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
770 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
771 UnlockSemaphoreInfo(delegate_info->semaphore);
772 image=DestroyImageList(image);
773 read_info->temporary=MagickTrue;
774 if (status != MagickFalse)
775 (void) SetImageInfo(read_info,0,exception);
776 magick_info=GetMagickInfo(read_info->magick,exception);
777 decoder=GetImageDecoder(magick_info);
778 if (decoder == (DecodeImageHandler *) NULL)
780 if (IsPathAccessible(read_info->filename) != MagickFalse)
781 (void) ThrowMagickException(exception,GetMagickModule(),
782 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
785 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
786 read_info->filename);
787 read_info=DestroyImageInfo(read_info);
788 return((
Image *) NULL);
793 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
794 LockSemaphoreInfo(magick_info->semaphore);
795 status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
796 image=(
Image *) NULL;
797 if (status != MagickFalse)
798 image=(decoder)(read_info,exception);
799 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
800 UnlockSemaphoreInfo(magick_info->semaphore);
802 if (read_info->temporary != MagickFalse)
804 (void) RelinquishUniqueFileResource(read_info->filename);
805 read_info->temporary=MagickFalse;
806 if (image != (
Image *) NULL)
807 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
809 if (image == (
Image *) NULL)
811 read_info=DestroyImageInfo(read_info);
814 if (exception->severity >= ErrorException)
815 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
816 "Coder (%s) generated an image despite an error (%d), "
817 "notify the developers",image->magick,exception->severity);
818 if (IsBlobTemporary(image) != MagickFalse)
819 (void) RelinquishUniqueFileResource(read_info->filename);
820 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
821 (GetImageListLength(image) != 1))
826 clones=CloneImages(image,read_info->scenes,exception);
827 image=DestroyImageList(image);
828 if (clones != (
Image *) NULL)
829 image=GetFirstImageInList(clones);
830 if (image == (
Image *) NULL)
832 read_info=DestroyImageInfo(read_info);
836 InitializeConstituteInfo(read_info,&constitute_info);
837 for (next=image; next != (
Image *) NULL; next=GetNextImageInList(next))
840 magick_path[MagickPathExtent],
847 *source_date_epoch = (
const char *) NULL;
849 static MagickBooleanType
850 epoch_initialized = MagickFalse;
852 next->taint=MagickFalse;
853 GetPathComponent(magick_filename,MagickPath,magick_path);
854 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
855 (void) CopyMagickString(next->magick,magick,MagickPathExtent);
856 (void) CopyMagickString(next->magick_filename,magick_filename,
858 if (IsBlobTemporary(image) != MagickFalse)
859 (void) CopyMagickString(next->filename,filename,MagickPathExtent);
860 if (next->magick_columns == 0)
861 next->magick_columns=next->columns;
862 if (next->magick_rows == 0)
863 next->magick_rows=next->rows;
864 (void) GetImageProperty(next,
"exif:*",exception);
865 (void) GetImageProperty(next,
"icc:*",exception);
866 (void) GetImageProperty(next,
"iptc:*",exception);
867 (void) GetImageProperty(next,
"xmp:*",exception);
868 SyncOrientationFromProperties(next,&constitute_info,exception);
869 SyncResolutionFromProperties(next,&constitute_info,exception);
870 if (next->page.width == 0)
871 next->page.width=next->columns;
872 if (next->page.height == 0)
873 next->page.height=next->rows;
874 if (constitute_info.caption != (
const char *) NULL)
876 property=InterpretImageProperties(read_info,next,
877 constitute_info.caption,exception);
878 (void) SetImageProperty(next,
"caption",property,exception);
879 property=DestroyString(property);
881 if (constitute_info.comment != (
const char *) NULL)
883 property=InterpretImageProperties(read_info,next,
884 constitute_info.comment,exception);
885 (void) SetImageProperty(next,
"comment",property,exception);
886 property=DestroyString(property);
888 if (constitute_info.label != (
const char *) NULL)
890 property=InterpretImageProperties(read_info,next,
891 constitute_info.label,exception);
892 (void) SetImageProperty(next,
"label",property,exception);
893 property=DestroyString(property);
895 if (LocaleCompare(next->magick,
"TEXT") == 0)
896 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
897 if ((read_info->extract != (
char *) NULL) &&
898 (read_info->stream == (StreamHandler) NULL))
906 SetGeometry(next,&geometry);
907 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
908 if ((next->columns != geometry.width) ||
909 (next->rows != geometry.height))
911 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
916 crop_image=CropImage(next,&geometry,exception);
917 if (crop_image != (
Image *) NULL)
918 ReplaceImageInList(&next,crop_image);
921 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
923 flags=ParseRegionGeometry(next,read_info->extract,&geometry,
925 if ((geometry.width != 0) && (geometry.height != 0))
927 Image *resize_image = ResizeImage(next,geometry.width,
928 geometry.height,next->filter,exception);
929 if (resize_image != (
Image *) NULL)
930 ReplaceImageInList(&next,resize_image);
935 profile=GetImageProfile(next,
"icc");
937 profile=GetImageProfile(next,
"icm");
938 profile=GetImageProfile(next,
"iptc");
940 profile=GetImageProfile(next,
"8bim");
941 if (epoch_initialized == MagickFalse)
943 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
944 epoch_initialized=MagickTrue;
946 if (source_date_epoch == (
const char *) NULL)
949 timestamp[MagickTimeExtent];
951 (void) FormatMagickTime(next->timestamp,
sizeof(timestamp),timestamp);
952 (void) SetImageProperty(next,
"date:timestamp",timestamp,exception);
953 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
954 sizeof(timestamp),timestamp);
955 (void) SetImageProperty(next,
"date:modify",timestamp,exception);
956 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
957 sizeof(timestamp),timestamp);
958 (void) SetImageProperty(next,
"date:create",timestamp,exception);
960 if (constitute_info.delay_flags != NoValue)
962 if ((constitute_info.delay_flags & GreaterValue) != 0)
964 if (next->delay > constitute_info.delay)
965 next->delay=constitute_info.delay;
968 if ((constitute_info.delay_flags & LessValue) != 0)
970 if (next->delay < constitute_info.delay)
971 next->delay=constitute_info.delay;
974 next->delay=constitute_info.delay;
975 if ((constitute_info.delay_flags & SigmaValue) != 0)
976 next->ticks_per_second=constitute_info.ticks_per_second;
978 if (constitute_info.dispose != (
const char *) NULL)
983 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
984 constitute_info.dispose);
985 if (option_type >= 0)
986 next->dispose=(DisposeType) option_type;
988 if (read_info->verbose != MagickFalse)
989 (void) IdentifyImage(next,stderr,MagickFalse,exception);
992 read_info=DestroyImageInfo(read_info);
993 if (GetBlobError(image) != MagickFalse)
994 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
995 return(GetFirstImageInList(image));
1025MagickExport
Image *ReadImages(
ImageInfo *image_info,
const char *filename,
1029 read_filename[MagickPathExtent];
1041 assert(image_info != (
ImageInfo *) NULL);
1042 assert(image_info->signature == MagickCoreSignature);
1044 if (IsEventLogging() != MagickFalse)
1045 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1046 image_info->filename);
1047 read_info=CloneImageInfo(image_info);
1048 *read_info->magick=
'\0';
1049 (void) SetImageOption(read_info,
"filename",filename);
1050 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1051 (void) InterpretImageFilename(read_info,(
Image *) NULL,filename,
1052 (
int) read_info->scene,read_filename,exception);
1053 if (LocaleCompare(read_filename,read_info->filename) != 0)
1065 sans=AcquireExceptionInfo();
1066 (void) SetImageInfo(read_info,0,sans);
1067 sans=DestroyExceptionInfo(sans);
1068 if (read_info->number_scenes != 0)
1070 (void) CopyMagickString(read_filename,read_info->filename,
1072 images=NewImageList();
1073 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
1074 scene=(ssize_t) read_info->scene;
1075 for ( ; scene < (ssize_t) extent; scene++)
1077 (void) InterpretImageFilename(image_info,(
Image *) NULL,
1078 read_filename,(
int) scene,read_info->filename,exception);
1079 image=ReadImage(read_info,exception);
1080 if (image == (
Image *) NULL)
1082 AppendImageToList(&images,image);
1084 read_info=DestroyImageInfo(read_info);
1088 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1089 image=ReadImage(read_info,exception);
1090 read_info=DestroyImageInfo(read_info);
1145 image=NewImageList();
1146 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1148 ThrowReaderException(CorruptImageError,
"CorruptImage");
1149 blob=Base64Decode(++p,&length);
1152 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1153 ThrowReaderException(CorruptImageError,
"CorruptImage");
1155 read_info=CloneImageInfo(image_info);
1156 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1158 *read_info->filename=
'\0';
1159 *read_info->magick=
'\0';
1160 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1172 if (LocaleNCompare(++p,
"x-",2) == 0)
1174 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1175 q=read_info->filename+5;
1176 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1180 image=BlobToImage(read_info,blob,length,exception);
1181 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1182 read_info=DestroyImageInfo(read_info);
1217MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1221 filename[MagickPathExtent];
1248 assert(image_info != (
ImageInfo *) NULL);
1249 assert(image_info->signature == MagickCoreSignature);
1250 assert(image != (
Image *) NULL);
1251 if (IsEventLogging() != MagickFalse)
1252 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1253 image_info->filename);
1254 assert(image->signature == MagickCoreSignature);
1256 sans_exception=AcquireExceptionInfo();
1257 write_info=CloneImageInfo(image_info);
1258 (void) CopyMagickString(write_info->filename,image->filename,
1260 (void) SetImageInfo(write_info,1,sans_exception);
1261 if (*write_info->magick ==
'\0')
1262 (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1263 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1264 (void) CopyMagickString(image->filename,write_info->filename,
1269 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1270 if (sans_exception->severity == PolicyError)
1271 magick_info=GetMagickInfo(write_info->magick,exception);
1272 sans_exception=DestroyExceptionInfo(sans_exception);
1273 if (magick_info != (
const MagickInfo *) NULL)
1275 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1276 image->endian=UndefinedEndian;
1278 if ((image_info->endian == UndefinedEndian) &&
1279 (GetMagickRawSupport(magick_info) != MagickFalse))
1285 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1288 SyncImageProfiles(image);
1289 DisassociateImageStream(image);
1290 option=GetImageOption(image_info,
"delegate:bimodal");
1291 if ((IsStringTrue(option) != MagickFalse) &&
1292 (write_info->page == (
char *) NULL) &&
1293 (GetPreviousImageInList(image) == (
Image *) NULL) &&
1294 (GetNextImageInList(image) == (
Image *) NULL) &&
1295 (IsTaintImage(image) == MagickFalse) )
1297 delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1299 (GetDelegateMode(delegate_info) == 0) &&
1300 (IsPathAccessible(image->magick_filename) != MagickFalse))
1305 (void) CopyMagickString(image->filename,image->magick_filename,
1307 status=InvokeDelegate(write_info,image,image->magick,
1308 write_info->magick,exception);
1309 write_info=DestroyImageInfo(write_info);
1310 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1315 temporary=MagickFalse;
1316 if ((magick_info != (
const MagickInfo *) NULL) &&
1317 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1320 image_filename[MagickPathExtent];
1322 (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1323 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1324 (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1325 if (status != MagickFalse)
1327 if (IsBlobSeekable(image) == MagickFalse)
1332 write_info->adjoin=MagickTrue;
1333 (void) CopyMagickString(write_info->filename,image->filename,
1335 (void) AcquireUniqueFilename(image->filename);
1336 temporary=MagickTrue;
1338 if (CloseBlob(image) == MagickFalse)
1342 encoder=GetImageEncoder(magick_info);
1343 if (encoder != (EncodeImageHandler *) NULL)
1348 if ((magick_info != (
const MagickInfo *) NULL) &&
1349 (GetMagickEncoderThreadSupport(magick_info) == MagickFalse))
1350 LockSemaphoreInfo(magick_info->semaphore);
1351 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,exception);
1352 if (status != MagickFalse)
1353 status=encoder(write_info,image,exception);
1354 if ((magick_info != (
const MagickInfo *) NULL) &&
1355 (GetMagickEncoderThreadSupport(magick_info) == MagickFalse))
1356 UnlockSemaphoreInfo(magick_info->semaphore);
1360 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,exception);
1366 *write_info->filename=
'\0';
1367 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1368 LockSemaphoreInfo(delegate_info->semaphore);
1369 status=InvokeDelegate(write_info,image,(
char *) NULL,
1370 write_info->magick,exception);
1371 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1372 UnlockSemaphoreInfo(delegate_info->semaphore);
1373 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1377 sans_exception=AcquireExceptionInfo();
1378 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1379 if (sans_exception->severity == PolicyError)
1380 magick_info=GetMagickInfo(write_info->magick,exception);
1381 sans_exception=DestroyExceptionInfo(sans_exception);
1382 if ((write_info->affirm == MagickFalse) &&
1385 (void) CopyMagickString(write_info->magick,image->magick,
1387 magick_info=GetMagickInfo(write_info->magick,exception);
1389 encoder=GetImageEncoder(magick_info);
1390 if (encoder == (EncodeImageHandler *) NULL)
1393 extension[MagickPathExtent];
1395 GetPathComponent(image->filename,ExtensionPath,extension);
1396 if (*extension !=
'\0')
1397 magick_info=GetMagickInfo(extension,exception);
1399 magick_info=GetMagickInfo(image->magick,exception);
1400 (void) CopyMagickString(image->filename,filename,
1402 encoder=GetImageEncoder(magick_info);
1403 (void) ThrowMagickException(exception,GetMagickModule(),
1404 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1405 "`%s'",write_info->magick);
1407 if (encoder == (EncodeImageHandler *) NULL)
1409 magick_info=GetMagickInfo(image->magick,exception);
1410 encoder=GetImageEncoder(magick_info);
1411 if (encoder == (EncodeImageHandler *) NULL)
1412 (void) ThrowMagickException(exception,GetMagickModule(),
1413 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1414 "`%s'",write_info->magick);
1416 if (encoder != (EncodeImageHandler *) NULL)
1421 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1422 LockSemaphoreInfo(magick_info->semaphore);
1423 status=IsCoderAuthorized(write_info->magick,WritePolicyRights,
1425 if (status != MagickFalse)
1426 status=encoder(write_info,image,exception);
1427 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1428 UnlockSemaphoreInfo(magick_info->semaphore);
1432 if (temporary != MagickFalse)
1437 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1438 if (status != MagickFalse)
1440 (void) RelinquishUniqueFileResource(write_info->filename);
1441 status=ImageToFile(image,write_info->filename,exception);
1443 if (CloseBlob(image) == MagickFalse)
1445 (void) RelinquishUniqueFileResource(image->filename);
1446 (void) CopyMagickString(image->filename,write_info->filename,
1449 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1450 (write_info->verbose != MagickFalse))
1451 (void) IdentifyImage(image,stdout,MagickFalse,exception);
1452 write_info=DestroyImageInfo(write_info);
1453 if (GetBlobError(image) != MagickFalse)
1454 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1494MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1497#define WriteImageTag "Write/Image"
1511 MagickProgressMonitor
1523 assert(image_info != (
const ImageInfo *) NULL);
1524 assert(image_info->signature == MagickCoreSignature);
1525 assert(images != (
Image *) NULL);
1526 assert(images->signature == MagickCoreSignature);
1527 if (IsEventLogging() != MagickFalse)
1528 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1530 write_info=CloneImageInfo(image_info);
1531 *write_info->magick=
'\0';
1532 images=GetFirstImageInList(images);
1533 if (images == (
Image *) NULL)
1534 return(MagickFalse);
1535 if (filename != (
const char *) NULL)
1536 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1537 (
void) CopyMagickString(p->filename,filename,MagickPathExtent);
1538 (void) CopyMagickString(write_info->filename,images->filename,
1540 sans_exception=AcquireExceptionInfo();
1541 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1543 sans_exception=DestroyExceptionInfo(sans_exception);
1544 if (*write_info->magick ==
'\0')
1545 (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1547 for ( ; GetNextImageInList(p) != (
Image *) NULL; p=GetNextImageInList(p))
1549 if (p->scene >= GetNextImageInList(p)->scene)
1557 i=(ssize_t) images->scene;
1558 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1559 p->scene=(
size_t) i++;
1567 progress_monitor=(MagickProgressMonitor) NULL;
1569 number_images=GetImageListLength(images);
1570 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1572 if (number_images != 1)
1573 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1575 status&=(MagickStatusType) WriteImage(write_info,p,exception);
1576 if (number_images != 1)
1577 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1578 if (write_info->adjoin != MagickFalse)
1580 if (number_images != 1)
1582#if defined(MAGICKCORE_OPENMP_SUPPORT)
1586 proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1587 if (proceed == MagickFalse)
1591 write_info=DestroyImageInfo(write_info);
1592 return(status != 0 ? MagickTrue : MagickFalse);