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)
457 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
458 "NotAuthorized",
"`%s'",coder);
461 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
464 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
465 "NotAuthorized",
"`%s'",module);
471static void InitializeConstituteInfo(
const ImageInfo *image_info,
472 ConstituteInfo *constitute_info)
477 memset(constitute_info,0,
sizeof(*constitute_info));
478 constitute_info->sync_from_exif=MagickTrue;
479 constitute_info->sync_from_tiff=MagickTrue;
480 option=GetImageOption(image_info,
"exif:sync-image");
481 if (IsStringFalse(option) != MagickFalse)
482 constitute_info->sync_from_exif=MagickFalse;
483 option=GetImageOption(image_info,
"tiff:sync-image");
484 if (IsStringFalse(option) != MagickFalse)
485 constitute_info->sync_from_tiff=MagickFalse;
486 constitute_info->caption=GetImageOption(image_info,
"caption");
487 constitute_info->comment=GetImageOption(image_info,
"comment");
488 constitute_info->label=GetImageOption(image_info,
"label");
489 option=GetImageOption(image_info,
"delay");
490 if (option != (
const char *) NULL)
495 constitute_info->delay_flags=ParseGeometry(option,&geometry_info);
496 if (constitute_info->delay_flags != NoValue)
498 constitute_info->delay=(size_t) floor(geometry_info.rho+0.5);
499 if ((constitute_info->delay_flags & SigmaValue) != 0)
500 constitute_info->ticks_per_second=CastDoubleToSsizeT(floor(
501 geometry_info.sigma+0.5));
506static void SyncOrientationFromProperties(Image *image,
507 ConstituteInfo *constitute_info,ExceptionInfo *exception)
512 orientation=(
const char *) NULL;
513 if (constitute_info->sync_from_exif != MagickFalse)
515 orientation=GetImageProperty(image,
"exif:Orientation",exception);
516 if (orientation != (
const char *) NULL)
518 image->orientation=(OrientationType) StringToLong(orientation);
519 (void) DeleteImageProperty(image,
"exif:Orientation");
522 if ((orientation == (
const char *) NULL) &&
523 (constitute_info->sync_from_tiff != MagickFalse))
525 orientation=GetImageProperty(image,
"tiff:Orientation",exception);
526 if (orientation != (
const char *) NULL)
528 image->orientation=(OrientationType) StringToLong(orientation);
529 (void) DeleteImageProperty(image,
"tiff:Orientation");
534static void SyncResolutionFromProperties(Image *image,
535 ConstituteInfo *constitute_info, ExceptionInfo *exception)
545 resolution_x=(
const char *) NULL;
546 resolution_y=(
const char *) NULL;
547 resolution_units=(
const char *) NULL;
548 used_tiff=MagickFalse;
549 if (constitute_info->sync_from_exif != MagickFalse)
551 resolution_x=GetImageProperty(image,
"exif:XResolution",exception);
552 resolution_y=GetImageProperty(image,
"exif:YResolution",exception);
553 if ((resolution_x != (
const char *) NULL) &&
554 (resolution_y != (
const char *) NULL))
555 resolution_units=GetImageProperty(image,
"exif:ResolutionUnit",
558 if ((resolution_x == (
const char *) NULL) &&
559 (resolution_y == (
const char *) NULL) &&
560 (constitute_info->sync_from_tiff != MagickFalse))
562 resolution_x=GetImageProperty(image,
"tiff:XResolution",exception);
563 resolution_y=GetImageProperty(image,
"tiff:YResolution",exception);
564 if ((resolution_x != (
const char *) NULL) &&
565 (resolution_y != (
const char *) NULL))
567 used_tiff=MagickTrue;
568 resolution_units=GetImageProperty(image,
"tiff:ResolutionUnit",
572 if ((resolution_x != (
const char *) NULL) &&
573 (resolution_y != (
const char *) NULL))
581 geometry_info.rho=image->resolution.x;
582 geometry_info.sigma=1.0;
583 (void) ParseGeometry(resolution_x,&geometry_info);
584 if (geometry_info.sigma != 0)
585 image->resolution.x=geometry_info.rho/geometry_info.sigma;
586 if (strchr(resolution_x,
',') != (
char *) NULL)
587 image->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
588 geometry_info.rho=image->resolution.y;
589 geometry_info.sigma=1.0;
590 (void) ParseGeometry(resolution_y,&geometry_info);
591 if (geometry_info.sigma != 0)
592 image->resolution.y=geometry_info.rho/geometry_info.sigma;
593 if (strchr(resolution_y,
',') != (
char *) NULL)
594 image->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
595 if (resolution_units != (
char *) NULL)
597 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
599 if (option_type >= 0)
600 image->units=(ResolutionType) option_type;
602 if (used_tiff == MagickFalse)
604 (void) DeleteImageProperty(image,
"exif:XResolution");
605 (void) DeleteImageProperty(image,
"exif:YResolution");
606 (void) DeleteImageProperty(image,
"exif:ResolutionUnit");
610 (void) DeleteImageProperty(image,
"tiff:XResolution");
611 (void) DeleteImageProperty(image,
"tiff:YResolution");
612 (void) DeleteImageProperty(image,
"tiff:ResolutionUnit");
617MagickExport Image *ReadImage(
const ImageInfo *image_info,
618 ExceptionInfo *exception)
621 filename[MagickPathExtent],
622 magick[MagickPathExtent],
623 magick_filename[MagickPathExtent];
653 assert(image_info != (ImageInfo *) NULL);
654 assert(image_info->signature == MagickCoreSignature);
655 assert(image_info->filename != (
char *) NULL);
656 if (IsEventLogging() != MagickFalse)
657 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
658 image_info->filename);
659 assert(exception != (ExceptionInfo *) NULL);
660 read_info=CloneImageInfo(image_info);
661 (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
662 (void) SetImageInfo(read_info,0,exception);
663 (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
664 (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
668 sans_exception=AcquireExceptionInfo();
669 magick_info=GetMagickInfo(read_info->magick,sans_exception);
670 if (sans_exception->severity == PolicyError)
671 InheritException(exception,sans_exception);
672 sans_exception=DestroyExceptionInfo(sans_exception);
673 if (magick_info != (
const MagickInfo *) NULL)
675 if (GetMagickEndianSupport(magick_info) == MagickFalse)
676 read_info->endian=UndefinedEndian;
678 if ((image_info->endian == UndefinedEndian) &&
679 (GetMagickRawSupport(magick_info) != MagickFalse))
685 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
689 if ((magick_info != (
const MagickInfo *) NULL) &&
690 (GetMagickDecoderSeekableStream(magick_info) != MagickFalse))
692 image=AcquireImage(read_info,exception);
693 (void) CopyMagickString(image->filename,read_info->filename,
695 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
696 if (status == MagickFalse)
698 read_info=DestroyImageInfo(read_info);
699 image=DestroyImage(image);
700 return((Image *) NULL);
702 if (IsBlobSeekable(image) == MagickFalse)
707 *read_info->filename=
'\0';
708 status=ImageToFile(image,read_info->filename,exception);
709 if (status == MagickFalse)
711 (void) CloseBlob(image);
712 read_info=DestroyImageInfo(read_info);
713 image=DestroyImage(image);
714 return((Image *) NULL);
716 read_info->temporary=MagickTrue;
718 (void) CloseBlob(image);
719 image=DestroyImage(image);
721 image=NewImageList();
722 decoder=GetImageDecoder(magick_info);
723 if (decoder == (DecodeImageHandler *) NULL)
725 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
726 if (delegate_info == (
const DelegateInfo *) NULL)
728 (void) SetImageInfo(read_info,0,exception);
729 (void) CopyMagickString(read_info->filename,filename,
731 magick_info=GetMagickInfo(read_info->magick,exception);
732 decoder=GetImageDecoder(magick_info);
735 if (decoder != (DecodeImageHandler *) NULL)
740 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
741 LockSemaphoreInfo(magick_info->semaphore);
742 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
743 ReadPolicyRights,exception);
744 image=(Image *) NULL;
745 if (status != MagickFalse)
746 image=decoder(read_info,exception);
747 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
748 UnlockSemaphoreInfo(magick_info->semaphore);
752 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
753 if (delegate_info == (
const DelegateInfo *) NULL)
755 (void) ThrowMagickException(exception,GetMagickModule(),
756 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
757 read_info->filename);
758 if (read_info->temporary != MagickFalse)
759 (void) RelinquishUniqueFileResource(read_info->filename);
760 read_info=DestroyImageInfo(read_info);
761 return((Image *) NULL);
766 image=AcquireImage(read_info,exception);
767 if (image == (Image *) NULL)
769 read_info=DestroyImageInfo(read_info);
770 return((Image *) NULL);
772 (void) CopyMagickString(image->filename,read_info->filename,
774 *read_info->filename=
'\0';
775 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
776 LockSemaphoreInfo(delegate_info->semaphore);
777 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
779 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
780 UnlockSemaphoreInfo(delegate_info->semaphore);
781 image=DestroyImageList(image);
782 read_info->temporary=MagickTrue;
783 if (status != MagickFalse)
784 (void) SetImageInfo(read_info,0,exception);
785 magick_info=GetMagickInfo(read_info->magick,exception);
786 decoder=GetImageDecoder(magick_info);
787 if (decoder == (DecodeImageHandler *) NULL)
789 if (IsPathAccessible(read_info->filename) != MagickFalse)
790 (void) ThrowMagickException(exception,GetMagickModule(),
791 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
794 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
795 read_info->filename);
796 read_info=DestroyImageInfo(read_info);
797 return((Image *) NULL);
802 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
803 LockSemaphoreInfo(magick_info->semaphore);
804 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
805 ReadPolicyRights,exception);
806 image=(Image *) NULL;
807 if (status != MagickFalse)
808 image=(decoder)(read_info,exception);
809 if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
810 UnlockSemaphoreInfo(magick_info->semaphore);
812 if (read_info->temporary != MagickFalse)
814 (void) RelinquishUniqueFileResource(read_info->filename);
815 read_info->temporary=MagickFalse;
816 if (image != (Image *) NULL)
817 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
819 if (image == (Image *) NULL)
821 read_info=DestroyImageInfo(read_info);
824 if (exception->severity >= ErrorException)
825 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
826 "Coder (%s) generated an image despite an error (%d), "
827 "notify the developers",image->magick,exception->severity);
828 if (IsBlobTemporary(image) != MagickFalse)
829 (void) RelinquishUniqueFileResource(read_info->filename);
830 if (read_info->ping != MagickFalse)
832 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
834 if ((image->columns == 0) || (image->rows == 0))
836 read_info=DestroyImageInfo(read_info);
837 ThrowReaderException(ImageError,
"NegativeOrZeroImageSize");
841 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
842 (GetImageListLength(image) != 1))
847 clones=CloneImages(image,read_info->scenes,exception);
848 image=DestroyImageList(image);
849 if (clones != (Image *) NULL)
850 image=GetFirstImageInList(clones);
851 if (image == (Image *) NULL)
853 read_info=DestroyImageInfo(read_info);
857 InitializeConstituteInfo(read_info,&constitute_info);
858 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
861 magick_path[MagickPathExtent],
867 next->taint=MagickFalse;
868 GetPathComponent(magick_filename,MagickPath,magick_path);
869 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
870 (void) CopyMagickString(next->magick,magick,MagickPathExtent);
871 (void) CopyMagickString(next->magick_filename,magick_filename,
873 if (IsBlobTemporary(image) != MagickFalse)
874 (void) CopyMagickString(next->filename,filename,MagickPathExtent);
875 if (next->magick_columns == 0)
876 next->magick_columns=next->columns;
877 if (next->magick_rows == 0)
878 next->magick_rows=next->rows;
879 (void) GetImageProperty(next,
"exif:*",exception);
880 (void) GetImageProperty(next,
"icc:*",exception);
881 (void) GetImageProperty(next,
"iptc:*",exception);
882 (void) GetImageProperty(next,
"xmp:*",exception);
883 SyncOrientationFromProperties(next,&constitute_info,exception);
884 SyncResolutionFromProperties(next,&constitute_info,exception);
885 if (next->page.width == 0)
886 next->page.width=next->columns;
887 if (next->page.height == 0)
888 next->page.height=next->rows;
889 if (constitute_info.caption != (
const char *) NULL)
891 property=InterpretImageProperties(read_info,next,
892 constitute_info.caption,exception);
893 (void) SetImageProperty(next,
"caption",property,exception);
894 property=DestroyString(property);
896 if (constitute_info.comment != (
const char *) NULL)
898 property=InterpretImageProperties(read_info,next,
899 constitute_info.comment,exception);
900 (void) SetImageProperty(next,
"comment",property,exception);
901 property=DestroyString(property);
903 if (constitute_info.label != (
const char *) NULL)
905 property=InterpretImageProperties(read_info,next,
906 constitute_info.label,exception);
907 (void) SetImageProperty(next,
"label",property,exception);
908 property=DestroyString(property);
910 if (LocaleCompare(next->magick,
"TEXT") == 0)
911 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
912 if ((read_info->extract != (
char *) NULL) &&
913 (read_info->stream == (StreamHandler) NULL))
921 SetGeometry(next,&geometry);
922 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
923 if ((next->columns != geometry.width) ||
924 (next->rows != geometry.height))
926 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
928 Image *crop_image = CropImage(next,&geometry,exception);
929 if (crop_image != (Image *) NULL)
930 ReplaceImageInList(&next,crop_image);
933 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
935 flags=ParseRegionGeometry(next,read_info->extract,&geometry,
937 if ((geometry.width != 0) && (geometry.height != 0))
939 Image *resize_image = ResizeImage(next,geometry.width,
940 geometry.height,next->filter,exception);
941 if (resize_image != (Image *) NULL)
942 ReplaceImageInList(&next,resize_image);
947 profile=GetImageProfile(next,
"icc");
948 if (profile == (
const StringInfo *) NULL)
949 profile=GetImageProfile(next,
"icm");
950 profile=GetImageProfile(next,
"iptc");
951 if (profile == (
const StringInfo *) NULL)
952 profile=GetImageProfile(next,
"8bim");
953 if (IsSourceDataEpochSet() == MagickFalse)
956 timestamp[MagickTimeExtent];
958 (void) FormatMagickTime(next->timestamp,
sizeof(timestamp),timestamp);
959 (void) SetImageProperty(next,
"date:timestamp",timestamp,exception);
960 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
961 sizeof(timestamp),timestamp);
962 (void) SetImageProperty(next,
"date:modify",timestamp,exception);
963 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
964 sizeof(timestamp),timestamp);
965 (void) SetImageProperty(next,
"date:create",timestamp,exception);
967 if (constitute_info.delay_flags != NoValue)
969 if ((constitute_info.delay_flags & GreaterValue) != 0)
971 if (next->delay > constitute_info.delay)
972 next->delay=constitute_info.delay;
975 if ((constitute_info.delay_flags & LessValue) != 0)
977 if (next->delay < constitute_info.delay)
978 next->delay=constitute_info.delay;
981 next->delay=constitute_info.delay;
982 if ((constitute_info.delay_flags & SigmaValue) != 0)
983 next->ticks_per_second=constitute_info.ticks_per_second;
985 if (constitute_info.dispose != (
const char *) NULL)
990 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
991 constitute_info.dispose);
992 if (option_type >= 0)
993 next->dispose=(DisposeType) option_type;
995 if (read_info->verbose != MagickFalse)
996 (void) IdentifyImage(next,stderr,MagickFalse,exception);
999 read_info=DestroyImageInfo(read_info);
1000 if (GetBlobError(image) != MagickFalse)
1001 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
1002 return(GetFirstImageInList(image));
1032MagickExport Image *ReadImages(ImageInfo *image_info,
const char *filename,
1033 ExceptionInfo *exception)
1036 read_filename[MagickPathExtent];
1048 assert(image_info != (ImageInfo *) NULL);
1049 assert(image_info->signature == MagickCoreSignature);
1050 assert(exception != (ExceptionInfo *) NULL);
1051 if (IsEventLogging() != MagickFalse)
1052 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1053 image_info->filename);
1054 read_info=CloneImageInfo(image_info);
1055 *read_info->magick=
'\0';
1056 (void) SetImageOption(read_info,
"filename",filename);
1057 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1058 (void) InterpretImageFilename(read_info,(Image *) NULL,filename,
1059 (
int) read_info->scene,read_filename,exception);
1060 if (LocaleCompare(read_filename,read_info->filename) != 0)
1072 sans=AcquireExceptionInfo();
1073 (void) SetImageInfo(read_info,0,sans);
1074 sans=DestroyExceptionInfo(sans);
1075 if (read_info->number_scenes != 0)
1077 (void) CopyMagickString(read_filename,read_info->filename,
1079 images=NewImageList();
1080 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
1081 scene=(ssize_t) read_info->scene;
1082 for ( ; scene < (ssize_t) extent; scene++)
1084 (void) InterpretImageFilename(image_info,(Image *) NULL,
1085 read_filename,(
int) scene,read_info->filename,exception);
1086 image=ReadImage(read_info,exception);
1087 if (image == (Image *) NULL)
1089 AppendImageToList(&images,image);
1091 read_info=DestroyImageInfo(read_info);
1095 (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
1096 image=ReadImage(read_info,exception);
1097 read_info=DestroyImageInfo(read_info);
1131MagickExport Image *ReadInlineImage(
const ImageInfo *image_info,
1132 const char *content,ExceptionInfo *exception)
1152 image=NewImageList();
1153 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1155 ThrowReaderException(CorruptImageError,
"CorruptImage");
1156 blob=Base64Decode(++p,&length);
1159 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1160 ThrowReaderException(CorruptImageError,
"CorruptImage");
1162 read_info=CloneImageInfo(image_info);
1163 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1165 *read_info->filename=
'\0';
1166 *read_info->magick=
'\0';
1167 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1179 if (LocaleNCompare(++p,
"x-",2) == 0)
1181 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1182 q=read_info->filename+5;
1183 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1187 image=BlobToImage(read_info,blob,length,exception);
1188 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1189 read_info=DestroyImageInfo(read_info);
1224MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1225 Image *image,ExceptionInfo *exception)
1228 filename[MagickPathExtent];
1255 assert(image_info != (ImageInfo *) NULL);
1256 assert(image_info->signature == MagickCoreSignature);
1257 assert(image != (Image *) NULL);
1258 if (IsEventLogging() != MagickFalse)
1259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1260 image_info->filename);
1261 assert(image->signature == MagickCoreSignature);
1262 assert(exception != (ExceptionInfo *) NULL);
1263 sans_exception=AcquireExceptionInfo();
1264 write_info=CloneImageInfo(image_info);
1265 (void) CopyMagickString(write_info->filename,image->filename,
1267 (void) SetImageInfo(write_info,1,sans_exception);
1268 if (*write_info->magick ==
'\0')
1269 (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1270 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1271 (void) CopyMagickString(image->filename,write_info->filename,
1276 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1277 if (sans_exception->severity == PolicyError)
1278 magick_info=GetMagickInfo(write_info->magick,exception);
1279 sans_exception=DestroyExceptionInfo(sans_exception);
1280 if (magick_info != (
const MagickInfo *) NULL)
1282 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1283 image->endian=UndefinedEndian;
1285 if ((image_info->endian == UndefinedEndian) &&
1286 (GetMagickRawSupport(magick_info) != MagickFalse))
1292 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1295 if ((image->ping != MagickFalse) &&
1296 (SyncImagePixelCache(image,exception) == MagickFalse))
1298 write_info=DestroyImageInfo(write_info);
1299 return(MagickFalse);
1301 SyncImageProfiles(image);
1302 DisassociateImageStream(image);
1303 option=GetImageOption(image_info,
"delegate:bimodal");
1304 if ((IsStringTrue(option) != MagickFalse) &&
1305 (write_info->page == (
char *) NULL) &&
1306 (GetPreviousImageInList(image) == (Image *) NULL) &&
1307 (GetNextImageInList(image) == (Image *) NULL) &&
1308 (IsTaintImage(image) == MagickFalse) )
1310 delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1311 if ((delegate_info != (
const DelegateInfo *) NULL) &&
1312 (GetDelegateMode(delegate_info) == 0) &&
1313 (IsPathAccessible(image->magick_filename) != MagickFalse))
1318 (void) CopyMagickString(image->filename,image->magick_filename,
1320 status=InvokeDelegate(write_info,image,image->magick,
1321 write_info->magick,exception);
1322 write_info=DestroyImageInfo(write_info);
1323 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1328 temporary=MagickFalse;
1329 if ((magick_info != (
const MagickInfo *) NULL) &&
1330 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1333 image_filename[MagickPathExtent];
1335 (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1336 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1337 (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1338 if (status != MagickFalse)
1340 if (IsBlobSeekable(image) == MagickFalse)
1345 write_info->adjoin=MagickTrue;
1346 (void) CopyMagickString(write_info->filename,image->filename,
1348 (void) AcquireUniqueFilename(image->filename);
1349 temporary=MagickTrue;
1351 if (CloseBlob(image) == MagickFalse)
1355 encoder=GetImageEncoder(magick_info);
1356 if (encoder != (EncodeImageHandler *) NULL)
1361 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1362 LockSemaphoreInfo(magick_info->semaphore);
1363 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1364 WritePolicyRights,exception);
1365 if (status != MagickFalse)
1366 status=encoder(write_info,image,exception);
1367 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1368 UnlockSemaphoreInfo(magick_info->semaphore);
1372 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,exception);
1373 if (delegate_info != (DelegateInfo *) NULL)
1378 *write_info->filename=
'\0';
1379 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1380 LockSemaphoreInfo(delegate_info->semaphore);
1381 status=InvokeDelegate(write_info,image,(
char *) NULL,
1382 write_info->magick,exception);
1383 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1384 UnlockSemaphoreInfo(delegate_info->semaphore);
1385 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1389 sans_exception=AcquireExceptionInfo();
1390 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1391 if (sans_exception->severity == PolicyError)
1392 magick_info=GetMagickInfo(write_info->magick,exception);
1393 sans_exception=DestroyExceptionInfo(sans_exception);
1394 if ((write_info->affirm == MagickFalse) &&
1395 (magick_info == (
const MagickInfo *) NULL))
1397 (void) CopyMagickString(write_info->magick,image->magick,
1399 magick_info=GetMagickInfo(write_info->magick,exception);
1401 encoder=GetImageEncoder(magick_info);
1402 if (encoder == (EncodeImageHandler *) NULL)
1405 extension[MagickPathExtent];
1407 GetPathComponent(image->filename,ExtensionPath,extension);
1408 if (*extension !=
'\0')
1409 magick_info=GetMagickInfo(extension,exception);
1411 magick_info=GetMagickInfo(image->magick,exception);
1412 (void) CopyMagickString(image->filename,filename,
1414 encoder=GetImageEncoder(magick_info);
1415 (void) ThrowMagickException(exception,GetMagickModule(),
1416 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1417 "`%s'",write_info->magick);
1419 if (encoder == (EncodeImageHandler *) NULL)
1421 magick_info=GetMagickInfo(image->magick,exception);
1422 encoder=GetImageEncoder(magick_info);
1423 if (encoder == (EncodeImageHandler *) NULL)
1424 (void) ThrowMagickException(exception,GetMagickModule(),
1425 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1426 "`%s'",write_info->magick);
1428 if (encoder != (EncodeImageHandler *) NULL)
1433 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1434 LockSemaphoreInfo(magick_info->semaphore);
1435 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1436 WritePolicyRights,exception);
1437 if (status != MagickFalse)
1438 status=encoder(write_info,image,exception);
1439 if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1440 UnlockSemaphoreInfo(magick_info->semaphore);
1444 if (temporary != MagickFalse)
1449 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1450 if (status != MagickFalse)
1452 (void) RelinquishUniqueFileResource(write_info->filename);
1453 status=ImageToFile(image,write_info->filename,exception);
1455 if (CloseBlob(image) == MagickFalse)
1457 (void) RelinquishUniqueFileResource(image->filename);
1458 (void) CopyMagickString(image->filename,write_info->filename,
1461 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1462 (write_info->verbose != MagickFalse))
1463 (void) IdentifyImage(image,stdout,MagickFalse,exception);
1464 write_info=DestroyImageInfo(write_info);
1465 if (GetBlobError(image) != MagickFalse)
1466 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1506MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1507 Image *images,
const char *filename,ExceptionInfo *exception)
1509#define WriteImageTag "Write/Image"
1523 MagickProgressMonitor
1535 assert(image_info != (
const ImageInfo *) NULL);
1536 assert(image_info->signature == MagickCoreSignature);
1537 assert(images != (Image *) NULL);
1538 assert(images->signature == MagickCoreSignature);
1539 if (IsEventLogging() != MagickFalse)
1540 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1541 assert(exception != (ExceptionInfo *) NULL);
1542 write_info=CloneImageInfo(image_info);
1543 *write_info->magick=
'\0';
1544 images=GetFirstImageInList(images);
1545 if (images == (Image *) NULL)
1546 return(MagickFalse);
1547 if (filename != (
const char *) NULL)
1548 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1549 (
void) CopyMagickString(p->filename,filename,MagickPathExtent);
1550 (void) CopyMagickString(write_info->filename,images->filename,
1552 sans_exception=AcquireExceptionInfo();
1553 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1555 sans_exception=DestroyExceptionInfo(sans_exception);
1556 if (*write_info->magick ==
'\0')
1557 (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1559 for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1561 if (p->scene >= GetNextImageInList(p)->scene)
1569 i=(ssize_t) images->scene;
1570 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1571 p->scene=(
size_t) i++;
1579 progress_monitor=(MagickProgressMonitor) NULL;
1581 number_images=GetImageListLength(images);
1582 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1584 if (number_images != 1)
1585 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1587 status&=(MagickStatusType) WriteImage(write_info,p,exception);
1588 if (number_images != 1)
1589 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1590 if (write_info->adjoin != MagickFalse)
1592 if (number_images != 1)
1594#if defined(MAGICKCORE_OPENMP_SUPPORT)
1598 proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1599 if (proceed == MagickFalse)
1603 write_info=DestroyImageInfo(write_info);
1604 return(status != 0 ? MagickTrue : MagickFalse);