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/quantum-private.h"
73#include "MagickCore/resize.h"
74#include "MagickCore/resource_.h"
75#include "MagickCore/semaphore.h"
76#include "MagickCore/statistic.h"
77#include "MagickCore/stream.h"
78#include "MagickCore/string_.h"
79#include "MagickCore/string-private.h"
80#include "MagickCore/timer.h"
81#include "MagickCore/timer-private.h"
82#include "MagickCore/token.h"
83#include "MagickCore/transform.h"
84#include "MagickCore/utility.h"
85#include "MagickCore/utility-private.h"
90#define MaxReadRecursionDepth 100
166MagickExport Image *ConstituteImage(
const size_t columns,
const size_t rows,
167 const char *map,
const StorageType storage,
const void *pixels,
168 ExceptionInfo *exception)
185 assert(map != (
const char *) NULL);
186 assert(pixels != (
void *) NULL);
187 assert(exception != (ExceptionInfo *) NULL);
188 assert(exception->signature == MagickCoreSignature);
189 if (IsEventLogging() != MagickFalse)
190 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
191 image=AcquireImage((ImageInfo *) NULL,exception);
192 if (image == (Image *) NULL)
193 return((Image *) NULL);
196 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
197 case DoublePixel: image->depth=8*
sizeof(double);
break;
198 case FloatPixel: image->depth=8*
sizeof(float);
break;
199 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
200 case LongLongPixel: image->depth=8*
sizeof(MagickSizeType);
break;
201 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
205 for (i=0; i < (ssize_t) length; i++)
214 image->alpha_trait=BlendPixelTrait;
226 image->colorspace=CMYKColorspace;
232 image->colorspace=GRAYColorspace;
238 image->colorspace=GRAYColorspace;
243 status=SetImageExtent(image,columns,rows,exception);
244 if (status == MagickFalse)
245 return(DestroyImageList(image));
246 status=ResetImagePixels(image,exception);
247 if (status == MagickFalse)
248 return(DestroyImageList(image));
249 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels,exception);
250 if (status == MagickFalse)
251 image=DestroyImage(image);
284#if defined(__cplusplus) || defined(c_plusplus)
288static size_t PingStream(
const Image *magick_unused(image),
289 const void *magick_unused(pixels),
const size_t columns)
291 magick_unreferenced(image);
292 magick_unreferenced(pixels);
296#if defined(__cplusplus) || defined(c_plusplus)
300MagickExport Image *PingImage(
const ImageInfo *image_info,
301 ExceptionInfo *exception)
309 assert(image_info != (ImageInfo *) NULL);
310 assert(image_info->signature == MagickCoreSignature);
311 assert(exception != (ExceptionInfo *) NULL);
312 if (IsEventLogging() != MagickFalse)
313 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
314 image_info->filename);
315 ping_info=CloneImageInfo(image_info);
316 ping_info->ping=MagickTrue;
317 image=ReadStream(ping_info,&PingStream,exception);
318 if (image != (Image *) NULL)
320 if ((image->columns == 0) || (image->rows == 0))
321 ThrowReaderException(CorruptImageError,
"ImproperImageHeader");
322 ResetTimer(&image->timer);
323 if (ping_info->verbose != MagickFalse)
324 (void) IdentifyImage(image,stdout,MagickFalse,exception);
326 ping_info=DestroyImageInfo(ping_info);
357MagickExport Image *PingImages(ImageInfo *image_info,
const char *filename,
358 ExceptionInfo *exception)
361 ping_filename[MagickPathExtent];
373 assert(image_info != (ImageInfo *) NULL);
374 assert(image_info->signature == MagickCoreSignature);
375 assert(exception != (ExceptionInfo *) NULL);
376 if (IsEventLogging() != MagickFalse)
377 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
378 image_info->filename);
379 (void) SetImageOption(image_info,
"filename",filename);
380 (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
381 (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
382 (
int) image_info->scene,ping_filename,exception);
383 if (LocaleCompare(ping_filename,image_info->filename) != 0)
395 read_info=CloneImageInfo(image_info);
396 sans=AcquireExceptionInfo();
397 (void) SetImageInfo(read_info,0,sans);
398 sans=DestroyExceptionInfo(sans);
399 if (read_info->number_scenes == 0)
401 read_info=DestroyImageInfo(read_info);
402 return(PingImage(image_info,exception));
404 (void) CopyMagickString(ping_filename,read_info->filename,
406 images=NewImageList();
407 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
408 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
410 (void) InterpretImageFilename(image_info,(Image *) NULL,ping_filename,
411 (
int) scene,read_info->filename,exception);
412 image=PingImage(read_info,exception);
413 if (image == (Image *) NULL)
415 AppendImageToList(&images,image);
417 read_info=DestroyImageInfo(read_info);
420 return(PingImage(image_info,exception));
452static MagickBooleanType IsCoderAuthorized(
const char *module,
453 const char *coder,
const PolicyRights rights,ExceptionInfo *exception)
455 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
456 ThrowPolicyException(coder,MagickFalse);
457 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
458 ThrowPolicyException(module,MagickFalse);
462static void InitializeConstituteInfo(
const ImageInfo *image_info,
463 ConstituteInfo *constitute_info)
468 memset(constitute_info,0,
sizeof(*constitute_info));
469 constitute_info->sync_from_exif=MagickTrue;
470 constitute_info->sync_from_tiff=MagickTrue;
471 option=GetImageOption(image_info,
"exif:sync-image");
472 if (IsStringFalse(option) != MagickFalse)
473 constitute_info->sync_from_exif=MagickFalse;
474 option=GetImageOption(image_info,
"tiff:sync-image");
475 if (IsStringFalse(option) != MagickFalse)
476 constitute_info->sync_from_tiff=MagickFalse;
477 constitute_info->caption=GetImageOption(image_info,
"caption");
478 constitute_info->comment=GetImageOption(image_info,
"comment");
479 constitute_info->label=GetImageOption(image_info,
"label");
480 option=GetImageOption(image_info,
"delay");
481 if (option != (
const char *) NULL)
486 constitute_info->delay_flags=ParseGeometry(option,&geometry_info);
487 if (constitute_info->delay_flags != NoValue)
489 constitute_info->delay=(size_t) floor(geometry_info.rho+0.5);
490 if ((constitute_info->delay_flags & SigmaValue) != 0)
491 constitute_info->ticks_per_second=CastDoubleToSsizeT(floor(
492 geometry_info.sigma+0.5));
497static void SyncOrientationFromProperties(Image *image,
498 ConstituteInfo *constitute_info,ExceptionInfo *exception)
503 orientation=(
const char *) NULL;
504 if (constitute_info->sync_from_exif != MagickFalse)
506 orientation=GetImageProperty(image,
"exif:Orientation",exception);
507 if (orientation != (
const char *) NULL)
509 image->orientation=(OrientationType) StringToLong(orientation);
510 (void) DeleteImageProperty(image,
"exif:Orientation");
513 if ((orientation == (
const char *) NULL) &&
514 (constitute_info->sync_from_tiff != MagickFalse))
516 orientation=GetImageProperty(image,
"tiff:Orientation",exception);
517 if (orientation != (
const char *) NULL)
519 image->orientation=(OrientationType) StringToLong(orientation);
520 (void) DeleteImageProperty(image,
"tiff:Orientation");
525static void SyncResolutionFromProperties(Image *image,
526 ConstituteInfo *constitute_info, ExceptionInfo *exception)
536 resolution_x=(
const char *) NULL;
537 resolution_y=(
const char *) NULL;
538 resolution_units=(
const char *) NULL;
539 used_tiff=MagickFalse;
540 if (constitute_info->sync_from_exif != MagickFalse)
542 resolution_x=GetImageProperty(image,
"exif:XResolution",exception);
543 resolution_y=GetImageProperty(image,
"exif:YResolution",exception);
544 if ((resolution_x != (
const char *) NULL) &&
545 (resolution_y != (
const char *) NULL))
546 resolution_units=GetImageProperty(image,
"exif:ResolutionUnit",
549 if ((resolution_x == (
const char *) NULL) &&
550 (resolution_y == (
const char *) NULL) &&
551 (constitute_info->sync_from_tiff != MagickFalse))
553 resolution_x=GetImageProperty(image,
"tiff:XResolution",exception);
554 resolution_y=GetImageProperty(image,
"tiff:YResolution",exception);
555 if ((resolution_x != (
const char *) NULL) &&
556 (resolution_y != (
const char *) NULL))
558 used_tiff=MagickTrue;
559 resolution_units=GetImageProperty(image,
"tiff:ResolutionUnit",
563 if ((resolution_x != (
const char *) NULL) &&
564 (resolution_y != (
const char *) NULL))
572 geometry_info.rho=image->resolution.x;
573 geometry_info.sigma=1.0;
574 (void) ParseGeometry(resolution_x,&geometry_info);
575 if (geometry_info.sigma != 0)
576 image->resolution.x=geometry_info.rho/geometry_info.sigma;
577 if (strchr(resolution_x,
',') != (
char *) NULL)
578 image->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
579 geometry_info.rho=image->resolution.y;
580 geometry_info.sigma=1.0;
581 (void) ParseGeometry(resolution_y,&geometry_info);
582 if (geometry_info.sigma != 0)
583 image->resolution.y=geometry_info.rho/geometry_info.sigma;
584 if (strchr(resolution_y,
',') != (
char *) NULL)
585 image->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
586 if (resolution_units != (
char *) NULL)
588 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
590 if (option_type >= 0)
591 image->units=(ResolutionType) option_type;
593 if (used_tiff == MagickFalse)
595 (void) DeleteImageProperty(image,
"exif:XResolution");
596 (void) DeleteImageProperty(image,
"exif:YResolution");
597 (void) DeleteImageProperty(image,
"exif:ResolutionUnit");
601 (void) DeleteImageProperty(image,
"tiff:XResolution");
602 (void) DeleteImageProperty(image,
"tiff:YResolution");
603 (void) DeleteImageProperty(image,
"tiff:ResolutionUnit");
608static Image *ReadImageInternal(
const ImageInfo *image_info,
609 const MagickBooleanType postprocess,ExceptionInfo *exception)
612 filename[MagickPathExtent],
613 magick[MagickPathExtent],
614 magick_filename[MagickPathExtent];
644 assert(image_info != (ImageInfo *) NULL);
645 assert(image_info->signature == MagickCoreSignature);
646 assert(image_info->filename != (
char *) NULL);
647 if (IsEventLogging() != MagickFalse)
648 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
649 image_info->filename);
650 assert(exception != (ExceptionInfo *) NULL);
651 read_info=CloneImageInfo(image_info);
652 (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
653 (void) SetImageInfo(read_info,0,exception);
654 (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
655 (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
659 sans_exception=AcquireExceptionInfo();
660 magick_info=GetMagickInfo(read_info->magick,sans_exception);
661 if (sans_exception->severity == PolicyError)
662 InheritException(exception,sans_exception);
663 sans_exception=DestroyExceptionInfo(sans_exception);
664 if (magick_info != (
const MagickInfo *) NULL)
666 if (GetMagickEndianSupport(magick_info) == MagickFalse)
667 read_info->endian=UndefinedEndian;
669 if ((image_info->endian == UndefinedEndian) &&
670 (GetMagickRawSupport(magick_info) != MagickFalse))
671 read_info->endian=GetHostEndian();
673 if ((magick_info != (
const MagickInfo *) NULL) &&
674 (GetMagickDecoderSeekableStream(magick_info) != MagickFalse))
676 image=AcquireImage(read_info,exception);
677 (void) CopyMagickString(image->filename,read_info->filename,
679 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
680 if (status == MagickFalse)
682 read_info=DestroyImageInfo(read_info);
683 image=DestroyImage(image);
684 return((Image *) NULL);
686 if (IsBlobSeekable(image) == MagickFalse)
691 *read_info->filename=
'\0';
692 status=ImageToFile(image,read_info->filename,exception);
693 if (status == MagickFalse)
695 (void) CloseBlob(image);
696 read_info=DestroyImageInfo(read_info);
697 image=DestroyImage(image);
698 return((Image *) NULL);
700 read_info->temporary=MagickTrue;
702 (void) CloseBlob(image);
703 image=DestroyImage(image);
705 image=NewImageList();
706 decoder=GetImageDecoder(magick_info);
707 if (decoder == (DecodeImageHandler *) NULL)
709 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
710 if (delegate_info == (
const DelegateInfo *) NULL)
712 (void) SetImageInfo(read_info,0,exception);
713 (void) CopyMagickString(read_info->filename,filename,
715 magick_info=GetMagickInfo(read_info->magick,exception);
716 decoder=GetImageDecoder(magick_info);
719 if (decoder != (DecodeImageHandler *) NULL)
724 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
725 LockSemaphoreInfo(magick_info->semaphore);
726 status=IsCoderAuthorized(magick_info->magick_module,magick_info->name,
727 ReadPolicyRights,exception);
728 image=(Image *) NULL;
729 if (status != MagickFalse)
730 image=decoder(read_info,exception);
731 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
732 UnlockSemaphoreInfo(magick_info->semaphore);
736 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
737 if (delegate_info == (
const DelegateInfo *) NULL)
739 (void) ThrowMagickException(exception,GetMagickModule(),
740 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
741 read_info->filename);
742 if (read_info->temporary != MagickFalse)
743 (void) RelinquishUniqueFileResource(read_info->filename);
744 read_info=DestroyImageInfo(read_info);
745 return((Image *) NULL);
750 image=AcquireImage(read_info,exception);
751 if (image == (Image *) NULL)
753 read_info=DestroyImageInfo(read_info);
754 return((Image *) NULL);
756 (void) CopyMagickString(image->filename,read_info->filename,
758 *read_info->filename=
'\0';
759 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
760 LockSemaphoreInfo(delegate_info->semaphore);
761 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
763 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
764 UnlockSemaphoreInfo(delegate_info->semaphore);
765 image=DestroyImageList(image);
766 read_info->temporary=MagickTrue;
767 if (status != MagickFalse)
768 (void) SetImageInfo(read_info,0,exception);
769 magick_info=GetMagickInfo(read_info->magick,exception);
770 decoder=GetImageDecoder(magick_info);
771 if (decoder == (DecodeImageHandler *) NULL)
773 if (IsPathAccessible(read_info->filename) != MagickFalse)
774 (void) ThrowMagickException(exception,GetMagickModule(),
775 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
778 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
779 read_info->filename);
780 read_info=DestroyImageInfo(read_info);
781 return((Image *) NULL);
786 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
787 LockSemaphoreInfo(magick_info->semaphore);
788 status=IsCoderAuthorized(magick_info->magick_module,magick_info->name,
789 ReadPolicyRights,exception);
790 image=(Image *) NULL;
791 if (status != MagickFalse)
792 image=(decoder)(read_info,exception);
793 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
794 UnlockSemaphoreInfo(magick_info->semaphore);
796 if (read_info->temporary != MagickFalse)
798 (void) RelinquishUniqueFileResource(read_info->filename);
799 read_info->temporary=MagickFalse;
800 if (image != (Image *) NULL)
801 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
803 if (image == (Image *) NULL)
805 read_info=DestroyImageInfo(read_info);
808 if (IsBlobTemporary(image) != MagickFalse)
809 (void) RelinquishUniqueFileResource(read_info->filename);
810 if (exception->severity >= ErrorException)
812 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
813 "Coder (%s) generated an image despite an error (%d), "
814 "notify the developers",image->magick,exception->severity);
815 return(DestroyImageList(image));
817 if (read_info->ping != MagickFalse)
819 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
821 if ((image->columns == 0) || (image->rows == 0))
823 read_info=DestroyImageInfo(read_info);
824 ThrowReaderException(ImageError,
"NegativeOrZeroImageSize");
828 if ((postprocess != MagickFalse) &&
829 (IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
830 (GetImageListLength(image) != 1))
835 clones=CloneImages(image,read_info->scenes,exception);
836 image=DestroyImageList(image);
837 if (clones != (Image *) NULL)
838 image=GetFirstImageInList(clones);
839 if (image == (Image *) NULL)
841 read_info=DestroyImageInfo(read_info);
845 InitializeConstituteInfo(read_info,&constitute_info);
846 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
849 magick_path[MagickPathExtent],
855 next->taint=MagickFalse;
856 GetPathComponent(magick_filename,MagickPath,magick_path);
857 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
858 (void) CopyMagickString(next->magick,magick,MagickPathExtent);
859 (void) CopyMagickString(next->magick_filename,magick_filename,
861 if (IsBlobTemporary(image) != MagickFalse)
862 (void) CopyMagickString(next->filename,filename,MagickPathExtent);
863 if (next->magick_columns == 0)
864 next->magick_columns=next->columns;
865 if (next->magick_rows == 0)
866 next->magick_rows=next->rows;
867 if (postprocess == MagickFalse)
872 (void) GetImageProperty(next,
"exif:*",exception);
873 (void) GetImageProperty(next,
"icc:*",exception);
874 (void) GetImageProperty(next,
"iptc:*",exception);
875 (void) GetImageProperty(next,
"xmp:*",exception);
876 SyncOrientationFromProperties(next,&constitute_info,exception);
877 SyncResolutionFromProperties(next,&constitute_info,exception);
878 if (next->page.width == 0)
879 next->page.width=next->columns;
880 if (next->page.height == 0)
881 next->page.height=next->rows;
882 if (constitute_info.caption != (
const char *) NULL)
884 property=InterpretImageProperties(read_info,next,
885 constitute_info.caption,exception);
886 (void) SetImageProperty(next,
"caption",property,exception);
887 property=DestroyString(property);
889 if (constitute_info.comment != (
const char *) NULL)
891 property=InterpretImageProperties(read_info,next,
892 constitute_info.comment,exception);
893 (void) SetImageProperty(next,
"comment",property,exception);
894 property=DestroyString(property);
896 if (constitute_info.label != (
const char *) NULL)
898 property=InterpretImageProperties(read_info,next,
899 constitute_info.label,exception);
900 (void) SetImageProperty(next,
"label",property,exception);
901 property=DestroyString(property);
903 if (LocaleCompare(next->magick,
"TEXT") == 0)
904 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
905 if ((read_info->extract != (
char *) NULL) &&
906 (read_info->stream == (StreamHandler) NULL))
914 SetGeometry(next,&geometry);
915 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
916 if ((next->columns != geometry.width) ||
917 (next->rows != geometry.height))
919 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
921 Image *crop_image = CropImage(next,&geometry,exception);
922 if (crop_image != (Image *) NULL)
923 ReplaceImageInList(&next,crop_image);
926 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
928 flags=ParseRegionGeometry(next,read_info->extract,&geometry,
930 if ((geometry.width != 0) && (geometry.height != 0))
932 Image *resize_image = ResizeImage(next,geometry.width,
933 geometry.height,next->filter,exception);
934 if (resize_image != (Image *) NULL)
935 ReplaceImageInList(&next,resize_image);
940 profile=GetImageProfile(next,
"icc");
941 if (profile == (
const StringInfo *) NULL)
942 profile=GetImageProfile(next,
"icm");
943 profile=GetImageProfile(next,
"iptc");
944 if (profile == (
const StringInfo *) NULL)
945 profile=GetImageProfile(next,
"8bim");
946 if (IsSourceDataEpochSet() == MagickFalse)
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));
998MagickExport Image *ReadImage(
const ImageInfo *image_info,
999 ExceptionInfo *exception)
1001 return(ReadImageInternal(image_info,MagickTrue,exception));
1033MagickExport Image *ReadImageWithoutPostProcessing(
const ImageInfo *image_info,
1034 ExceptionInfo *exception)
1036 return(ReadImageInternal(image_info,MagickFalse,exception));
1066MagickExport Image *ReadImages(ImageInfo *image_info,
const char *filename,
1067 ExceptionInfo *exception)
1070 read_filename[MagickPathExtent];
1082 assert(image_info != (ImageInfo *) NULL);
1083 assert(image_info->signature == MagickCoreSignature);
1084 assert(exception != (ExceptionInfo *) NULL);
1085 if (IsEventLogging() != MagickFalse)
1086 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1087 image_info->filename);
1088 read_info=CloneImageInfo(image_info);
1089 *read_info->magick=
'\0';
1090 (void) SetImageOption(read_info,
"filename",filename);
1091 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1092 (void) InterpretImageFilename(read_info,(Image *) NULL,filename,
1093 (
int) read_info->scene,read_filename,exception);
1094 if (LocaleCompare(read_filename,read_info->filename) != 0)
1106 sans=AcquireExceptionInfo();
1107 (void) SetImageInfo(read_info,0,sans);
1108 sans=DestroyExceptionInfo(sans);
1109 if (read_info->number_scenes != 0)
1111 (void) CopyMagickString(read_filename,read_info->filename,
1113 images=NewImageList();
1114 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
1115 scene=(ssize_t) read_info->scene;
1116 for ( ; scene < (ssize_t) extent; scene++)
1118 (void) InterpretImageFilename(image_info,(Image *) NULL,
1119 read_filename,(
int) scene,read_info->filename,exception);
1120 image=ReadImage(read_info,exception);
1121 if (image == (Image *) NULL)
1123 AppendImageToList(&images,image);
1125 read_info=DestroyImageInfo(read_info);
1129 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1130 image=ReadImage(read_info,exception);
1131 read_info=DestroyImageInfo(read_info);
1166static MagickBooleanType GetImplicitDataImageType(
const char *data_url,
1167 char *magick,ExceptionInfo *exception)
1183 if (data_url == (
const char *) NULL)
1184 return(MagickFalse);
1185 if (strncmp(data_url,
"data:",5) != 0)
1186 return(MagickFalse);
1189 while ((*p !=
'\0') && (*p !=
';') && (*p !=
','))
1192 return(MagickFalse);
1193 slash=(
const char *) memchr(type,
'/',(
size_t) (p-type));
1194 if ((slash == (
const char *) NULL) || ((slash+1) >= p))
1195 return(MagickFalse);
1196 offset=(size_t) (p-(slash+1));
1197 if (offset >= MagickPathExtent)
1198 return(MagickFalse);
1199 (void) memcpy(magick,slash+1,offset);
1200 magick[offset]=
'\0';
1201 plus=strchr(magick,
'+');
1202 if (plus != (
char *) NULL)
1204 if (LocaleNCompare(magick,
"x-",2) == 0)
1205 (void) memmove(magick,magick+2,strlen(magick+2)+1);
1206 magick_info=GetMagickInfo(magick,exception);
1207 if ((magick_info == (
const MagickInfo *) NULL) ||
1208 (magick_info->format_type == ImplicitFormatType))
1209 return(MagickFalse);
1213MagickExport Image *ReadInlineImage(
const ImageInfo *image_info,
1214 const char *content,ExceptionInfo *exception)
1220 *image = (Image *) NULL;
1234 image=NewImageList();
1235 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1237 ThrowReaderException(CorruptImageError,
"CorruptImage");
1238 blob=Base64Decode(++p,&length);
1241 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1242 ThrowReaderException(CorruptImageError,
"CorruptImage");
1244 read_info=CloneImageInfo(image_info);
1245 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1247 *read_info->filename=
'\0';
1248 if (GetImplicitDataImageType(content,read_info->magick,exception) == MagickFalse)
1250 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1251 read_info=DestroyImageInfo(read_info);
1252 ThrowReaderException(ImageError,
"ImageTypeNotSupported");
1254 image=BlobToImage(read_info,blob,length,exception);
1255 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1256 read_info=DestroyImageInfo(read_info);
1291MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1292 Image *image,ExceptionInfo *exception)
1295 filename[MagickPathExtent];
1322 assert(image_info != (ImageInfo *) NULL);
1323 assert(image_info->signature == MagickCoreSignature);
1324 assert(image != (Image *) NULL);
1325 if (IsEventLogging() != MagickFalse)
1326 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1327 image_info->filename);
1328 assert(image->signature == MagickCoreSignature);
1329 assert(exception != (ExceptionInfo *) NULL);
1330 sans_exception=AcquireExceptionInfo();
1331 write_info=CloneImageInfo(image_info);
1332 (void) CopyMagickString(write_info->filename,image->filename,
1334 (void) SetImageInfo(write_info,1,sans_exception);
1335 if (*write_info->magick ==
'\0')
1336 (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1337 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1338 (void) CopyMagickString(image->filename,write_info->filename,
1343 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1344 if (sans_exception->severity == PolicyError)
1345 magick_info=GetMagickInfo(write_info->magick,exception);
1346 sans_exception=DestroyExceptionInfo(sans_exception);
1347 if (magick_info != (
const MagickInfo *) NULL)
1349 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1350 image->endian=UndefinedEndian;
1352 if ((image_info->endian == UndefinedEndian) &&
1353 (GetMagickRawSupport(magick_info) != MagickFalse))
1354 image->endian=GetHostEndian();
1356 if ((image->ping != MagickFalse) &&
1357 (SyncImagePixelCache(image,exception) == MagickFalse))
1359 write_info=DestroyImageInfo(write_info);
1360 return(MagickFalse);
1362 SyncImageProfiles(image);
1363 DisassociateImageStream(image);
1364 option=GetImageOption(image_info,
"delegate:bimodal");
1365 if ((IsStringTrue(option) != MagickFalse) &&
1366 (write_info->page == (
char *) NULL) &&
1367 (GetPreviousImageInList(image) == (Image *) NULL) &&
1368 (GetNextImageInList(image) == (Image *) NULL) &&
1369 (IsTaintImage(image) == MagickFalse) )
1371 delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1372 if ((delegate_info != (
const DelegateInfo *) NULL) &&
1373 (GetDelegateMode(delegate_info) == 0) &&
1374 (IsPathAccessible(image->magick_filename) != MagickFalse))
1379 (void) CopyMagickString(image->filename,image->magick_filename,
1381 status=InvokeDelegate(write_info,image,image->magick,
1382 write_info->magick,exception);
1383 write_info=DestroyImageInfo(write_info);
1384 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1389 temporary=MagickFalse;
1390 if ((magick_info != (
const MagickInfo *) NULL) &&
1391 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1394 image_filename[MagickPathExtent];
1396 (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1397 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1398 (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1399 if (status != MagickFalse)
1401 if (IsBlobSeekable(image) == MagickFalse)
1406 write_info->adjoin=MagickTrue;
1407 (void) CopyMagickString(write_info->filename,image->filename,
1409 (void) AcquireUniqueFilename(image->filename);
1410 temporary=MagickTrue;
1412 if (CloseBlob(image) == MagickFalse)
1416 encoder=GetImageEncoder(magick_info);
1417 if (encoder != (EncodeImageHandler *) NULL)
1422 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1423 LockSemaphoreInfo(magick_info->semaphore);
1424 status=IsCoderAuthorized(magick_info->magick_module,magick_info->name,
1425 WritePolicyRights,exception);
1426 if (status != MagickFalse)
1427 status=encoder(write_info,image,exception);
1428 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1429 UnlockSemaphoreInfo(magick_info->semaphore);
1433 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,exception);
1434 if (delegate_info != (DelegateInfo *) NULL)
1439 *write_info->filename=
'\0';
1440 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1441 LockSemaphoreInfo(delegate_info->semaphore);
1442 status=InvokeDelegate(write_info,image,(
char *) NULL,
1443 write_info->magick,exception);
1444 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1445 UnlockSemaphoreInfo(delegate_info->semaphore);
1446 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1450 sans_exception=AcquireExceptionInfo();
1451 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1452 if (sans_exception->severity == PolicyError)
1453 magick_info=GetMagickInfo(write_info->magick,exception);
1454 sans_exception=DestroyExceptionInfo(sans_exception);
1455 if ((write_info->affirm == MagickFalse) &&
1456 (magick_info == (
const MagickInfo *) NULL))
1458 (void) CopyMagickString(write_info->magick,image->magick,
1460 magick_info=GetMagickInfo(write_info->magick,exception);
1462 encoder=GetImageEncoder(magick_info);
1463 if (encoder == (EncodeImageHandler *) NULL)
1466 extension[MagickPathExtent];
1468 GetPathComponent(image->filename,ExtensionPath,extension);
1469 if (*extension !=
'\0')
1470 magick_info=GetMagickInfo(extension,exception);
1472 magick_info=GetMagickInfo(image->magick,exception);
1473 (void) CopyMagickString(image->filename,filename,
1475 encoder=GetImageEncoder(magick_info);
1476 (void) ThrowMagickException(exception,GetMagickModule(),
1477 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1478 "`%s'",write_info->magick);
1480 if (encoder == (EncodeImageHandler *) NULL)
1482 magick_info=GetMagickInfo(image->magick,exception);
1483 encoder=GetImageEncoder(magick_info);
1484 if (encoder == (EncodeImageHandler *) NULL)
1485 (void) ThrowMagickException(exception,GetMagickModule(),
1486 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1487 "`%s'",write_info->magick);
1489 if (encoder != (EncodeImageHandler *) NULL)
1494 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1495 LockSemaphoreInfo(magick_info->semaphore);
1496 status=IsCoderAuthorized(magick_info->magick_module,magick_info->name,
1497 WritePolicyRights,exception);
1498 if (status != MagickFalse)
1499 status=encoder(write_info,image,exception);
1500 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1501 UnlockSemaphoreInfo(magick_info->semaphore);
1505 if (temporary != MagickFalse)
1510 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1511 if (status != MagickFalse)
1513 (void) RelinquishUniqueFileResource(write_info->filename);
1514 status=ImageToFile(image,write_info->filename,exception);
1516 if (CloseBlob(image) == MagickFalse)
1518 (void) RelinquishUniqueFileResource(image->filename);
1519 (void) CopyMagickString(image->filename,write_info->filename,
1522 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1523 (write_info->verbose != MagickFalse))
1524 (void) IdentifyImage(image,stdout,MagickFalse,exception);
1525 write_info=DestroyImageInfo(write_info);
1526 if (GetBlobError(image) != MagickFalse)
1527 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1567MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1568 Image *images,
const char *filename,ExceptionInfo *exception)
1570#define WriteImageTag "Write/Image"
1584 MagickProgressMonitor
1596 assert(image_info != (
const ImageInfo *) NULL);
1597 assert(image_info->signature == MagickCoreSignature);
1598 assert(images != (Image *) NULL);
1599 assert(images->signature == MagickCoreSignature);
1600 if (IsEventLogging() != MagickFalse)
1601 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1602 assert(exception != (ExceptionInfo *) NULL);
1603 write_info=CloneImageInfo(image_info);
1604 *write_info->magick=
'\0';
1605 images=GetFirstImageInList(images);
1606 if (images == (Image *) NULL)
1607 return(MagickFalse);
1608 if (filename != (
const char *) NULL)
1609 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1610 (
void) CopyMagickString(p->filename,filename,MagickPathExtent);
1611 (void) CopyMagickString(write_info->filename,images->filename,
1613 sans_exception=AcquireExceptionInfo();
1614 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1616 sans_exception=DestroyExceptionInfo(sans_exception);
1617 if (*write_info->magick ==
'\0')
1618 (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1620 for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1622 if (p->scene >= GetNextImageInList(p)->scene)
1630 i=(ssize_t) images->scene;
1631 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1632 p->scene=(
size_t) i++;
1640 progress_monitor=(MagickProgressMonitor) NULL;
1642 number_images=GetImageListLength(images);
1643 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1645 if (number_images != 1)
1646 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1648 status&=(MagickStatusType) WriteImage(write_info,p,exception);
1649 if (write_info->blob != (
void *) NULL)
1650 SyncBlobStream(write_info,p,images);
1651 if (number_images != 1)
1652 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1653 if (write_info->adjoin != MagickFalse)
1655 if (number_images != 1)
1657#if defined(MAGICKCORE_OPENMP_SUPPORT)
1661 proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1662 if (proceed == MagickFalse)
1666 write_info=DestroyImageInfo(write_info);
1667 return(status != 0 ? MagickTrue : MagickFalse);