42#include "MagickCore/studio.h"
43#include "MagickCore/attribute.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/exception.h"
47#include "MagickCore/exception-private.h"
48#include "MagickCore/cache.h"
49#include "MagickCore/cache-private.h"
50#include "MagickCore/client.h"
51#include "MagickCore/coder-private.h"
52#include "MagickCore/colorspace-private.h"
53#include "MagickCore/constitute.h"
54#include "MagickCore/constitute-private.h"
55#include "MagickCore/delegate.h"
56#include "MagickCore/geometry.h"
57#include "MagickCore/identify.h"
58#include "MagickCore/image-private.h"
59#include "MagickCore/list.h"
60#include "MagickCore/magick.h"
61#include "MagickCore/memory_.h"
62#include "MagickCore/monitor.h"
63#include "MagickCore/monitor-private.h"
64#include "MagickCore/option.h"
65#include "MagickCore/pixel.h"
66#include "MagickCore/pixel-accessor.h"
67#include "MagickCore/policy.h"
68#include "MagickCore/profile.h"
69#include "MagickCore/profile-private.h"
70#include "MagickCore/property.h"
71#include "MagickCore/quantum.h"
72#include "MagickCore/resize.h"
73#include "MagickCore/resource_.h"
74#include "MagickCore/semaphore.h"
75#include "MagickCore/statistic.h"
76#include "MagickCore/stream.h"
77#include "MagickCore/string_.h"
78#include "MagickCore/string-private.h"
79#include "MagickCore/timer.h"
80#include "MagickCore/timer-private.h"
81#include "MagickCore/token.h"
82#include "MagickCore/transform.h"
83#include "MagickCore/utility.h"
84#include "MagickCore/utility-private.h"
89#define MaxReadRecursionDepth 100
165MagickExport Image *ConstituteImage(
const size_t columns,
const size_t rows,
166 const char *map,
const StorageType storage,
const void *pixels,
167 ExceptionInfo *exception)
184 assert(map != (
const char *) NULL);
185 assert(pixels != (
void *) NULL);
186 assert(exception != (ExceptionInfo *) NULL);
187 assert(exception->signature == MagickCoreSignature);
188 if (IsEventLogging() != MagickFalse)
189 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
190 image=AcquireImage((ImageInfo *) NULL,exception);
191 if (image == (Image *) NULL)
192 return((Image *) NULL);
195 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
196 case DoublePixel: image->depth=8*
sizeof(double);
break;
197 case FloatPixel: image->depth=8*
sizeof(float);
break;
198 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
199 case LongLongPixel: image->depth=8*
sizeof(MagickSizeType);
break;
200 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
204 for (i=0; i < (ssize_t) length; i++)
213 image->alpha_trait=BlendPixelTrait;
225 image->colorspace=CMYKColorspace;
231 image->colorspace=GRAYColorspace;
237 image->colorspace=GRAYColorspace;
242 status=SetImageExtent(image,columns,rows,exception);
243 if (status == MagickFalse)
244 return(DestroyImageList(image));
245 status=ResetImagePixels(image,exception);
246 if (status == MagickFalse)
247 return(DestroyImageList(image));
248 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels,exception);
249 if (status == MagickFalse)
250 image=DestroyImage(image);
283#if defined(__cplusplus) || defined(c_plusplus)
287static size_t PingStream(
const Image *magick_unused(image),
288 const void *magick_unused(pixels),
const size_t columns)
290 magick_unreferenced(image);
291 magick_unreferenced(pixels);
295#if defined(__cplusplus) || defined(c_plusplus)
299MagickExport Image *PingImage(
const ImageInfo *image_info,
300 ExceptionInfo *exception)
308 assert(image_info != (ImageInfo *) NULL);
309 assert(image_info->signature == MagickCoreSignature);
310 assert(exception != (ExceptionInfo *) NULL);
311 if (IsEventLogging() != MagickFalse)
312 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
313 image_info->filename);
314 ping_info=CloneImageInfo(image_info);
315 ping_info->ping=MagickTrue;
316 image=ReadStream(ping_info,&PingStream,exception);
317 if (image != (Image *) NULL)
319 if ((image->columns == 0) || (image->rows == 0))
320 ThrowReaderException(CorruptImageError,
"ImproperImageHeader");
321 ResetTimer(&image->timer);
322 if (ping_info->verbose != MagickFalse)
323 (void) IdentifyImage(image,stdout,MagickFalse,exception);
325 ping_info=DestroyImageInfo(ping_info);
356MagickExport Image *PingImages(ImageInfo *image_info,
const char *filename,
357 ExceptionInfo *exception)
360 ping_filename[MagickPathExtent];
372 assert(image_info != (ImageInfo *) NULL);
373 assert(image_info->signature == MagickCoreSignature);
374 assert(exception != (ExceptionInfo *) NULL);
375 if (IsEventLogging() != MagickFalse)
376 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
377 image_info->filename);
378 (void) SetImageOption(image_info,
"filename",filename);
379 (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
380 (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
381 (
int) image_info->scene,ping_filename,exception);
382 if (LocaleCompare(ping_filename,image_info->filename) != 0)
394 read_info=CloneImageInfo(image_info);
395 sans=AcquireExceptionInfo();
396 (void) SetImageInfo(read_info,0,sans);
397 sans=DestroyExceptionInfo(sans);
398 if (read_info->number_scenes == 0)
400 read_info=DestroyImageInfo(read_info);
401 return(PingImage(image_info,exception));
403 (void) CopyMagickString(ping_filename,read_info->filename,
405 images=NewImageList();
406 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
407 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
409 (void) InterpretImageFilename(image_info,(Image *) NULL,ping_filename,
410 (
int) scene,read_info->filename,exception);
411 image=PingImage(read_info,exception);
412 if (image == (Image *) NULL)
414 AppendImageToList(&images,image);
416 read_info=DestroyImageInfo(read_info);
419 return(PingImage(image_info,exception));
451static MagickBooleanType IsCoderAuthorized(
const char *module,
452 const char *coder,
const PolicyRights rights,ExceptionInfo *exception)
454 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
455 ThrowPolicyException(coder,MagickFalse);
456 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
457 ThrowPolicyException(module,MagickFalse);
461static void InitializeConstituteInfo(
const ImageInfo *image_info,
462 ConstituteInfo *constitute_info)
467 memset(constitute_info,0,
sizeof(*constitute_info));
468 constitute_info->sync_from_exif=MagickTrue;
469 constitute_info->sync_from_tiff=MagickTrue;
470 option=GetImageOption(image_info,
"exif:sync-image");
471 if (IsStringFalse(option) != MagickFalse)
472 constitute_info->sync_from_exif=MagickFalse;
473 option=GetImageOption(image_info,
"tiff:sync-image");
474 if (IsStringFalse(option) != MagickFalse)
475 constitute_info->sync_from_tiff=MagickFalse;
476 constitute_info->caption=GetImageOption(image_info,
"caption");
477 constitute_info->comment=GetImageOption(image_info,
"comment");
478 constitute_info->label=GetImageOption(image_info,
"label");
479 option=GetImageOption(image_info,
"delay");
480 if (option != (
const char *) NULL)
485 constitute_info->delay_flags=ParseGeometry(option,&geometry_info);
486 if (constitute_info->delay_flags != NoValue)
488 constitute_info->delay=(size_t) floor(geometry_info.rho+0.5);
489 if ((constitute_info->delay_flags & SigmaValue) != 0)
490 constitute_info->ticks_per_second=CastDoubleToSsizeT(floor(
491 geometry_info.sigma+0.5));
496static void SyncOrientationFromProperties(Image *image,
497 ConstituteInfo *constitute_info,ExceptionInfo *exception)
502 orientation=(
const char *) NULL;
503 if (constitute_info->sync_from_exif != MagickFalse)
505 orientation=GetImageProperty(image,
"exif:Orientation",exception);
506 if (orientation != (
const char *) NULL)
508 image->orientation=(OrientationType) StringToLong(orientation);
509 (void) DeleteImageProperty(image,
"exif:Orientation");
512 if ((orientation == (
const char *) NULL) &&
513 (constitute_info->sync_from_tiff != MagickFalse))
515 orientation=GetImageProperty(image,
"tiff:Orientation",exception);
516 if (orientation != (
const char *) NULL)
518 image->orientation=(OrientationType) StringToLong(orientation);
519 (void) DeleteImageProperty(image,
"tiff:Orientation");
524static void SyncResolutionFromProperties(Image *image,
525 ConstituteInfo *constitute_info, ExceptionInfo *exception)
535 resolution_x=(
const char *) NULL;
536 resolution_y=(
const char *) NULL;
537 resolution_units=(
const char *) NULL;
538 used_tiff=MagickFalse;
539 if (constitute_info->sync_from_exif != MagickFalse)
541 resolution_x=GetImageProperty(image,
"exif:XResolution",exception);
542 resolution_y=GetImageProperty(image,
"exif:YResolution",exception);
543 if ((resolution_x != (
const char *) NULL) &&
544 (resolution_y != (
const char *) NULL))
545 resolution_units=GetImageProperty(image,
"exif:ResolutionUnit",
548 if ((resolution_x == (
const char *) NULL) &&
549 (resolution_y == (
const char *) NULL) &&
550 (constitute_info->sync_from_tiff != MagickFalse))
552 resolution_x=GetImageProperty(image,
"tiff:XResolution",exception);
553 resolution_y=GetImageProperty(image,
"tiff:YResolution",exception);
554 if ((resolution_x != (
const char *) NULL) &&
555 (resolution_y != (
const char *) NULL))
557 used_tiff=MagickTrue;
558 resolution_units=GetImageProperty(image,
"tiff:ResolutionUnit",
562 if ((resolution_x != (
const char *) NULL) &&
563 (resolution_y != (
const char *) NULL))
571 geometry_info.rho=image->resolution.x;
572 geometry_info.sigma=1.0;
573 (void) ParseGeometry(resolution_x,&geometry_info);
574 if (geometry_info.sigma != 0)
575 image->resolution.x=geometry_info.rho/geometry_info.sigma;
576 if (strchr(resolution_x,
',') != (
char *) NULL)
577 image->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
578 geometry_info.rho=image->resolution.y;
579 geometry_info.sigma=1.0;
580 (void) ParseGeometry(resolution_y,&geometry_info);
581 if (geometry_info.sigma != 0)
582 image->resolution.y=geometry_info.rho/geometry_info.sigma;
583 if (strchr(resolution_y,
',') != (
char *) NULL)
584 image->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
585 if (resolution_units != (
char *) NULL)
587 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
589 if (option_type >= 0)
590 image->units=(ResolutionType) option_type;
592 if (used_tiff == MagickFalse)
594 (void) DeleteImageProperty(image,
"exif:XResolution");
595 (void) DeleteImageProperty(image,
"exif:YResolution");
596 (void) DeleteImageProperty(image,
"exif:ResolutionUnit");
600 (void) DeleteImageProperty(image,
"tiff:XResolution");
601 (void) DeleteImageProperty(image,
"tiff:YResolution");
602 (void) DeleteImageProperty(image,
"tiff:ResolutionUnit");
607MagickExport Image *ReadImage(
const ImageInfo *image_info,
608 ExceptionInfo *exception)
611 filename[MagickPathExtent],
612 magick[MagickPathExtent],
613 magick_filename[MagickPathExtent];
643 assert(image_info != (ImageInfo *) NULL);
644 assert(image_info->signature == MagickCoreSignature);
645 assert(image_info->filename != (
char *) NULL);
646 if (IsEventLogging() != MagickFalse)
647 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
648 image_info->filename);
649 assert(exception != (ExceptionInfo *) NULL);
650 read_info=CloneImageInfo(image_info);
651 (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
652 (void) SetImageInfo(read_info,0,exception);
653 (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
654 (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
658 sans_exception=AcquireExceptionInfo();
659 magick_info=GetMagickInfo(read_info->magick,sans_exception);
660 if (sans_exception->severity == PolicyError)
661 InheritException(exception,sans_exception);
662 sans_exception=DestroyExceptionInfo(sans_exception);
663 if (magick_info != (
const MagickInfo *) NULL)
665 if (GetMagickEndianSupport(magick_info) == MagickFalse)
666 read_info->endian=UndefinedEndian;
668 if ((image_info->endian == UndefinedEndian) &&
669 (GetMagickRawSupport(magick_info) != MagickFalse))
675 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
679 if ((magick_info != (
const MagickInfo *) NULL) &&
680 (GetMagickDecoderSeekableStream(magick_info) != MagickFalse))
682 image=AcquireImage(read_info,exception);
683 (void) CopyMagickString(image->filename,read_info->filename,
685 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
686 if (status == MagickFalse)
688 read_info=DestroyImageInfo(read_info);
689 image=DestroyImage(image);
690 return((Image *) NULL);
692 if (IsBlobSeekable(image) == MagickFalse)
697 *read_info->filename=
'\0';
698 status=ImageToFile(image,read_info->filename,exception);
699 if (status == MagickFalse)
701 (void) CloseBlob(image);
702 read_info=DestroyImageInfo(read_info);
703 image=DestroyImage(image);
704 return((Image *) NULL);
706 read_info->temporary=MagickTrue;
708 (void) CloseBlob(image);
709 image=DestroyImage(image);
711 image=NewImageList();
712 decoder=GetImageDecoder(magick_info);
713 if (decoder == (DecodeImageHandler *) NULL)
715 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
716 if (delegate_info == (
const DelegateInfo *) NULL)
718 (void) SetImageInfo(read_info,0,exception);
719 (void) CopyMagickString(read_info->filename,filename,
721 magick_info=GetMagickInfo(read_info->magick,exception);
722 decoder=GetImageDecoder(magick_info);
725 if (decoder != (DecodeImageHandler *) NULL)
730 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
731 LockSemaphoreInfo(magick_info->semaphore);
732 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
733 ReadPolicyRights,exception);
734 image=(Image *) NULL;
735 if (status != MagickFalse)
736 image=decoder(read_info,exception);
737 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
738 UnlockSemaphoreInfo(magick_info->semaphore);
742 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
743 if (delegate_info == (
const DelegateInfo *) NULL)
745 (void) ThrowMagickException(exception,GetMagickModule(),
746 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
747 read_info->filename);
748 if (read_info->temporary != MagickFalse)
749 (void) RelinquishUniqueFileResource(read_info->filename);
750 read_info=DestroyImageInfo(read_info);
751 return((Image *) NULL);
756 image=AcquireImage(read_info,exception);
757 if (image == (Image *) NULL)
759 read_info=DestroyImageInfo(read_info);
760 return((Image *) NULL);
762 (void) CopyMagickString(image->filename,read_info->filename,
764 *read_info->filename=
'\0';
765 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
766 LockSemaphoreInfo(delegate_info->semaphore);
767 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
769 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
770 UnlockSemaphoreInfo(delegate_info->semaphore);
771 image=DestroyImageList(image);
772 read_info->temporary=MagickTrue;
773 if (status != MagickFalse)
774 (void) SetImageInfo(read_info,0,exception);
775 magick_info=GetMagickInfo(read_info->magick,exception);
776 decoder=GetImageDecoder(magick_info);
777 if (decoder == (DecodeImageHandler *) NULL)
779 if (IsPathAccessible(read_info->filename) != MagickFalse)
780 (void) ThrowMagickException(exception,GetMagickModule(),
781 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
784 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
785 read_info->filename);
786 read_info=DestroyImageInfo(read_info);
787 return((Image *) NULL);
792 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
793 LockSemaphoreInfo(magick_info->semaphore);
794 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
795 ReadPolicyRights,exception);
796 image=(Image *) NULL;
797 if (status != MagickFalse)
798 image=(decoder)(read_info,exception);
799 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
800 UnlockSemaphoreInfo(magick_info->semaphore);
802 if (read_info->temporary != MagickFalse)
804 (void) RelinquishUniqueFileResource(read_info->filename);
805 read_info->temporary=MagickFalse;
806 if (image != (Image *) NULL)
807 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
809 if (image == (Image *) NULL)
811 read_info=DestroyImageInfo(read_info);
814 if (exception->severity >= ErrorException)
815 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
816 "Coder (%s) generated an image despite an error (%d), "
817 "notify the developers",image->magick,exception->severity);
818 if (IsBlobTemporary(image) != MagickFalse)
819 (void) RelinquishUniqueFileResource(read_info->filename);
820 if (read_info->ping != MagickFalse)
822 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
824 if ((image->columns == 0) || (image->rows == 0))
826 read_info=DestroyImageInfo(read_info);
827 ThrowReaderException(ImageError,
"NegativeOrZeroImageSize");
831 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
832 (GetImageListLength(image) != 1))
837 clones=CloneImages(image,read_info->scenes,exception);
838 image=DestroyImageList(image);
839 if (clones != (Image *) NULL)
840 image=GetFirstImageInList(clones);
841 if (image == (Image *) NULL)
843 read_info=DestroyImageInfo(read_info);
847 InitializeConstituteInfo(read_info,&constitute_info);
848 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
851 magick_path[MagickPathExtent],
857 next->taint=MagickFalse;
858 GetPathComponent(magick_filename,MagickPath,magick_path);
859 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
860 (void) CopyMagickString(next->magick,magick,MagickPathExtent);
861 (void) CopyMagickString(next->magick_filename,magick_filename,
863 if (IsBlobTemporary(image) != MagickFalse)
864 (void) CopyMagickString(next->filename,filename,MagickPathExtent);
865 if (next->magick_columns == 0)
866 next->magick_columns=next->columns;
867 if (next->magick_rows == 0)
868 next->magick_rows=next->rows;
869 (void) GetImageProperty(next,
"exif:*",exception);
870 (void) GetImageProperty(next,
"icc:*",exception);
871 (void) GetImageProperty(next,
"iptc:*",exception);
872 (void) GetImageProperty(next,
"xmp:*",exception);
873 SyncOrientationFromProperties(next,&constitute_info,exception);
874 SyncResolutionFromProperties(next,&constitute_info,exception);
875 if (next->page.width == 0)
876 next->page.width=next->columns;
877 if (next->page.height == 0)
878 next->page.height=next->rows;
879 if (constitute_info.caption != (
const char *) NULL)
881 property=InterpretImageProperties(read_info,next,
882 constitute_info.caption,exception);
883 (void) SetImageProperty(next,
"caption",property,exception);
884 property=DestroyString(property);
886 if (constitute_info.comment != (
const char *) NULL)
888 property=InterpretImageProperties(read_info,next,
889 constitute_info.comment,exception);
890 (void) SetImageProperty(next,
"comment",property,exception);
891 property=DestroyString(property);
893 if (constitute_info.label != (
const char *) NULL)
895 property=InterpretImageProperties(read_info,next,
896 constitute_info.label,exception);
897 (void) SetImageProperty(next,
"label",property,exception);
898 property=DestroyString(property);
900 if (LocaleCompare(next->magick,
"TEXT") == 0)
901 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
902 if ((read_info->extract != (
char *) NULL) &&
903 (read_info->stream == (StreamHandler) NULL))
911 SetGeometry(next,&geometry);
912 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
913 if ((next->columns != geometry.width) ||
914 (next->rows != geometry.height))
916 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
918 Image *crop_image = CropImage(next,&geometry,exception);
919 if (crop_image != (Image *) NULL)
920 ReplaceImageInList(&next,crop_image);
923 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
925 flags=ParseRegionGeometry(next,read_info->extract,&geometry,
927 if ((geometry.width != 0) && (geometry.height != 0))
929 Image *resize_image = ResizeImage(next,geometry.width,
930 geometry.height,next->filter,exception);
931 if (resize_image != (Image *) NULL)
932 ReplaceImageInList(&next,resize_image);
937 profile=GetImageProfile(next,
"icc");
938 if (profile == (
const StringInfo *) NULL)
939 profile=GetImageProfile(next,
"icm");
940 profile=GetImageProfile(next,
"iptc");
941 if (profile == (
const StringInfo *) NULL)
942 profile=GetImageProfile(next,
"8bim");
943 if (IsSourceDataEpochSet() == MagickFalse)
946 timestamp[MagickTimeExtent];
948 (void) FormatMagickTime(next->timestamp,
sizeof(timestamp),timestamp);
949 (void) SetImageProperty(next,
"date:timestamp",timestamp,exception);
950 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
951 sizeof(timestamp),timestamp);
952 (void) SetImageProperty(next,
"date:modify",timestamp,exception);
953 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
954 sizeof(timestamp),timestamp);
955 (void) SetImageProperty(next,
"date:create",timestamp,exception);
957 if (constitute_info.delay_flags != NoValue)
959 if ((constitute_info.delay_flags & GreaterValue) != 0)
961 if (next->delay > constitute_info.delay)
962 next->delay=constitute_info.delay;
965 if ((constitute_info.delay_flags & LessValue) != 0)
967 if (next->delay < constitute_info.delay)
968 next->delay=constitute_info.delay;
971 next->delay=constitute_info.delay;
972 if ((constitute_info.delay_flags & SigmaValue) != 0)
973 next->ticks_per_second=constitute_info.ticks_per_second;
975 if (constitute_info.dispose != (
const char *) NULL)
980 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
981 constitute_info.dispose);
982 if (option_type >= 0)
983 next->dispose=(DisposeType) option_type;
985 if (read_info->verbose != MagickFalse)
986 (void) IdentifyImage(next,stderr,MagickFalse,exception);
989 read_info=DestroyImageInfo(read_info);
990 if (GetBlobError(image) != MagickFalse)
991 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
992 return(GetFirstImageInList(image));
1022MagickExport Image *ReadImages(ImageInfo *image_info,
const char *filename,
1023 ExceptionInfo *exception)
1026 read_filename[MagickPathExtent];
1038 assert(image_info != (ImageInfo *) NULL);
1039 assert(image_info->signature == MagickCoreSignature);
1040 assert(exception != (ExceptionInfo *) NULL);
1041 if (IsEventLogging() != MagickFalse)
1042 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1043 image_info->filename);
1044 read_info=CloneImageInfo(image_info);
1045 *read_info->magick=
'\0';
1046 (void) SetImageOption(read_info,
"filename",filename);
1047 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1048 (void) InterpretImageFilename(read_info,(Image *) NULL,filename,
1049 (
int) read_info->scene,read_filename,exception);
1050 if (LocaleCompare(read_filename,read_info->filename) != 0)
1062 sans=AcquireExceptionInfo();
1063 (void) SetImageInfo(read_info,0,sans);
1064 sans=DestroyExceptionInfo(sans);
1065 if (read_info->number_scenes != 0)
1067 (void) CopyMagickString(read_filename,read_info->filename,
1069 images=NewImageList();
1070 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
1071 scene=(ssize_t) read_info->scene;
1072 for ( ; scene < (ssize_t) extent; scene++)
1074 (void) InterpretImageFilename(image_info,(Image *) NULL,
1075 read_filename,(
int) scene,read_info->filename,exception);
1076 image=ReadImage(read_info,exception);
1077 if (image == (Image *) NULL)
1079 AppendImageToList(&images,image);
1081 read_info=DestroyImageInfo(read_info);
1085 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1086 image=ReadImage(read_info,exception);
1087 read_info=DestroyImageInfo(read_info);
1121MagickExport Image *ReadInlineImage(
const ImageInfo *image_info,
1122 const char *content,ExceptionInfo *exception)
1142 image=NewImageList();
1143 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1145 ThrowReaderException(CorruptImageError,
"CorruptImage");
1146 blob=Base64Decode(++p,&length);
1149 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1150 ThrowReaderException(CorruptImageError,
"CorruptImage");
1152 read_info=CloneImageInfo(image_info);
1153 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1155 *read_info->filename=
'\0';
1156 *read_info->magick=
'\0';
1157 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1169 if (LocaleNCompare(++p,
"x-",2) == 0)
1171 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1172 q=read_info->filename+5;
1173 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1177 image=BlobToImage(read_info,blob,length,exception);
1178 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1179 read_info=DestroyImageInfo(read_info);
1214MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1215 Image *image,ExceptionInfo *exception)
1218 filename[MagickPathExtent];
1245 assert(image_info != (ImageInfo *) NULL);
1246 assert(image_info->signature == MagickCoreSignature);
1247 assert(image != (Image *) NULL);
1248 if (IsEventLogging() != MagickFalse)
1249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1250 image_info->filename);
1251 assert(image->signature == MagickCoreSignature);
1252 assert(exception != (ExceptionInfo *) NULL);
1253 sans_exception=AcquireExceptionInfo();
1254 write_info=CloneImageInfo(image_info);
1255 (void) CopyMagickString(write_info->filename,image->filename,
1257 (void) SetImageInfo(write_info,1,sans_exception);
1258 if (*write_info->magick ==
'\0')
1259 (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1260 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1261 (void) CopyMagickString(image->filename,write_info->filename,
1266 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1267 if (sans_exception->severity == PolicyError)
1268 magick_info=GetMagickInfo(write_info->magick,exception);
1269 sans_exception=DestroyExceptionInfo(sans_exception);
1270 if (magick_info != (
const MagickInfo *) NULL)
1272 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1273 image->endian=UndefinedEndian;
1275 if ((image_info->endian == UndefinedEndian) &&
1276 (GetMagickRawSupport(magick_info) != MagickFalse))
1282 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1285 if ((image->ping != MagickFalse) &&
1286 (SyncImagePixelCache(image,exception) == MagickFalse))
1288 write_info=DestroyImageInfo(write_info);
1289 return(MagickFalse);
1291 SyncImageProfiles(image);
1292 DisassociateImageStream(image);
1293 option=GetImageOption(image_info,
"delegate:bimodal");
1294 if ((IsStringTrue(option) != MagickFalse) &&
1295 (write_info->page == (
char *) NULL) &&
1296 (GetPreviousImageInList(image) == (Image *) NULL) &&
1297 (GetNextImageInList(image) == (Image *) NULL) &&
1298 (IsTaintImage(image) == MagickFalse) )
1300 delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1301 if ((delegate_info != (
const DelegateInfo *) NULL) &&
1302 (GetDelegateMode(delegate_info) == 0) &&
1303 (IsPathAccessible(image->magick_filename) != MagickFalse))
1308 (void) CopyMagickString(image->filename,image->magick_filename,
1310 status=InvokeDelegate(write_info,image,image->magick,
1311 write_info->magick,exception);
1312 write_info=DestroyImageInfo(write_info);
1313 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1318 temporary=MagickFalse;
1319 if ((magick_info != (
const MagickInfo *) NULL) &&
1320 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1323 image_filename[MagickPathExtent];
1325 (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1326 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1327 (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1328 if (status != MagickFalse)
1330 if (IsBlobSeekable(image) == MagickFalse)
1335 write_info->adjoin=MagickTrue;
1336 (void) CopyMagickString(write_info->filename,image->filename,
1338 (void) AcquireUniqueFilename(image->filename);
1339 temporary=MagickTrue;
1341 if (CloseBlob(image) == MagickFalse)
1345 encoder=GetImageEncoder(magick_info);
1346 if (encoder != (EncodeImageHandler *) NULL)
1351 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1352 LockSemaphoreInfo(magick_info->semaphore);
1353 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1354 WritePolicyRights,exception);
1355 if (status != MagickFalse)
1356 status=encoder(write_info,image,exception);
1357 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1358 UnlockSemaphoreInfo(magick_info->semaphore);
1362 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,exception);
1363 if (delegate_info != (DelegateInfo *) NULL)
1368 *write_info->filename=
'\0';
1369 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1370 LockSemaphoreInfo(delegate_info->semaphore);
1371 status=InvokeDelegate(write_info,image,(
char *) NULL,
1372 write_info->magick,exception);
1373 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1374 UnlockSemaphoreInfo(delegate_info->semaphore);
1375 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1379 sans_exception=AcquireExceptionInfo();
1380 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1381 if (sans_exception->severity == PolicyError)
1382 magick_info=GetMagickInfo(write_info->magick,exception);
1383 sans_exception=DestroyExceptionInfo(sans_exception);
1384 if ((write_info->affirm == MagickFalse) &&
1385 (magick_info == (
const MagickInfo *) NULL))
1387 (void) CopyMagickString(write_info->magick,image->magick,
1389 magick_info=GetMagickInfo(write_info->magick,exception);
1391 encoder=GetImageEncoder(magick_info);
1392 if (encoder == (EncodeImageHandler *) NULL)
1395 extension[MagickPathExtent];
1397 GetPathComponent(image->filename,ExtensionPath,extension);
1398 if (*extension !=
'\0')
1399 magick_info=GetMagickInfo(extension,exception);
1401 magick_info=GetMagickInfo(image->magick,exception);
1402 (void) CopyMagickString(image->filename,filename,
1404 encoder=GetImageEncoder(magick_info);
1405 (void) ThrowMagickException(exception,GetMagickModule(),
1406 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1407 "`%s'",write_info->magick);
1409 if (encoder == (EncodeImageHandler *) NULL)
1411 magick_info=GetMagickInfo(image->magick,exception);
1412 encoder=GetImageEncoder(magick_info);
1413 if (encoder == (EncodeImageHandler *) NULL)
1414 (void) ThrowMagickException(exception,GetMagickModule(),
1415 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1416 "`%s'",write_info->magick);
1418 if (encoder != (EncodeImageHandler *) NULL)
1423 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1424 LockSemaphoreInfo(magick_info->semaphore);
1425 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1426 WritePolicyRights,exception);
1427 if (status != MagickFalse)
1428 status=encoder(write_info,image,exception);
1429 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1430 UnlockSemaphoreInfo(magick_info->semaphore);
1434 if (temporary != MagickFalse)
1439 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1440 if (status != MagickFalse)
1442 (void) RelinquishUniqueFileResource(write_info->filename);
1443 status=ImageToFile(image,write_info->filename,exception);
1445 if (CloseBlob(image) == MagickFalse)
1447 (void) RelinquishUniqueFileResource(image->filename);
1448 (void) CopyMagickString(image->filename,write_info->filename,
1451 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1452 (write_info->verbose != MagickFalse))
1453 (void) IdentifyImage(image,stdout,MagickFalse,exception);
1454 write_info=DestroyImageInfo(write_info);
1455 if (GetBlobError(image) != MagickFalse)
1456 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1496MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1497 Image *images,
const char *filename,ExceptionInfo *exception)
1499#define WriteImageTag "Write/Image"
1513 MagickProgressMonitor
1525 assert(image_info != (
const ImageInfo *) NULL);
1526 assert(image_info->signature == MagickCoreSignature);
1527 assert(images != (Image *) NULL);
1528 assert(images->signature == MagickCoreSignature);
1529 if (IsEventLogging() != MagickFalse)
1530 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1531 assert(exception != (ExceptionInfo *) NULL);
1532 write_info=CloneImageInfo(image_info);
1533 *write_info->magick=
'\0';
1534 images=GetFirstImageInList(images);
1535 if (images == (Image *) NULL)
1536 return(MagickFalse);
1537 if (filename != (
const char *) NULL)
1538 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1539 (
void) CopyMagickString(p->filename,filename,MagickPathExtent);
1540 (void) CopyMagickString(write_info->filename,images->filename,
1542 sans_exception=AcquireExceptionInfo();
1543 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1545 sans_exception=DestroyExceptionInfo(sans_exception);
1546 if (*write_info->magick ==
'\0')
1547 (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1549 for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1551 if (p->scene >= GetNextImageInList(p)->scene)
1559 i=(ssize_t) images->scene;
1560 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1561 p->scene=(
size_t) i++;
1569 progress_monitor=(MagickProgressMonitor) NULL;
1571 number_images=GetImageListLength(images);
1572 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1574 if (number_images != 1)
1575 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1577 status&=(MagickStatusType) WriteImage(write_info,p,exception);
1578 if (number_images != 1)
1579 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1580 if (write_info->adjoin != MagickFalse)
1582 if (number_images != 1)
1584#if defined(MAGICKCORE_OPENMP_SUPPORT)
1588 proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1589 if (proceed == MagickFalse)
1593 write_info=DestroyImageInfo(write_info);
1594 return(status != 0 ? MagickTrue : MagickFalse);