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");
608MagickExport Image *ReadImage(
const ImageInfo *image_info,
609 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,read_info->magick,
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,read_info->magick,
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 (exception->severity >= ErrorException)
809 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
810 "Coder (%s) generated an image despite an error (%d), "
811 "notify the developers",image->magick,exception->severity);
812 if (IsBlobTemporary(image) != MagickFalse)
813 (void) RelinquishUniqueFileResource(read_info->filename);
814 if (read_info->ping != MagickFalse)
816 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
818 if ((image->columns == 0) || (image->rows == 0))
820 read_info=DestroyImageInfo(read_info);
821 ThrowReaderException(ImageError,
"NegativeOrZeroImageSize");
825 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
826 (GetImageListLength(image) != 1))
831 clones=CloneImages(image,read_info->scenes,exception);
832 image=DestroyImageList(image);
833 if (clones != (Image *) NULL)
834 image=GetFirstImageInList(clones);
835 if (image == (Image *) NULL)
837 read_info=DestroyImageInfo(read_info);
841 InitializeConstituteInfo(read_info,&constitute_info);
842 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
845 magick_path[MagickPathExtent],
851 next->taint=MagickFalse;
852 GetPathComponent(magick_filename,MagickPath,magick_path);
853 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
854 (void) CopyMagickString(next->magick,magick,MagickPathExtent);
855 (void) CopyMagickString(next->magick_filename,magick_filename,
857 if (IsBlobTemporary(image) != MagickFalse)
858 (void) CopyMagickString(next->filename,filename,MagickPathExtent);
859 if (next->magick_columns == 0)
860 next->magick_columns=next->columns;
861 if (next->magick_rows == 0)
862 next->magick_rows=next->rows;
863 (void) GetImageProperty(next,
"exif:*",exception);
864 (void) GetImageProperty(next,
"icc:*",exception);
865 (void) GetImageProperty(next,
"iptc:*",exception);
866 (void) GetImageProperty(next,
"xmp:*",exception);
867 SyncOrientationFromProperties(next,&constitute_info,exception);
868 SyncResolutionFromProperties(next,&constitute_info,exception);
869 if (next->page.width == 0)
870 next->page.width=next->columns;
871 if (next->page.height == 0)
872 next->page.height=next->rows;
873 if (constitute_info.caption != (
const char *) NULL)
875 property=InterpretImageProperties(read_info,next,
876 constitute_info.caption,exception);
877 (void) SetImageProperty(next,
"caption",property,exception);
878 property=DestroyString(property);
880 if (constitute_info.comment != (
const char *) NULL)
882 property=InterpretImageProperties(read_info,next,
883 constitute_info.comment,exception);
884 (void) SetImageProperty(next,
"comment",property,exception);
885 property=DestroyString(property);
887 if (constitute_info.label != (
const char *) NULL)
889 property=InterpretImageProperties(read_info,next,
890 constitute_info.label,exception);
891 (void) SetImageProperty(next,
"label",property,exception);
892 property=DestroyString(property);
894 if (LocaleCompare(next->magick,
"TEXT") == 0)
895 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
896 if ((read_info->extract != (
char *) NULL) &&
897 (read_info->stream == (StreamHandler) NULL))
905 SetGeometry(next,&geometry);
906 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
907 if ((next->columns != geometry.width) ||
908 (next->rows != geometry.height))
910 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
912 Image *crop_image = CropImage(next,&geometry,exception);
913 if (crop_image != (Image *) NULL)
914 ReplaceImageInList(&next,crop_image);
917 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
919 flags=ParseRegionGeometry(next,read_info->extract,&geometry,
921 if ((geometry.width != 0) && (geometry.height != 0))
923 Image *resize_image = ResizeImage(next,geometry.width,
924 geometry.height,next->filter,exception);
925 if (resize_image != (Image *) NULL)
926 ReplaceImageInList(&next,resize_image);
931 profile=GetImageProfile(next,
"icc");
932 if (profile == (
const StringInfo *) NULL)
933 profile=GetImageProfile(next,
"icm");
934 profile=GetImageProfile(next,
"iptc");
935 if (profile == (
const StringInfo *) NULL)
936 profile=GetImageProfile(next,
"8bim");
937 if (IsSourceDataEpochSet() == MagickFalse)
940 timestamp[MagickTimeExtent];
942 (void) FormatMagickTime(next->timestamp,
sizeof(timestamp),timestamp);
943 (void) SetImageProperty(next,
"date:timestamp",timestamp,exception);
944 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
945 sizeof(timestamp),timestamp);
946 (void) SetImageProperty(next,
"date:modify",timestamp,exception);
947 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
948 sizeof(timestamp),timestamp);
949 (void) SetImageProperty(next,
"date:create",timestamp,exception);
951 if (constitute_info.delay_flags != NoValue)
953 if ((constitute_info.delay_flags & GreaterValue) != 0)
955 if (next->delay > constitute_info.delay)
956 next->delay=constitute_info.delay;
959 if ((constitute_info.delay_flags & LessValue) != 0)
961 if (next->delay < constitute_info.delay)
962 next->delay=constitute_info.delay;
965 next->delay=constitute_info.delay;
966 if ((constitute_info.delay_flags & SigmaValue) != 0)
967 next->ticks_per_second=constitute_info.ticks_per_second;
969 if (constitute_info.dispose != (
const char *) NULL)
974 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
975 constitute_info.dispose);
976 if (option_type >= 0)
977 next->dispose=(DisposeType) option_type;
979 if (read_info->verbose != MagickFalse)
980 (void) IdentifyImage(next,stderr,MagickFalse,exception);
983 read_info=DestroyImageInfo(read_info);
984 if (GetBlobError(image) != MagickFalse)
985 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
986 return(GetFirstImageInList(image));
1016MagickExport Image *ReadImages(ImageInfo *image_info,
const char *filename,
1017 ExceptionInfo *exception)
1020 read_filename[MagickPathExtent];
1032 assert(image_info != (ImageInfo *) NULL);
1033 assert(image_info->signature == MagickCoreSignature);
1034 assert(exception != (ExceptionInfo *) NULL);
1035 if (IsEventLogging() != MagickFalse)
1036 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1037 image_info->filename);
1038 read_info=CloneImageInfo(image_info);
1039 *read_info->magick=
'\0';
1040 (void) SetImageOption(read_info,
"filename",filename);
1041 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1042 (void) InterpretImageFilename(read_info,(Image *) NULL,filename,
1043 (
int) read_info->scene,read_filename,exception);
1044 if (LocaleCompare(read_filename,read_info->filename) != 0)
1056 sans=AcquireExceptionInfo();
1057 (void) SetImageInfo(read_info,0,sans);
1058 sans=DestroyExceptionInfo(sans);
1059 if (read_info->number_scenes != 0)
1061 (void) CopyMagickString(read_filename,read_info->filename,
1063 images=NewImageList();
1064 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
1065 scene=(ssize_t) read_info->scene;
1066 for ( ; scene < (ssize_t) extent; scene++)
1068 (void) InterpretImageFilename(image_info,(Image *) NULL,
1069 read_filename,(
int) scene,read_info->filename,exception);
1070 image=ReadImage(read_info,exception);
1071 if (image == (Image *) NULL)
1073 AppendImageToList(&images,image);
1075 read_info=DestroyImageInfo(read_info);
1079 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1080 image=ReadImage(read_info,exception);
1081 read_info=DestroyImageInfo(read_info);
1115MagickExport Image *ReadInlineImage(
const ImageInfo *image_info,
1116 const char *content,ExceptionInfo *exception)
1136 image=NewImageList();
1137 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1139 ThrowReaderException(CorruptImageError,
"CorruptImage");
1140 blob=Base64Decode(++p,&length);
1143 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1144 ThrowReaderException(CorruptImageError,
"CorruptImage");
1146 read_info=CloneImageInfo(image_info);
1147 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1149 *read_info->filename=
'\0';
1150 *read_info->magick=
'\0';
1151 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1163 if (LocaleNCompare(++p,
"x-",2) == 0)
1165 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1166 q=read_info->filename+5;
1167 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1171 image=BlobToImage(read_info,blob,length,exception);
1172 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1173 read_info=DestroyImageInfo(read_info);
1208MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1209 Image *image,ExceptionInfo *exception)
1212 filename[MagickPathExtent];
1239 assert(image_info != (ImageInfo *) NULL);
1240 assert(image_info->signature == MagickCoreSignature);
1241 assert(image != (Image *) NULL);
1242 if (IsEventLogging() != MagickFalse)
1243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1244 image_info->filename);
1245 assert(image->signature == MagickCoreSignature);
1246 assert(exception != (ExceptionInfo *) NULL);
1247 sans_exception=AcquireExceptionInfo();
1248 write_info=CloneImageInfo(image_info);
1249 (void) CopyMagickString(write_info->filename,image->filename,
1251 (void) SetImageInfo(write_info,1,sans_exception);
1252 if (*write_info->magick ==
'\0')
1253 (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1254 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1255 (void) CopyMagickString(image->filename,write_info->filename,
1260 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1261 if (sans_exception->severity == PolicyError)
1262 magick_info=GetMagickInfo(write_info->magick,exception);
1263 sans_exception=DestroyExceptionInfo(sans_exception);
1264 if (magick_info != (
const MagickInfo *) NULL)
1266 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1267 image->endian=UndefinedEndian;
1269 if ((image_info->endian == UndefinedEndian) &&
1270 (GetMagickRawSupport(magick_info) != MagickFalse))
1271 image->endian=GetHostEndian();
1273 if ((image->ping != MagickFalse) &&
1274 (SyncImagePixelCache(image,exception) == MagickFalse))
1276 write_info=DestroyImageInfo(write_info);
1277 return(MagickFalse);
1279 SyncImageProfiles(image);
1280 DisassociateImageStream(image);
1281 option=GetImageOption(image_info,
"delegate:bimodal");
1282 if ((IsStringTrue(option) != MagickFalse) &&
1283 (write_info->page == (
char *) NULL) &&
1284 (GetPreviousImageInList(image) == (Image *) NULL) &&
1285 (GetNextImageInList(image) == (Image *) NULL) &&
1286 (IsTaintImage(image) == MagickFalse) )
1288 delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1289 if ((delegate_info != (
const DelegateInfo *) NULL) &&
1290 (GetDelegateMode(delegate_info) == 0) &&
1291 (IsPathAccessible(image->magick_filename) != MagickFalse))
1296 (void) CopyMagickString(image->filename,image->magick_filename,
1298 status=InvokeDelegate(write_info,image,image->magick,
1299 write_info->magick,exception);
1300 write_info=DestroyImageInfo(write_info);
1301 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1306 temporary=MagickFalse;
1307 if ((magick_info != (
const MagickInfo *) NULL) &&
1308 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1311 image_filename[MagickPathExtent];
1313 (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1314 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1315 (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1316 if (status != MagickFalse)
1318 if (IsBlobSeekable(image) == MagickFalse)
1323 write_info->adjoin=MagickTrue;
1324 (void) CopyMagickString(write_info->filename,image->filename,
1326 (void) AcquireUniqueFilename(image->filename);
1327 temporary=MagickTrue;
1329 if (CloseBlob(image) == MagickFalse)
1333 encoder=GetImageEncoder(magick_info);
1334 if (encoder != (EncodeImageHandler *) NULL)
1339 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1340 LockSemaphoreInfo(magick_info->semaphore);
1341 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1342 WritePolicyRights,exception);
1343 if (status != MagickFalse)
1344 status=encoder(write_info,image,exception);
1345 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1346 UnlockSemaphoreInfo(magick_info->semaphore);
1350 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,exception);
1351 if (delegate_info != (DelegateInfo *) NULL)
1356 *write_info->filename=
'\0';
1357 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1358 LockSemaphoreInfo(delegate_info->semaphore);
1359 status=InvokeDelegate(write_info,image,(
char *) NULL,
1360 write_info->magick,exception);
1361 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1362 UnlockSemaphoreInfo(delegate_info->semaphore);
1363 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1367 sans_exception=AcquireExceptionInfo();
1368 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1369 if (sans_exception->severity == PolicyError)
1370 magick_info=GetMagickInfo(write_info->magick,exception);
1371 sans_exception=DestroyExceptionInfo(sans_exception);
1372 if ((write_info->affirm == MagickFalse) &&
1373 (magick_info == (
const MagickInfo *) NULL))
1375 (void) CopyMagickString(write_info->magick,image->magick,
1377 magick_info=GetMagickInfo(write_info->magick,exception);
1379 encoder=GetImageEncoder(magick_info);
1380 if (encoder == (EncodeImageHandler *) NULL)
1383 extension[MagickPathExtent];
1385 GetPathComponent(image->filename,ExtensionPath,extension);
1386 if (*extension !=
'\0')
1387 magick_info=GetMagickInfo(extension,exception);
1389 magick_info=GetMagickInfo(image->magick,exception);
1390 (void) CopyMagickString(image->filename,filename,
1392 encoder=GetImageEncoder(magick_info);
1393 (void) ThrowMagickException(exception,GetMagickModule(),
1394 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1395 "`%s'",write_info->magick);
1397 if (encoder == (EncodeImageHandler *) NULL)
1399 magick_info=GetMagickInfo(image->magick,exception);
1400 encoder=GetImageEncoder(magick_info);
1401 if (encoder == (EncodeImageHandler *) NULL)
1402 (void) ThrowMagickException(exception,GetMagickModule(),
1403 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1404 "`%s'",write_info->magick);
1406 if (encoder != (EncodeImageHandler *) NULL)
1411 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1412 LockSemaphoreInfo(magick_info->semaphore);
1413 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1414 WritePolicyRights,exception);
1415 if (status != MagickFalse)
1416 status=encoder(write_info,image,exception);
1417 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1418 UnlockSemaphoreInfo(magick_info->semaphore);
1422 if (temporary != MagickFalse)
1427 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1428 if (status != MagickFalse)
1430 (void) RelinquishUniqueFileResource(write_info->filename);
1431 status=ImageToFile(image,write_info->filename,exception);
1433 if (CloseBlob(image) == MagickFalse)
1435 (void) RelinquishUniqueFileResource(image->filename);
1436 (void) CopyMagickString(image->filename,write_info->filename,
1439 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1440 (write_info->verbose != MagickFalse))
1441 (void) IdentifyImage(image,stdout,MagickFalse,exception);
1442 write_info=DestroyImageInfo(write_info);
1443 if (GetBlobError(image) != MagickFalse)
1444 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1484MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1485 Image *images,
const char *filename,ExceptionInfo *exception)
1487#define WriteImageTag "Write/Image"
1501 MagickProgressMonitor
1513 assert(image_info != (
const ImageInfo *) NULL);
1514 assert(image_info->signature == MagickCoreSignature);
1515 assert(images != (Image *) NULL);
1516 assert(images->signature == MagickCoreSignature);
1517 if (IsEventLogging() != MagickFalse)
1518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1519 assert(exception != (ExceptionInfo *) NULL);
1520 write_info=CloneImageInfo(image_info);
1521 *write_info->magick=
'\0';
1522 images=GetFirstImageInList(images);
1523 if (images == (Image *) NULL)
1524 return(MagickFalse);
1525 if (filename != (
const char *) NULL)
1526 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1527 (
void) CopyMagickString(p->filename,filename,MagickPathExtent);
1528 (void) CopyMagickString(write_info->filename,images->filename,
1530 sans_exception=AcquireExceptionInfo();
1531 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1533 sans_exception=DestroyExceptionInfo(sans_exception);
1534 if (*write_info->magick ==
'\0')
1535 (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1537 for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1539 if (p->scene >= GetNextImageInList(p)->scene)
1547 i=(ssize_t) images->scene;
1548 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1549 p->scene=(
size_t) i++;
1557 progress_monitor=(MagickProgressMonitor) NULL;
1559 number_images=GetImageListLength(images);
1560 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1562 if (number_images != 1)
1563 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1565 status&=(MagickStatusType) WriteImage(write_info,p,exception);
1566 if (number_images != 1)
1567 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1568 if (write_info->adjoin != MagickFalse)
1570 if (number_images != 1)
1572#if defined(MAGICKCORE_OPENMP_SUPPORT)
1576 proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1577 if (proceed == MagickFalse)
1581 write_info=DestroyImageInfo(write_info);
1582 return(status != 0 ? MagickTrue : MagickFalse);