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/cache-private.h"
50#include "MagickCore/client.h"
51#include "MagickCore/coder-private.h"
52#include "MagickCore/colorspace-private.h"
53#include "MagickCore/constitute.h"
54#include "MagickCore/constitute-private.h"
55#include "MagickCore/delegate.h"
56#include "MagickCore/geometry.h"
57#include "MagickCore/identify.h"
58#include "MagickCore/image-private.h"
59#include "MagickCore/list.h"
60#include "MagickCore/magick.h"
61#include "MagickCore/memory_.h"
62#include "MagickCore/monitor.h"
63#include "MagickCore/monitor-private.h"
64#include "MagickCore/option.h"
65#include "MagickCore/pixel.h"
66#include "MagickCore/pixel-accessor.h"
67#include "MagickCore/policy.h"
68#include "MagickCore/profile.h"
69#include "MagickCore/profile-private.h"
70#include "MagickCore/property.h"
71#include "MagickCore/quantum.h"
72#include "MagickCore/resize.h"
73#include "MagickCore/resource_.h"
74#include "MagickCore/semaphore.h"
75#include "MagickCore/statistic.h"
76#include "MagickCore/stream.h"
77#include "MagickCore/string_.h"
78#include "MagickCore/string-private.h"
79#include "MagickCore/timer.h"
80#include "MagickCore/timer-private.h"
81#include "MagickCore/token.h"
82#include "MagickCore/transform.h"
83#include "MagickCore/utility.h"
84#include "MagickCore/utility-private.h"
89#define MaxReadRecursionDepth 100
165MagickExport
Image *ConstituteImage(
const size_t columns,
const size_t rows,
166 const char *map,
const StorageType storage,
const void *pixels,
184 assert(map != (
const char *) NULL);
185 assert(pixels != (
void *) NULL);
187 assert(exception->signature == MagickCoreSignature);
188 if (IsEventLogging() != MagickFalse)
189 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
190 image=AcquireImage((
ImageInfo *) NULL,exception);
191 if (image == (
Image *) NULL)
192 return((
Image *) NULL);
195 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
196 case DoublePixel: image->depth=8*
sizeof(double);
break;
197 case FloatPixel: image->depth=8*
sizeof(float);
break;
198 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
199 case LongLongPixel: image->depth=8*
sizeof(MagickSizeType);
break;
200 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
204 for (i=0; i < (ssize_t) length; i++)
213 image->alpha_trait=BlendPixelTrait;
225 image->colorspace=CMYKColorspace;
231 image->colorspace=GRAYColorspace;
237 image->colorspace=GRAYColorspace;
242 status=SetImageExtent(image,columns,rows,exception);
243 if (status == MagickFalse)
244 return(DestroyImageList(image));
245 status=ResetImagePixels(image,exception);
246 if (status == MagickFalse)
247 return(DestroyImageList(image));
248 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels,exception);
249 if (status == MagickFalse)
250 image=DestroyImage(image);
283#if defined(__cplusplus) || defined(c_plusplus)
287static size_t PingStream(
const Image *magick_unused(image),
288 const void *magick_unused(pixels),
const size_t columns)
290 magick_unreferenced(image);
291 magick_unreferenced(pixels);
295#if defined(__cplusplus) || defined(c_plusplus)
308 assert(image_info != (
ImageInfo *) NULL);
309 assert(image_info->signature == MagickCoreSignature);
311 if (IsEventLogging() != MagickFalse)
312 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
313 image_info->filename);
314 ping_info=CloneImageInfo(image_info);
315 ping_info->ping=MagickTrue;
316 image=ReadStream(ping_info,&PingStream,exception);
317 if (image != (
Image *) NULL)
319 ResetTimer(&image->timer);
320 if (ping_info->verbose != MagickFalse)
321 (void) IdentifyImage(image,stdout,MagickFalse,exception);
323 ping_info=DestroyImageInfo(ping_info);
354MagickExport
Image *PingImages(
ImageInfo *image_info,
const char *filename,
358 ping_filename[MagickPathExtent];
370 assert(image_info != (
ImageInfo *) NULL);
371 assert(image_info->signature == MagickCoreSignature);
373 if (IsEventLogging() != MagickFalse)
374 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
375 image_info->filename);
376 (void) SetImageOption(image_info,
"filename",filename);
377 (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
378 (void) InterpretImageFilename(image_info,(
Image *) NULL,image_info->filename,
379 (int) image_info->scene,ping_filename,exception);
380 if (LocaleCompare(ping_filename,image_info->filename) != 0)
392 read_info=CloneImageInfo(image_info);
393 sans=AcquireExceptionInfo();
394 (void) SetImageInfo(read_info,0,sans);
395 sans=DestroyExceptionInfo(sans);
396 if (read_info->number_scenes == 0)
398 read_info=DestroyImageInfo(read_info);
399 return(PingImage(image_info,exception));
401 (void) CopyMagickString(ping_filename,read_info->filename,
403 images=NewImageList();
404 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
405 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
407 (void) InterpretImageFilename(image_info,(
Image *) NULL,ping_filename,
408 (int) scene,read_info->filename,exception);
409 image=PingImage(read_info,exception);
410 if (image == (
Image *) NULL)
412 AppendImageToList(&images,image);
414 read_info=DestroyImageInfo(read_info);
417 return(PingImage(image_info,exception));
449static MagickBooleanType IsCoderAuthorized(
const char *module,
450 const char *coder,
const PolicyRights rights,
ExceptionInfo *exception)
452 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
455 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
456 "NotAuthorized",
"`%s'",coder);
459 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
462 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
463 "NotAuthorized",
"`%s'",module);
469static void InitializeConstituteInfo(
const ImageInfo *image_info,
475 memset(constitute_info,0,
sizeof(*constitute_info));
476 constitute_info->sync_from_exif=MagickTrue;
477 constitute_info->sync_from_tiff=MagickTrue;
478 option=GetImageOption(image_info,
"exif:sync-image");
479 if (IsStringFalse(option) != MagickFalse)
480 constitute_info->sync_from_exif=MagickFalse;
481 option=GetImageOption(image_info,
"tiff:sync-image");
482 if (IsStringFalse(option) != MagickFalse)
483 constitute_info->sync_from_tiff=MagickFalse;
484 constitute_info->caption=GetImageOption(image_info,
"caption");
485 constitute_info->comment=GetImageOption(image_info,
"comment");
486 constitute_info->label=GetImageOption(image_info,
"label");
487 option=GetImageOption(image_info,
"delay");
488 if (option != (
const char *) NULL)
493 constitute_info->delay_flags=ParseGeometry(option,&geometry_info);
494 if (constitute_info->delay_flags != NoValue)
496 constitute_info->delay=(size_t) floor(geometry_info.rho+0.5);
497 if ((constitute_info->delay_flags & SigmaValue) != 0)
498 constitute_info->ticks_per_second=CastDoubleToSsizeT(floor(
499 geometry_info.sigma+0.5));
504static void SyncOrientationFromProperties(
Image *image,
510 orientation=(
const char *) NULL;
511 if (constitute_info->sync_from_exif != MagickFalse)
513 orientation=GetImageProperty(image,
"exif:Orientation",exception);
514 if (orientation != (
const char *) NULL)
516 image->orientation=(OrientationType) StringToLong(orientation);
517 (void) DeleteImageProperty(image,
"exif:Orientation");
520 if ((orientation == (
const char *) NULL) &&
521 (constitute_info->sync_from_tiff != MagickFalse))
523 orientation=GetImageProperty(image,
"tiff:Orientation",exception);
524 if (orientation != (
const char *) NULL)
526 image->orientation=(OrientationType) StringToLong(orientation);
527 (void) DeleteImageProperty(image,
"tiff:Orientation");
532static void SyncResolutionFromProperties(
Image *image,
543 resolution_x=(
const char *) NULL;
544 resolution_y=(
const char *) NULL;
545 resolution_units=(
const char *) NULL;
546 used_tiff=MagickFalse;
547 if (constitute_info->sync_from_exif != MagickFalse)
549 resolution_x=GetImageProperty(image,
"exif:XResolution",exception);
550 resolution_y=GetImageProperty(image,
"exif:YResolution",exception);
551 if ((resolution_x != (
const char *) NULL) &&
552 (resolution_y != (
const char *) NULL))
553 resolution_units=GetImageProperty(image,
"exif:ResolutionUnit",
556 if ((resolution_x == (
const char *) NULL) &&
557 (resolution_y == (
const char *) NULL) &&
558 (constitute_info->sync_from_tiff != MagickFalse))
560 resolution_x=GetImageProperty(image,
"tiff:XResolution",exception);
561 resolution_y=GetImageProperty(image,
"tiff:YResolution",exception);
562 if ((resolution_x != (
const char *) NULL) &&
563 (resolution_y != (
const char *) NULL))
565 used_tiff=MagickTrue;
566 resolution_units=GetImageProperty(image,
"tiff:ResolutionUnit",
570 if ((resolution_x != (
const char *) NULL) &&
571 (resolution_y != (
const char *) NULL))
579 geometry_info.rho=image->resolution.x;
580 geometry_info.sigma=1.0;
581 (void) ParseGeometry(resolution_x,&geometry_info);
582 if (geometry_info.sigma != 0)
583 image->resolution.x=geometry_info.rho/geometry_info.sigma;
584 if (strchr(resolution_x,
',') != (
char *) NULL)
585 image->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
586 geometry_info.rho=image->resolution.y;
587 geometry_info.sigma=1.0;
588 (void) ParseGeometry(resolution_y,&geometry_info);
589 if (geometry_info.sigma != 0)
590 image->resolution.y=geometry_info.rho/geometry_info.sigma;
591 if (strchr(resolution_y,
',') != (
char *) NULL)
592 image->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
593 if (resolution_units != (
char *) NULL)
595 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
597 if (option_type >= 0)
598 image->units=(ResolutionType) option_type;
600 if (used_tiff == MagickFalse)
602 (void) DeleteImageProperty(image,
"exif:XResolution");
603 (void) DeleteImageProperty(image,
"exif:YResolution");
604 (void) DeleteImageProperty(image,
"exif:ResolutionUnit");
608 (void) DeleteImageProperty(image,
"tiff:XResolution");
609 (void) DeleteImageProperty(image,
"tiff:YResolution");
610 (void) DeleteImageProperty(image,
"tiff:ResolutionUnit");
619 filename[MagickPathExtent],
620 magick[MagickPathExtent],
621 magick_filename[MagickPathExtent];
651 assert(image_info != (
ImageInfo *) NULL);
652 assert(image_info->signature == MagickCoreSignature);
653 assert(image_info->filename != (
char *) NULL);
654 if (IsEventLogging() != MagickFalse)
655 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
656 image_info->filename);
658 read_info=CloneImageInfo(image_info);
659 (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
660 (void) SetImageInfo(read_info,0,exception);
661 (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
662 (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
666 sans_exception=AcquireExceptionInfo();
667 magick_info=GetMagickInfo(read_info->magick,sans_exception);
668 if (sans_exception->severity == PolicyError)
669 InheritException(exception,sans_exception);
670 sans_exception=DestroyExceptionInfo(sans_exception);
673 if (GetMagickEndianSupport(magick_info) == MagickFalse)
674 read_info->endian=UndefinedEndian;
676 if ((image_info->endian == UndefinedEndian) &&
677 (GetMagickRawSupport(magick_info) != MagickFalse))
683 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
687 if ((magick_info != (
const MagickInfo *) NULL) &&
688 (GetMagickDecoderSeekableStream(magick_info) != MagickFalse))
690 image=AcquireImage(read_info,exception);
691 (void) CopyMagickString(image->filename,read_info->filename,
693 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
694 if (status == MagickFalse)
696 read_info=DestroyImageInfo(read_info);
697 image=DestroyImage(image);
698 return((
Image *) NULL);
700 if (IsBlobSeekable(image) == MagickFalse)
705 *read_info->filename=
'\0';
706 status=ImageToFile(image,read_info->filename,exception);
707 if (status == MagickFalse)
709 (void) CloseBlob(image);
710 read_info=DestroyImageInfo(read_info);
711 image=DestroyImage(image);
712 return((
Image *) NULL);
714 read_info->temporary=MagickTrue;
716 (void) CloseBlob(image);
717 image=DestroyImage(image);
719 image=NewImageList();
720 decoder=GetImageDecoder(magick_info);
721 if (decoder == (DecodeImageHandler *) NULL)
723 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
726 (void) SetImageInfo(read_info,0,exception);
727 (void) CopyMagickString(read_info->filename,filename,
729 magick_info=GetMagickInfo(read_info->magick,exception);
730 decoder=GetImageDecoder(magick_info);
733 if (decoder != (DecodeImageHandler *) NULL)
738 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
739 LockSemaphoreInfo(magick_info->semaphore);
740 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
741 ReadPolicyRights,exception);
742 image=(
Image *) NULL;
743 if (status != MagickFalse)
744 image=decoder(read_info,exception);
745 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
746 UnlockSemaphoreInfo(magick_info->semaphore);
750 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
753 (void) ThrowMagickException(exception,GetMagickModule(),
754 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
755 read_info->filename);
756 if (read_info->temporary != MagickFalse)
757 (void) RelinquishUniqueFileResource(read_info->filename);
758 read_info=DestroyImageInfo(read_info);
759 return((
Image *) NULL);
764 image=AcquireImage(read_info,exception);
765 if (image == (
Image *) NULL)
767 read_info=DestroyImageInfo(read_info);
768 return((
Image *) NULL);
770 (void) CopyMagickString(image->filename,read_info->filename,
772 *read_info->filename=
'\0';
773 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
774 LockSemaphoreInfo(delegate_info->semaphore);
775 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
777 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
778 UnlockSemaphoreInfo(delegate_info->semaphore);
779 image=DestroyImageList(image);
780 read_info->temporary=MagickTrue;
781 if (status != MagickFalse)
782 (void) SetImageInfo(read_info,0,exception);
783 magick_info=GetMagickInfo(read_info->magick,exception);
784 decoder=GetImageDecoder(magick_info);
785 if (decoder == (DecodeImageHandler *) NULL)
787 if (IsPathAccessible(read_info->filename) != MagickFalse)
788 (void) ThrowMagickException(exception,GetMagickModule(),
789 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
792 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
793 read_info->filename);
794 read_info=DestroyImageInfo(read_info);
795 return((
Image *) NULL);
800 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
801 LockSemaphoreInfo(magick_info->semaphore);
802 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
803 ReadPolicyRights,exception);
804 image=(
Image *) NULL;
805 if (status != MagickFalse)
806 image=(decoder)(read_info,exception);
807 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
808 UnlockSemaphoreInfo(magick_info->semaphore);
810 if (read_info->temporary != MagickFalse)
812 (void) RelinquishUniqueFileResource(read_info->filename);
813 read_info->temporary=MagickFalse;
814 if (image != (
Image *) NULL)
815 (
void) CopyMagickString(image->filename,filename,MagickPathExtent);
817 if (image == (
Image *) NULL)
819 read_info=DestroyImageInfo(read_info);
822 if (exception->severity >= ErrorException)
823 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
824 "Coder (%s) generated an image despite an error (%d), "
825 "notify the developers",image->magick,exception->severity);
826 if (IsBlobTemporary(image) != MagickFalse)
827 (
void) RelinquishUniqueFileResource(read_info->filename);
828 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
829 (GetImageListLength(image) != 1))
834 clones=CloneImages(image,read_info->scenes,exception);
835 image=DestroyImageList(image);
836 if (clones != (
Image *) NULL)
837 image=GetFirstImageInList(clones);
838 if (image == (
Image *) NULL)
840 read_info=DestroyImageInfo(read_info);
844 InitializeConstituteInfo(read_info,&constitute_info);
845 for (next=image; next != (
Image *) NULL; next=GetNextImageInList(next))
848 magick_path[MagickPathExtent],
854 next->taint=MagickFalse;
855 GetPathComponent(magick_filename,MagickPath,magick_path);
856 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
857 (void) CopyMagickString(next->magick,magick,MagickPathExtent);
858 (void) CopyMagickString(next->magick_filename,magick_filename,
860 if (IsBlobTemporary(image) != MagickFalse)
861 (
void) CopyMagickString(next->filename,filename,MagickPathExtent);
862 if (next->magick_columns == 0)
863 next->magick_columns=next->columns;
864 if (next->magick_rows == 0)
865 next->magick_rows=next->rows;
866 (void) GetImageProperty(next,
"exif:*",exception);
867 (void) GetImageProperty(next,
"icc:*",exception);
868 (void) GetImageProperty(next,
"iptc:*",exception);
869 (void) GetImageProperty(next,
"xmp:*",exception);
870 SyncOrientationFromProperties(next,&constitute_info,exception);
871 SyncResolutionFromProperties(next,&constitute_info,exception);
872 if (next->page.width == 0)
873 next->page.width=next->columns;
874 if (next->page.height == 0)
875 next->page.height=next->rows;
876 if (constitute_info.caption != (
const char *) NULL)
878 property=InterpretImageProperties(read_info,next,
879 constitute_info.caption,exception);
880 (void) SetImageProperty(next,
"caption",property,exception);
881 property=DestroyString(property);
883 if (constitute_info.comment != (
const char *) NULL)
885 property=InterpretImageProperties(read_info,next,
886 constitute_info.comment,exception);
887 (void) SetImageProperty(next,
"comment",property,exception);
888 property=DestroyString(property);
890 if (constitute_info.label != (
const char *) NULL)
892 property=InterpretImageProperties(read_info,next,
893 constitute_info.label,exception);
894 (void) SetImageProperty(next,
"label",property,exception);
895 property=DestroyString(property);
897 if (LocaleCompare(next->magick,
"TEXT") == 0)
898 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
899 if ((read_info->extract != (
char *) NULL) &&
900 (read_info->stream == (StreamHandler) NULL))
908 SetGeometry(next,&geometry);
909 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
910 if ((next->columns != geometry.width) ||
911 (next->rows != geometry.height))
913 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
915 Image *crop_image = CropImage(next,&geometry,exception);
916 if (crop_image != (
Image *) NULL)
917 ReplaceImageInList(&next,crop_image);
920 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
922 flags=ParseRegionGeometry(next,read_info->extract,&geometry,
924 if ((geometry.width != 0) && (geometry.height != 0))
926 Image *resize_image = ResizeImage(next,geometry.width,
927 geometry.height,next->filter,exception);
928 if (resize_image != (
Image *) NULL)
929 ReplaceImageInList(&next,resize_image);
934 profile=GetImageProfile(next,
"icc");
936 profile=GetImageProfile(next,
"icm");
937 profile=GetImageProfile(next,
"iptc");
939 profile=GetImageProfile(next,
"8bim");
940 if (IsSourceDataEpochSet() == MagickFalse)
943 timestamp[MagickTimeExtent];
945 (void) FormatMagickTime(next->timestamp,
sizeof(timestamp),timestamp);
946 (void) SetImageProperty(next,
"date:timestamp",timestamp,exception);
947 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
948 sizeof(timestamp),timestamp);
949 (void) SetImageProperty(next,
"date:modify",timestamp,exception);
950 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
951 sizeof(timestamp),timestamp);
952 (void) SetImageProperty(next,
"date:create",timestamp,exception);
954 if (constitute_info.delay_flags != NoValue)
956 if ((constitute_info.delay_flags & GreaterValue) != 0)
958 if (next->delay > constitute_info.delay)
959 next->delay=constitute_info.delay;
962 if ((constitute_info.delay_flags & LessValue) != 0)
964 if (next->delay < constitute_info.delay)
965 next->delay=constitute_info.delay;
968 next->delay=constitute_info.delay;
969 if ((constitute_info.delay_flags & SigmaValue) != 0)
970 next->ticks_per_second=constitute_info.ticks_per_second;
972 if (constitute_info.dispose != (
const char *) NULL)
977 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
978 constitute_info.dispose);
979 if (option_type >= 0)
980 next->dispose=(DisposeType) option_type;
982 if (read_info->verbose != MagickFalse)
983 (void) IdentifyImage(next,stderr,MagickFalse,exception);
986 read_info=DestroyImageInfo(read_info);
987 if (GetBlobError(image) != MagickFalse)
988 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
989 return(GetFirstImageInList(image));
1019MagickExport
Image *ReadImages(
ImageInfo *image_info,
const char *filename,
1023 read_filename[MagickPathExtent];
1035 assert(image_info != (
ImageInfo *) NULL);
1036 assert(image_info->signature == MagickCoreSignature);
1038 if (IsEventLogging() != MagickFalse)
1039 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1040 image_info->filename);
1041 read_info=CloneImageInfo(image_info);
1042 *read_info->magick=
'\0';
1043 (void) SetImageOption(read_info,
"filename",filename);
1044 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1045 (void) InterpretImageFilename(read_info,(
Image *) NULL,filename,
1046 (int) read_info->scene,read_filename,exception);
1047 if (LocaleCompare(read_filename,read_info->filename) != 0)
1059 sans=AcquireExceptionInfo();
1060 (void) SetImageInfo(read_info,0,sans);
1061 sans=DestroyExceptionInfo(sans);
1062 if (read_info->number_scenes != 0)
1064 (void) CopyMagickString(read_filename,read_info->filename,
1066 images=NewImageList();
1067 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
1068 scene=(ssize_t) read_info->scene;
1069 for ( ; scene < (ssize_t) extent; scene++)
1071 (void) InterpretImageFilename(image_info,(
Image *) NULL,
1072 read_filename,(int) scene,read_info->filename,exception);
1073 image=ReadImage(read_info,exception);
1074 if (image == (
Image *) NULL)
1076 AppendImageToList(&images,image);
1078 read_info=DestroyImageInfo(read_info);
1082 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1083 image=ReadImage(read_info,exception);
1084 read_info=DestroyImageInfo(read_info);
1139 image=NewImageList();
1140 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1142 ThrowReaderException(CorruptImageError,
"CorruptImage");
1143 blob=Base64Decode(++p,&length);
1146 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1147 ThrowReaderException(CorruptImageError,
"CorruptImage");
1149 read_info=CloneImageInfo(image_info);
1150 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1152 *read_info->filename=
'\0';
1153 *read_info->magick=
'\0';
1154 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1166 if (LocaleNCompare(++p,
"x-",2) == 0)
1168 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1169 q=read_info->filename+5;
1170 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1174 image=BlobToImage(read_info,blob,length,exception);
1175 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1176 read_info=DestroyImageInfo(read_info);
1211MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1215 filename[MagickPathExtent];
1242 assert(image_info != (
ImageInfo *) NULL);
1243 assert(image_info->signature == MagickCoreSignature);
1244 assert(image != (
Image *) NULL);
1245 if (IsEventLogging() != MagickFalse)
1246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1247 image_info->filename);
1248 assert(image->signature == MagickCoreSignature);
1250 sans_exception=AcquireExceptionInfo();
1251 write_info=CloneImageInfo(image_info);
1252 (void) CopyMagickString(write_info->filename,image->filename,
1254 (void) SetImageInfo(write_info,1,sans_exception);
1255 if (*write_info->magick ==
'\0')
1256 (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1257 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1258 (void) CopyMagickString(image->filename,write_info->filename,
1263 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1264 if (sans_exception->severity == PolicyError)
1265 magick_info=GetMagickInfo(write_info->magick,exception);
1266 sans_exception=DestroyExceptionInfo(sans_exception);
1267 if (magick_info != (
const MagickInfo *) NULL)
1269 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1270 image->endian=UndefinedEndian;
1272 if ((image_info->endian == UndefinedEndian) &&
1273 (GetMagickRawSupport(magick_info) != MagickFalse))
1279 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1282 if (SyncImagePixelCache(image,exception) == MagickFalse)
1284 write_info=DestroyImageInfo(write_info);
1285 return(MagickFalse);
1287 SyncImageProfiles(image);
1288 DisassociateImageStream(image);
1289 option=GetImageOption(image_info,
"delegate:bimodal");
1290 if ((IsStringTrue(option) != MagickFalse) &&
1291 (write_info->page == (
char *) NULL) &&
1292 (GetPreviousImageInList(image) == (
Image *) NULL) &&
1293 (GetNextImageInList(image) == (
Image *) NULL) &&
1294 (IsTaintImage(image) == MagickFalse) )
1296 delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1298 (GetDelegateMode(delegate_info) == 0) &&
1299 (IsPathAccessible(image->magick_filename) != MagickFalse))
1304 (void) CopyMagickString(image->filename,image->magick_filename,
1306 status=InvokeDelegate(write_info,image,image->magick,
1307 write_info->magick,exception);
1308 write_info=DestroyImageInfo(write_info);
1309 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1314 temporary=MagickFalse;
1315 if ((magick_info != (
const MagickInfo *) NULL) &&
1316 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1319 image_filename[MagickPathExtent];
1321 (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1322 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1323 (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1324 if (status != MagickFalse)
1326 if (IsBlobSeekable(image) == MagickFalse)
1331 write_info->adjoin=MagickTrue;
1332 (void) CopyMagickString(write_info->filename,image->filename,
1334 (void) AcquireUniqueFilename(image->filename);
1335 temporary=MagickTrue;
1337 if (CloseBlob(image) == MagickFalse)
1341 encoder=GetImageEncoder(magick_info);
1342 if (encoder != (EncodeImageHandler *) NULL)
1347 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1348 LockSemaphoreInfo(magick_info->semaphore);
1349 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1350 WritePolicyRights,exception);
1351 if (status != MagickFalse)
1352 status=encoder(write_info,image,exception);
1353 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1354 UnlockSemaphoreInfo(magick_info->semaphore);
1358 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,exception);
1364 *write_info->filename=
'\0';
1365 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1366 LockSemaphoreInfo(delegate_info->semaphore);
1367 status=InvokeDelegate(write_info,image,(
char *) NULL,
1368 write_info->magick,exception);
1369 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1370 UnlockSemaphoreInfo(delegate_info->semaphore);
1371 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1375 sans_exception=AcquireExceptionInfo();
1376 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1377 if (sans_exception->severity == PolicyError)
1378 magick_info=GetMagickInfo(write_info->magick,exception);
1379 sans_exception=DestroyExceptionInfo(sans_exception);
1380 if ((write_info->affirm == MagickFalse) &&
1383 (void) CopyMagickString(write_info->magick,image->magick,
1385 magick_info=GetMagickInfo(write_info->magick,exception);
1387 encoder=GetImageEncoder(magick_info);
1388 if (encoder == (EncodeImageHandler *) NULL)
1391 extension[MagickPathExtent];
1393 GetPathComponent(image->filename,ExtensionPath,extension);
1394 if (*extension !=
'\0')
1395 magick_info=GetMagickInfo(extension,exception);
1397 magick_info=GetMagickInfo(image->magick,exception);
1398 (void) CopyMagickString(image->filename,filename,
1400 encoder=GetImageEncoder(magick_info);
1401 (void) ThrowMagickException(exception,GetMagickModule(),
1402 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1403 "`%s'",write_info->magick);
1405 if (encoder == (EncodeImageHandler *) NULL)
1407 magick_info=GetMagickInfo(image->magick,exception);
1408 encoder=GetImageEncoder(magick_info);
1409 if (encoder == (EncodeImageHandler *) NULL)
1410 (void) ThrowMagickException(exception,GetMagickModule(),
1411 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1412 "`%s'",write_info->magick);
1414 if (encoder != (EncodeImageHandler *) NULL)
1419 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1420 LockSemaphoreInfo(magick_info->semaphore);
1421 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1422 WritePolicyRights,exception);
1423 if (status != MagickFalse)
1424 status=encoder(write_info,image,exception);
1425 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1426 UnlockSemaphoreInfo(magick_info->semaphore);
1430 if (temporary != MagickFalse)
1435 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1436 if (status != MagickFalse)
1438 (void) RelinquishUniqueFileResource(write_info->filename);
1439 status=ImageToFile(image,write_info->filename,exception);
1441 if (CloseBlob(image) == MagickFalse)
1443 (void) RelinquishUniqueFileResource(image->filename);
1444 (void) CopyMagickString(image->filename,write_info->filename,
1447 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1448 (write_info->verbose != MagickFalse))
1449 (
void) IdentifyImage(image,stdout,MagickFalse,exception);
1450 write_info=DestroyImageInfo(write_info);
1451 if (GetBlobError(image) != MagickFalse)
1452 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1492MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1495#define WriteImageTag "Write/Image"
1509 MagickProgressMonitor
1521 assert(image_info != (
const ImageInfo *) NULL);
1522 assert(image_info->signature == MagickCoreSignature);
1523 assert(images != (
Image *) NULL);
1524 assert(images->signature == MagickCoreSignature);
1525 if (IsEventLogging() != MagickFalse)
1526 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1528 write_info=CloneImageInfo(image_info);
1529 *write_info->magick=
'\0';
1530 images=GetFirstImageInList(images);
1531 if (images == (
Image *) NULL)
1532 return(MagickFalse);
1533 if (filename != (
const char *) NULL)
1534 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1535 (
void) CopyMagickString(p->filename,filename,MagickPathExtent);
1536 (void) CopyMagickString(write_info->filename,images->filename,
1538 sans_exception=AcquireExceptionInfo();
1539 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1541 sans_exception=DestroyExceptionInfo(sans_exception);
1542 if (*write_info->magick ==
'\0')
1543 (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1545 for ( ; GetNextImageInList(p) != (
Image *) NULL; p=GetNextImageInList(p))
1547 if (p->scene >= GetNextImageInList(p)->scene)
1555 i=(ssize_t) images->scene;
1556 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1557 p->scene=(
size_t) i++;
1565 progress_monitor=(MagickProgressMonitor) NULL;
1567 number_images=GetImageListLength(images);
1568 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1570 if (number_images != 1)
1571 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1573 status&=(MagickStatusType) WriteImage(write_info,p,exception);
1574 if (number_images != 1)
1575 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1576 if (write_info->adjoin != MagickFalse)
1578 if (number_images != 1)
1580#if defined(MAGICKCORE_OPENMP_SUPPORT)
1584 proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1585 if (proceed == MagickFalse)
1589 write_info=DestroyImageInfo(write_info);
1590 return(status != 0 ? MagickTrue : MagickFalse);