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 *module,
449 const char *coder,
const PolicyRights rights,
ExceptionInfo *exception)
451 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
454 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
455 "NotAuthorized",
"`%s'",coder);
458 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
461 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
462 "NotAuthorized",
"`%s'",module);
468static void InitializeConstituteInfo(
const ImageInfo *image_info,
474 memset(constitute_info,0,
sizeof(*constitute_info));
475 constitute_info->sync_from_exif=MagickTrue;
476 constitute_info->sync_from_tiff=MagickTrue;
477 option=GetImageOption(image_info,
"exif:sync-image");
478 if (IsStringFalse(option) != MagickFalse)
479 constitute_info->sync_from_exif=MagickFalse;
480 option=GetImageOption(image_info,
"tiff:sync-image");
481 if (IsStringFalse(option) != MagickFalse)
482 constitute_info->sync_from_tiff=MagickFalse;
483 constitute_info->caption=GetImageOption(image_info,
"caption");
484 constitute_info->comment=GetImageOption(image_info,
"comment");
485 constitute_info->label=GetImageOption(image_info,
"label");
486 option=GetImageOption(image_info,
"delay");
487 if (option != (
const char *) NULL)
492 constitute_info->delay_flags=ParseGeometry(option,&geometry_info);
493 if (constitute_info->delay_flags != NoValue)
495 constitute_info->delay=floor(geometry_info.rho+0.5);
496 if ((constitute_info->delay_flags & SigmaValue) != 0)
497 constitute_info->ticks_per_second=CastDoubleToLong(floor(
498 geometry_info.sigma+0.5));
503static void SyncOrientationFromProperties(
Image *image,
509 orientation=(
const char *) NULL;
510 if (constitute_info->sync_from_exif != MagickFalse)
512 orientation=GetImageProperty(image,
"exif:Orientation",exception);
513 if (orientation != (
const char *) NULL)
515 image->orientation=(OrientationType) StringToLong(orientation);
516 (void) DeleteImageProperty(image,
"exif:Orientation");
519 if ((orientation == (
const char *) NULL) &&
520 (constitute_info->sync_from_tiff != MagickFalse))
522 orientation=GetImageProperty(image,
"tiff:Orientation",exception);
523 if (orientation != (
const char *) NULL)
525 image->orientation=(OrientationType) StringToLong(orientation);
526 (void) DeleteImageProperty(image,
"tiff:Orientation");
531static void SyncResolutionFromProperties(
Image *image,
542 resolution_x=(
const char *) NULL;
543 resolution_y=(
const char *) NULL;
544 resolution_units=(
const char *) NULL;
545 used_tiff=MagickFalse;
546 if (constitute_info->sync_from_exif != MagickFalse)
548 resolution_x=GetImageProperty(image,
"exif:XResolution",exception);
549 resolution_y=GetImageProperty(image,
"exif:YResolution",exception);
550 if ((resolution_x != (
const char *) NULL) &&
551 (resolution_y != (
const char *) NULL))
552 resolution_units=GetImageProperty(image,
"exif:ResolutionUnit",
555 if ((resolution_x == (
const char *) NULL) &&
556 (resolution_y == (
const char *) NULL) &&
557 (constitute_info->sync_from_tiff != MagickFalse))
559 resolution_x=GetImageProperty(image,
"tiff:XResolution",exception);
560 resolution_y=GetImageProperty(image,
"tiff:YResolution",exception);
561 if ((resolution_x != (
const char *) NULL) &&
562 (resolution_y != (
const char *) NULL))
564 used_tiff=MagickTrue;
565 resolution_units=GetImageProperty(image,
"tiff:ResolutionUnit",
569 if ((resolution_x != (
const char *) NULL) &&
570 (resolution_y != (
const char *) NULL))
578 geometry_info.rho=image->resolution.x;
579 geometry_info.sigma=1.0;
580 (void) ParseGeometry(resolution_x,&geometry_info);
581 if (geometry_info.sigma != 0)
582 image->resolution.x=geometry_info.rho/geometry_info.sigma;
583 if (strchr(resolution_x,
',') != (
char *) NULL)
584 image->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
585 geometry_info.rho=image->resolution.y;
586 geometry_info.sigma=1.0;
587 (void) ParseGeometry(resolution_y,&geometry_info);
588 if (geometry_info.sigma != 0)
589 image->resolution.y=geometry_info.rho/geometry_info.sigma;
590 if (strchr(resolution_y,
',') != (
char *) NULL)
591 image->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
592 if (resolution_units != (
char *) NULL)
594 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
596 if (option_type >= 0)
597 image->units=(ResolutionType) option_type;
599 if (used_tiff == MagickFalse)
601 (void) DeleteImageProperty(image,
"exif:XResolution");
602 (void) DeleteImageProperty(image,
"exif:YResolution");
603 (void) DeleteImageProperty(image,
"exif:ResolutionUnit");
607 (void) DeleteImageProperty(image,
"tiff:XResolution");
608 (void) DeleteImageProperty(image,
"tiff:YResolution");
609 (void) DeleteImageProperty(image,
"tiff:ResolutionUnit");
618 filename[MagickPathExtent],
619 magick[MagickPathExtent],
620 magick_filename[MagickPathExtent];
650 assert(image_info != (
ImageInfo *) NULL);
651 assert(image_info->signature == MagickCoreSignature);
652 assert(image_info->filename != (
char *) NULL);
653 if (IsEventLogging() != MagickFalse)
654 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
655 image_info->filename);
657 read_info=CloneImageInfo(image_info);
658 (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
659 (void) SetImageInfo(read_info,0,exception);
660 (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
661 (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
665 sans_exception=AcquireExceptionInfo();
666 magick_info=GetMagickInfo(read_info->magick,sans_exception);
667 if (sans_exception->severity == PolicyError)
668 InheritException(exception,sans_exception);
669 sans_exception=DestroyExceptionInfo(sans_exception);
672 if (GetMagickEndianSupport(magick_info) == MagickFalse)
673 read_info->endian=UndefinedEndian;
675 if ((image_info->endian == UndefinedEndian) &&
676 (GetMagickRawSupport(magick_info) != MagickFalse))
682 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
686 if ((magick_info != (
const MagickInfo *) NULL) &&
687 (GetMagickDecoderSeekableStream(magick_info) != MagickFalse))
689 image=AcquireImage(read_info,exception);
690 (void) CopyMagickString(image->filename,read_info->filename,
692 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
693 if (status == MagickFalse)
695 read_info=DestroyImageInfo(read_info);
696 image=DestroyImage(image);
697 return((
Image *) NULL);
699 if (IsBlobSeekable(image) == MagickFalse)
704 *read_info->filename=
'\0';
705 status=ImageToFile(image,read_info->filename,exception);
706 if (status == MagickFalse)
708 (void) CloseBlob(image);
709 read_info=DestroyImageInfo(read_info);
710 image=DestroyImage(image);
711 return((
Image *) NULL);
713 read_info->temporary=MagickTrue;
715 (void) CloseBlob(image);
716 image=DestroyImage(image);
718 image=NewImageList();
719 decoder=GetImageDecoder(magick_info);
720 if (decoder == (DecodeImageHandler *) NULL)
722 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
725 (void) SetImageInfo(read_info,0,exception);
726 (void) CopyMagickString(read_info->filename,filename,
728 magick_info=GetMagickInfo(read_info->magick,exception);
729 decoder=GetImageDecoder(magick_info);
732 if (decoder != (DecodeImageHandler *) NULL)
737 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
738 LockSemaphoreInfo(magick_info->semaphore);
739 status=IsCoderAuthorized(magick_info->magick_module,magick_info->name,
740 ReadPolicyRights,exception);
741 image=(
Image *) NULL;
742 if (status != MagickFalse)
743 image=decoder(read_info,exception);
744 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
745 UnlockSemaphoreInfo(magick_info->semaphore);
749 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
752 (void) ThrowMagickException(exception,GetMagickModule(),
753 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
755 if (read_info->temporary != MagickFalse)
756 (void) RelinquishUniqueFileResource(read_info->filename);
757 read_info=DestroyImageInfo(read_info);
758 return((
Image *) NULL);
763 image=AcquireImage(read_info,exception);
764 if (image == (
Image *) NULL)
766 read_info=DestroyImageInfo(read_info);
767 return((
Image *) NULL);
769 (void) CopyMagickString(image->filename,read_info->filename,
771 *read_info->filename=
'\0';
772 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
773 LockSemaphoreInfo(delegate_info->semaphore);
774 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
776 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
777 UnlockSemaphoreInfo(delegate_info->semaphore);
778 image=DestroyImageList(image);
779 read_info->temporary=MagickTrue;
780 if (status != MagickFalse)
781 (void) SetImageInfo(read_info,0,exception);
782 magick_info=GetMagickInfo(read_info->magick,exception);
783 decoder=GetImageDecoder(magick_info);
784 if (decoder == (DecodeImageHandler *) NULL)
786 if (IsPathAccessible(read_info->filename) != MagickFalse)
787 (void) ThrowMagickException(exception,GetMagickModule(),
788 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
791 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
792 read_info->filename);
793 read_info=DestroyImageInfo(read_info);
794 return((
Image *) NULL);
799 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
800 LockSemaphoreInfo(magick_info->semaphore);
801 status=IsCoderAuthorized(magick_info->magick_module,magick_info->name,
802 ReadPolicyRights,exception);
803 image=(
Image *) NULL;
804 if (status != MagickFalse)
805 image=(decoder)(read_info,exception);
806 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
807 UnlockSemaphoreInfo(magick_info->semaphore);
809 if (read_info->temporary != MagickFalse)
811 (void) RelinquishUniqueFileResource(read_info->filename);
812 read_info->temporary=MagickFalse;
813 if (image != (
Image *) NULL)
814 (
void) CopyMagickString(image->filename,filename,MagickPathExtent);
816 if (image == (
Image *) NULL)
818 read_info=DestroyImageInfo(read_info);
821 if (exception->severity >= ErrorException)
822 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
823 "Coder (%s) generated an image despite an error (%d), "
824 "notify the developers",image->magick,exception->severity);
825 if (IsBlobTemporary(image) != MagickFalse)
826 (
void) RelinquishUniqueFileResource(read_info->filename);
827 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
828 (GetImageListLength(image) != 1))
833 clones=CloneImages(image,read_info->scenes,exception);
834 image=DestroyImageList(image);
835 if (clones != (
Image *) NULL)
836 image=GetFirstImageInList(clones);
837 if (image == (
Image *) NULL)
839 read_info=DestroyImageInfo(read_info);
843 InitializeConstituteInfo(read_info,&constitute_info);
844 for (next=image; next != (
Image *) NULL; next=GetNextImageInList(next))
847 magick_path[MagickPathExtent],
854 *source_date_epoch = (
const char *) NULL;
856 static MagickBooleanType
857 epoch_initialized = MagickFalse;
859 next->taint=MagickFalse;
860 GetPathComponent(magick_filename,MagickPath,magick_path);
861 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
862 (void) CopyMagickString(next->magick,magick,MagickPathExtent);
863 (void) CopyMagickString(next->magick_filename,magick_filename,
865 if (IsBlobTemporary(image) != MagickFalse)
866 (
void) CopyMagickString(next->filename,filename,MagickPathExtent);
867 if (next->magick_columns == 0)
868 next->magick_columns=next->columns;
869 if (next->magick_rows == 0)
870 next->magick_rows=next->rows;
871 (void) GetImageProperty(next,
"exif:*",exception);
872 (void) GetImageProperty(next,
"icc:*",exception);
873 (void) GetImageProperty(next,
"iptc:*",exception);
874 (void) GetImageProperty(next,
"xmp:*",exception);
875 SyncOrientationFromProperties(next,&constitute_info,exception);
876 SyncResolutionFromProperties(next,&constitute_info,exception);
877 if (next->page.width == 0)
878 next->page.width=next->columns;
879 if (next->page.height == 0)
880 next->page.height=next->rows;
881 if (constitute_info.caption != (
const char *) NULL)
883 property=InterpretImageProperties(read_info,next,
884 constitute_info.caption,exception);
885 (void) SetImageProperty(next,
"caption",property,exception);
886 property=DestroyString(property);
888 if (constitute_info.comment != (
const char *) NULL)
890 property=InterpretImageProperties(read_info,next,
891 constitute_info.comment,exception);
892 (void) SetImageProperty(next,
"comment",property,exception);
893 property=DestroyString(property);
895 if (constitute_info.label != (
const char *) NULL)
897 property=InterpretImageProperties(read_info,next,
898 constitute_info.label,exception);
899 (void) SetImageProperty(next,
"label",property,exception);
900 property=DestroyString(property);
902 if (LocaleCompare(next->magick,
"TEXT") == 0)
903 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
904 if ((read_info->extract != (
char *) NULL) &&
905 (read_info->stream == (StreamHandler) NULL))
913 SetGeometry(next,&geometry);
914 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
915 if ((next->columns != geometry.width) ||
916 (next->rows != geometry.height))
918 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
923 crop_image=CropImage(next,&geometry,exception);
924 if (crop_image != (
Image *) NULL)
925 ReplaceImageInList(&next,crop_image);
928 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
930 flags=ParseRegionGeometry(next,read_info->extract,&geometry,
932 if ((geometry.width != 0) && (geometry.height != 0))
934 Image *resize_image = ResizeImage(next,geometry.width,
935 geometry.height,next->filter,exception);
936 if (resize_image != (
Image *) NULL)
937 ReplaceImageInList(&next,resize_image);
942 profile=GetImageProfile(next,
"icc");
944 profile=GetImageProfile(next,
"icm");
945 profile=GetImageProfile(next,
"iptc");
947 profile=GetImageProfile(next,
"8bim");
948 if (epoch_initialized == MagickFalse)
950 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
951 epoch_initialized=MagickTrue;
953 if (source_date_epoch == (
const char *) NULL)
956 timestamp[MagickTimeExtent];
958 (void) FormatMagickTime(next->timestamp,
sizeof(timestamp),timestamp);
959 (void) SetImageProperty(next,
"date:timestamp",timestamp,exception);
960 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
961 sizeof(timestamp),timestamp);
962 (void) SetImageProperty(next,
"date:modify",timestamp,exception);
963 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
964 sizeof(timestamp),timestamp);
965 (void) SetImageProperty(next,
"date:create",timestamp,exception);
967 if (constitute_info.delay_flags != NoValue)
969 if ((constitute_info.delay_flags & GreaterValue) != 0)
971 if (next->delay > constitute_info.delay)
972 next->delay=constitute_info.delay;
975 if ((constitute_info.delay_flags & LessValue) != 0)
977 if (next->delay < constitute_info.delay)
978 next->delay=constitute_info.delay;
981 next->delay=constitute_info.delay;
982 if ((constitute_info.delay_flags & SigmaValue) != 0)
983 next->ticks_per_second=constitute_info.ticks_per_second;
985 if (constitute_info.dispose != (
const char *) NULL)
990 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
991 constitute_info.dispose);
992 if (option_type >= 0)
993 next->dispose=(DisposeType) option_type;
995 if (read_info->verbose != MagickFalse)
996 (void) IdentifyImage(next,stderr,MagickFalse,exception);
999 read_info=DestroyImageInfo(read_info);
1000 if (GetBlobError(image) != MagickFalse)
1001 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
1002 return(GetFirstImageInList(image));
1032MagickExport
Image *ReadImages(
ImageInfo *image_info,
const char *filename,
1036 read_filename[MagickPathExtent];
1048 assert(image_info != (
ImageInfo *) NULL);
1049 assert(image_info->signature == MagickCoreSignature);
1051 if (IsEventLogging() != MagickFalse)
1052 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1053 image_info->filename);
1054 read_info=CloneImageInfo(image_info);
1055 *read_info->magick=
'\0';
1056 (void) SetImageOption(read_info,
"filename",filename);
1057 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1058 (void) InterpretImageFilename(read_info,(
Image *) NULL,filename,
1059 (int) read_info->scene,read_filename,exception);
1060 if (LocaleCompare(read_filename,read_info->filename) != 0)
1072 sans=AcquireExceptionInfo();
1073 (void) SetImageInfo(read_info,0,sans);
1074 sans=DestroyExceptionInfo(sans);
1075 if (read_info->number_scenes != 0)
1077 (void) CopyMagickString(read_filename,read_info->filename,
1079 images=NewImageList();
1080 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
1081 scene=(ssize_t) read_info->scene;
1082 for ( ; scene < (ssize_t) extent; scene++)
1084 (void) InterpretImageFilename(image_info,(
Image *) NULL,
1085 read_filename,(int) scene,read_info->filename,exception);
1086 image=ReadImage(read_info,exception);
1087 if (image == (
Image *) NULL)
1089 AppendImageToList(&images,image);
1091 read_info=DestroyImageInfo(read_info);
1095 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1096 image=ReadImage(read_info,exception);
1097 read_info=DestroyImageInfo(read_info);
1152 image=NewImageList();
1153 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1155 ThrowReaderException(CorruptImageError,
"CorruptImage");
1156 blob=Base64Decode(++p,&length);
1159 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1160 ThrowReaderException(CorruptImageError,
"CorruptImage");
1162 read_info=CloneImageInfo(image_info);
1163 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1165 *read_info->filename=
'\0';
1166 *read_info->magick=
'\0';
1167 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1179 if (LocaleNCompare(++p,
"x-",2) == 0)
1181 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1182 q=read_info->filename+5;
1183 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1187 image=BlobToImage(read_info,blob,length,exception);
1188 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1189 read_info=DestroyImageInfo(read_info);
1224MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1228 filename[MagickPathExtent];
1255 assert(image_info != (
ImageInfo *) NULL);
1256 assert(image_info->signature == MagickCoreSignature);
1257 assert(image != (
Image *) NULL);
1258 if (IsEventLogging() != MagickFalse)
1259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1260 image_info->filename);
1261 assert(image->signature == MagickCoreSignature);
1263 sans_exception=AcquireExceptionInfo();
1264 write_info=CloneImageInfo(image_info);
1265 (void) CopyMagickString(write_info->filename,image->filename,
1267 (void) SetImageInfo(write_info,1,sans_exception);
1268 if (*write_info->magick ==
'\0')
1269 (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1270 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1271 (void) CopyMagickString(image->filename,write_info->filename,
1276 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1277 if (sans_exception->severity == PolicyError)
1278 magick_info=GetMagickInfo(write_info->magick,exception);
1279 sans_exception=DestroyExceptionInfo(sans_exception);
1280 if (magick_info != (
const MagickInfo *) NULL)
1282 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1283 image->endian=UndefinedEndian;
1285 if ((image_info->endian == UndefinedEndian) &&
1286 (GetMagickRawSupport(magick_info) != MagickFalse))
1292 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1295 SyncImageProfiles(image);
1296 DisassociateImageStream(image);
1297 option=GetImageOption(image_info,
"delegate:bimodal");
1298 if ((IsStringTrue(option) != MagickFalse) &&
1299 (write_info->page == (
char *) NULL) &&
1300 (GetPreviousImageInList(image) == (
Image *) NULL) &&
1301 (GetNextImageInList(image) == (
Image *) NULL) &&
1302 (IsTaintImage(image) == MagickFalse) )
1304 delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1306 (GetDelegateMode(delegate_info) == 0) &&
1307 (IsPathAccessible(image->magick_filename) != MagickFalse))
1312 (void) CopyMagickString(image->filename,image->magick_filename,
1314 status=InvokeDelegate(write_info,image,image->magick,
1315 write_info->magick,exception);
1316 write_info=DestroyImageInfo(write_info);
1317 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1322 temporary=MagickFalse;
1323 if ((magick_info != (
const MagickInfo *) NULL) &&
1324 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1327 image_filename[MagickPathExtent];
1329 (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1330 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1331 (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1332 if (status != MagickFalse)
1334 if (IsBlobSeekable(image) == MagickFalse)
1339 write_info->adjoin=MagickTrue;
1340 (void) CopyMagickString(write_info->filename,image->filename,
1342 (void) AcquireUniqueFilename(image->filename);
1343 temporary=MagickTrue;
1345 if (CloseBlob(image) == MagickFalse)
1349 encoder=GetImageEncoder(magick_info);
1350 if (encoder != (EncodeImageHandler *) NULL)
1355 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1356 LockSemaphoreInfo(magick_info->semaphore);
1357 status=IsCoderAuthorized(magick_info->magick_module,magick_info->name,
1358 WritePolicyRights,exception);
1359 if (status != MagickFalse)
1360 status=encoder(write_info,image,exception);
1361 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1362 UnlockSemaphoreInfo(magick_info->semaphore);
1366 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,exception);
1372 *write_info->filename=
'\0';
1373 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1374 LockSemaphoreInfo(delegate_info->semaphore);
1375 status=InvokeDelegate(write_info,image,(
char *) NULL,
1376 write_info->magick,exception);
1377 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1378 UnlockSemaphoreInfo(delegate_info->semaphore);
1379 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1383 sans_exception=AcquireExceptionInfo();
1384 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1385 if (sans_exception->severity == PolicyError)
1386 magick_info=GetMagickInfo(write_info->magick,exception);
1387 sans_exception=DestroyExceptionInfo(sans_exception);
1388 if ((write_info->affirm == MagickFalse) &&
1391 (void) CopyMagickString(write_info->magick,image->magick,
1393 magick_info=GetMagickInfo(write_info->magick,exception);
1395 encoder=GetImageEncoder(magick_info);
1396 if (encoder == (EncodeImageHandler *) NULL)
1399 extension[MagickPathExtent];
1401 GetPathComponent(image->filename,ExtensionPath,extension);
1402 if (*extension !=
'\0')
1403 magick_info=GetMagickInfo(extension,exception);
1405 magick_info=GetMagickInfo(image->magick,exception);
1406 (void) CopyMagickString(image->filename,filename,
1408 encoder=GetImageEncoder(magick_info);
1409 (void) ThrowMagickException(exception,GetMagickModule(),
1410 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1411 "`%s'",write_info->magick);
1413 if (encoder == (EncodeImageHandler *) NULL)
1415 magick_info=GetMagickInfo(image->magick,exception);
1416 encoder=GetImageEncoder(magick_info);
1417 if (encoder == (EncodeImageHandler *) NULL)
1418 (void) ThrowMagickException(exception,GetMagickModule(),
1419 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1420 "`%s'",write_info->magick);
1422 if (encoder != (EncodeImageHandler *) NULL)
1427 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1428 LockSemaphoreInfo(magick_info->semaphore);
1429 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1430 WritePolicyRights,exception);
1431 if (status != MagickFalse)
1432 status=encoder(write_info,image,exception);
1433 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1434 UnlockSemaphoreInfo(magick_info->semaphore);
1438 if (temporary != MagickFalse)
1443 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1444 if (status != MagickFalse)
1446 (void) RelinquishUniqueFileResource(write_info->filename);
1447 status=ImageToFile(image,write_info->filename,exception);
1449 if (CloseBlob(image) == MagickFalse)
1451 (void) RelinquishUniqueFileResource(image->filename);
1452 (void) CopyMagickString(image->filename,write_info->filename,
1455 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1456 (write_info->verbose != MagickFalse))
1457 (
void) IdentifyImage(image,stdout,MagickFalse,exception);
1458 write_info=DestroyImageInfo(write_info);
1459 if (GetBlobError(image) != MagickFalse)
1460 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1500MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1503#define WriteImageTag "Write/Image"
1517 MagickProgressMonitor
1529 assert(image_info != (
const ImageInfo *) NULL);
1530 assert(image_info->signature == MagickCoreSignature);
1531 assert(images != (
Image *) NULL);
1532 assert(images->signature == MagickCoreSignature);
1533 if (IsEventLogging() != MagickFalse)
1534 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1536 write_info=CloneImageInfo(image_info);
1537 *write_info->magick=
'\0';
1538 images=GetFirstImageInList(images);
1539 if (images == (
Image *) NULL)
1540 return(MagickFalse);
1541 if (filename != (
const char *) NULL)
1542 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1543 (
void) CopyMagickString(p->filename,filename,MagickPathExtent);
1544 (void) CopyMagickString(write_info->filename,images->filename,
1546 sans_exception=AcquireExceptionInfo();
1547 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1549 sans_exception=DestroyExceptionInfo(sans_exception);
1550 if (*write_info->magick ==
'\0')
1551 (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1553 for ( ; GetNextImageInList(p) != (
Image *) NULL; p=GetNextImageInList(p))
1555 if (p->scene >= GetNextImageInList(p)->scene)
1563 i=(ssize_t) images->scene;
1564 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1565 p->scene=(
size_t) i++;
1573 progress_monitor=(MagickProgressMonitor) NULL;
1575 number_images=GetImageListLength(images);
1576 for (p=images; p != (
Image *) NULL; p=GetNextImageInList(p))
1578 if (number_images != 1)
1579 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1581 status&=(MagickStatusType) WriteImage(write_info,p,exception);
1582 if (write_info->blob != (
void *) NULL)
1583 SyncBlobStream(write_info,p,images);
1584 if (number_images != 1)
1585 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1586 if (write_info->adjoin != MagickFalse)
1588 if (number_images != 1)
1590#if defined(MAGICKCORE_OPENMP_SUPPORT)
1594 proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1595 if (proceed == MagickFalse)
1599 write_info=DestroyImageInfo(write_info);
1600 return(status != 0 ? MagickTrue : MagickFalse);