42#include "magick/studio.h"
43#include "magick/attribute.h"
44#include "magick/blob.h"
45#include "magick/blob-private.h"
46#include "magick/exception.h"
47#include "magick/exception-private.h"
48#include "magick/cache.h"
49#include "magick/cache-private.h"
50#include "magick/client.h"
51#include "magick/coder.h"
52#include "magick/colorspace-private.h"
53#include "magick/constitute.h"
54#include "magick/delegate.h"
55#include "magick/geometry.h"
56#include "magick/identify.h"
57#include "magick/image-private.h"
58#include "magick/list.h"
59#include "magick/magick.h"
60#include "magick/memory_.h"
61#include "magick/monitor.h"
62#include "magick/monitor-private.h"
63#include "magick/option.h"
64#include "magick/pixel.h"
65#include "magick/policy.h"
66#include "magick/profile.h"
67#include "magick/property.h"
68#include "magick/quantum.h"
69#include "magick/resize.h"
70#include "magick/resource_.h"
71#include "magick/semaphore.h"
72#include "magick/statistic.h"
73#include "magick/stream.h"
74#include "magick/string_.h"
75#include "magick/string-private.h"
76#include "magick/timer.h"
77#include "magick/token.h"
78#include "magick/transform.h"
79#include "magick/utility.h"
84#define MaxReadRecursionDepth 100
135MagickExport Image *ConstituteImage(
const size_t columns,
136 const size_t rows,
const char *map,
const StorageType storage,
137 const void *pixels,ExceptionInfo *exception)
154 assert(map != (
const char *) NULL);
155 assert(pixels != (
void *) NULL);
156 assert(exception != (ExceptionInfo *) NULL);
157 assert(exception->signature == MagickCoreSignature);
158 if (IsEventLogging() != MagickFalse)
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",map);
160 image=AcquireImage((ImageInfo *) NULL);
161 if (image == (Image *) NULL)
162 return((Image *) NULL);
165 case CharPixel: image->depth=8*
sizeof(
unsigned char);
break;
166 case DoublePixel: image->depth=8*
sizeof(double);
break;
167 case FloatPixel: image->depth=8*
sizeof(float);
break;
168 case LongPixel: image->depth=8*
sizeof(
unsigned long);
break;
169 case ShortPixel: image->depth=8*
sizeof(
unsigned short);
break;
173 for (i=0; i < (ssize_t) length; i++)
182 image->matte=MagickTrue;
194 image->colorspace=CMYKColorspace;
200 image->colorspace=GRAYColorspace;
206 image->colorspace=GRAYColorspace;
211 status=SetImageExtent(image,columns,rows);
212 if (status == MagickFalse)
214 InheritException(exception,&image->exception);
215 image=DestroyImage(image);
217 status=ResetImagePixels(image,exception);
218 if (status == MagickFalse)
220 InheritException(exception,&image->exception);
221 image=DestroyImage(image);
223 status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels);
224 if (status == MagickFalse)
226 InheritException(exception,&image->exception);
227 image=DestroyImage(image);
261#if defined(__cplusplus) || defined(c_plusplus)
265static size_t PingStream(
const Image *magick_unused(image),
266 const void *magick_unused(pixels),
const size_t columns)
268 magick_unreferenced(image);
269 magick_unreferenced(pixels);
274#if defined(__cplusplus) || defined(c_plusplus)
278MagickExport Image *PingImage(
const ImageInfo *image_info,
279 ExceptionInfo *exception)
287 assert(image_info != (ImageInfo *) NULL);
288 assert(image_info->signature == MagickCoreSignature);
289 assert(exception != (ExceptionInfo *) NULL);
290 if (IsEventLogging() != MagickFalse)
291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
292 image_info->filename);
293 ping_info=CloneImageInfo(image_info);
294 ping_info->ping=MagickTrue;
295 image=ReadStream(ping_info,&PingStream,exception);
296 if (image != (Image *) NULL)
298 if ((image->columns == 0) || (image->rows == 0))
299 ThrowReaderException(CorruptImageError,
"ImproperImageHeader");
300 ResetTimer(&image->timer);
301 if (ping_info->verbose != MagickFalse)
302 (void) IdentifyImage(image,stdout,MagickFalse);
304 ping_info=DestroyImageInfo(ping_info);
332MagickExport Image *PingImages(
const ImageInfo *image_info,
333 ExceptionInfo *exception)
336 filename[MaxTextExtent];
348 assert(image_info != (ImageInfo *) NULL);
349 assert(image_info->signature == MagickCoreSignature);
350 assert(exception != (ExceptionInfo *) NULL);
351 if (IsEventLogging() != MagickFalse)
352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
353 image_info->filename);
354 (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
355 (
int) image_info->scene,filename);
356 if (LocaleCompare(filename,image_info->filename) != 0)
368 read_info=CloneImageInfo(image_info);
369 sans=AcquireExceptionInfo();
370 (void) SetImageInfo(read_info,0,sans);
371 sans=DestroyExceptionInfo(sans);
372 if (read_info->number_scenes == 0)
374 read_info=DestroyImageInfo(read_info);
375 return(PingImage(image_info,exception));
377 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
378 images=NewImageList();
379 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
380 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
382 (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(
int)
383 scene,read_info->filename);
384 image=PingImage(read_info,exception);
385 if (image == (Image *) NULL)
387 AppendImageToList(&images,image);
389 read_info=DestroyImageInfo(read_info);
392 return(PingImage(image_info,exception));
424static MagickBooleanType IsCoderAuthorized(
const char *module,
425 const char *coder,
const PolicyRights rights,ExceptionInfo *exception)
427 if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
428 ThrowPolicyException(coder,MagickFalse);
429 if (IsRightsAuthorized(ModulePolicyDomain,rights,module) == MagickFalse)
430 ThrowPolicyException(module,MagickFalse);
434MagickExport Image *ReadImage(
const ImageInfo *image_info,
435 ExceptionInfo *exception)
438 filename[MaxTextExtent],
439 magick[MaxTextExtent],
440 magick_filename[MaxTextExtent];
474 assert(image_info != (ImageInfo *) NULL);
475 assert(image_info->signature == MagickCoreSignature);
476 assert(image_info->filename != (
char *) NULL);
477 assert(exception != (ExceptionInfo *) NULL);
478 if (IsEventLogging() != MagickFalse)
479 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
480 image_info->filename);
481 read_info=CloneImageInfo(image_info);
482 (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
483 (void) SetImageInfo(read_info,0,exception);
484 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
485 (void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
489 sans_exception=AcquireExceptionInfo();
490 magick_info=GetMagickInfo(read_info->magick,sans_exception);
491 if (sans_exception->severity == PolicyError)
492 magick_info=GetMagickInfo(read_info->magick,exception);
493 sans_exception=DestroyExceptionInfo(sans_exception);
494 if ((magick_info != (
const MagickInfo *) NULL) &&
495 (GetMagickRawSupport(magick_info) != MagickFalse))
497 if (GetMagickEndianSupport(magick_info) == MagickFalse)
498 read_info->endian=UndefinedEndian;
500 if (image_info->endian == UndefinedEndian)
506 read_info->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian :
510 if ((magick_info != (
const MagickInfo *) NULL) &&
511 (GetMagickSeekableStream(magick_info) != MagickFalse))
516 image=AcquireImage(read_info);
517 (void) CopyMagickString(image->filename,read_info->filename,
519 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
520 if (status == MagickFalse)
522 read_info=DestroyImageInfo(read_info);
523 image=DestroyImage(image);
524 return((Image *) NULL);
526 if (IsBlobSeekable(image) == MagickFalse)
531 *read_info->filename=
'\0';
532 status=ImageToFile(image,read_info->filename,exception);
533 if (status == MagickFalse)
535 (void) CloseBlob(image);
536 read_info=DestroyImageInfo(read_info);
537 image=DestroyImage(image);
538 return((Image *) NULL);
540 read_info->temporary=MagickTrue;
542 (void) CloseBlob(image);
543 image=DestroyImage(image);
545 image=NewImageList();
546 if ((magick_info == (
const MagickInfo *) NULL) ||
547 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
549 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
550 if (delegate_info == (
const DelegateInfo *) NULL)
552 (void) SetImageInfo(read_info,0,exception);
553 (void) CopyMagickString(read_info->filename,filename,MaxTextExtent);
554 magick_info=GetMagickInfo(read_info->magick,exception);
557 if ((magick_info != (
const MagickInfo *) NULL) &&
558 (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL))
563 thread_support=GetMagickThreadSupport(magick_info);
564 if ((thread_support & DecoderThreadSupport) == 0)
565 LockSemaphoreInfo(magick_info->semaphore);
566 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
567 ReadPolicyRights,exception);
568 image=(Image *) NULL;
569 if (status != MagickFalse)
570 image=GetImageDecoder(magick_info)(read_info,exception);
571 if ((thread_support & DecoderThreadSupport) == 0)
572 UnlockSemaphoreInfo(magick_info->semaphore);
579 delegate_info=GetDelegateInfo(read_info->magick,(
char *) NULL,exception);
580 if (delegate_info == (
const DelegateInfo *) NULL)
582 (void) ThrowMagickException(exception,GetMagickModule(),
583 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
584 read_info->filename);
585 if (read_info->temporary != MagickFalse)
586 (void) RelinquishUniqueFileResource(read_info->filename);
587 read_info=DestroyImageInfo(read_info);
588 return((Image *) NULL);
593 image=AcquireImage(read_info);
594 if (image == (Image *) NULL)
596 read_info=DestroyImageInfo(read_info);
597 return((Image *) NULL);
599 (void) CopyMagickString(image->filename,read_info->filename,
601 *read_info->filename=
'\0';
602 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
603 LockSemaphoreInfo(delegate_info->semaphore);
604 status=InvokeDelegate(read_info,image,read_info->magick,(
char *) NULL,
606 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
607 UnlockSemaphoreInfo(delegate_info->semaphore);
608 image=DestroyImageList(image);
609 read_info->temporary=MagickTrue;
610 if (status != MagickFalse)
611 (void) SetImageInfo(read_info,0,exception);
612 magick_info=GetMagickInfo(read_info->magick,exception);
613 if ((magick_info == (
const MagickInfo *) NULL) ||
614 (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
616 if (IsPathAccessible(read_info->filename) != MagickFalse)
617 (void) ThrowMagickException(exception,GetMagickModule(),
618 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
621 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
622 read_info->filename);
623 read_info=DestroyImageInfo(read_info);
624 return((Image *) NULL);
629 thread_support=GetMagickThreadSupport(magick_info);
630 if ((thread_support & DecoderThreadSupport) == 0)
631 LockSemaphoreInfo(magick_info->semaphore);
632 status=IsCoderAuthorized(magick_info->magick_module,read_info->magick,
633 ReadPolicyRights,exception);
634 image=(Image *) NULL;
635 if (status != MagickFalse)
636 image=(Image *) (GetImageDecoder(magick_info))(read_info,exception);
637 if ((thread_support & DecoderThreadSupport) == 0)
638 UnlockSemaphoreInfo(magick_info->semaphore);
640 if (read_info->temporary != MagickFalse)
642 (void) RelinquishUniqueFileResource(read_info->filename);
643 read_info->temporary=MagickFalse;
644 if (image != (Image *) NULL)
645 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
647 if (image == (Image *) NULL)
649 read_info=DestroyImageInfo(read_info);
652 if (exception->severity >= ErrorException)
653 (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
654 "Coder (%s) generated an image despite an error (%d), "
655 "notify the developers",image->magick,exception->severity);
656 if (IsBlobTemporary(image) != MagickFalse)
657 (void) RelinquishUniqueFileResource(read_info->filename);
658 if (read_info->ping != MagickFalse)
660 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
662 if ((image->columns == 0) || (image->rows == 0))
664 read_info=DestroyImageInfo(read_info);
665 ThrowReaderException(ImageError,
"NegativeOrZeroImageSize");
669 if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
670 (GetImageListLength(image) != 1))
675 clones=CloneImages(image,read_info->scenes,exception);
676 image=DestroyImageList(image);
677 if (clones != (Image *) NULL)
678 image=GetFirstImageInList(clones);
679 if (image == (Image *) NULL)
681 read_info=DestroyImageInfo(read_info);
685 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
688 magick_path[MaxTextExtent],
690 timestamp[MaxTextExtent];
702 *source_date_epoch = (
const char *) NULL;
704 static MagickBooleanType
705 epoch_initialized = MagickFalse;
707 next->taint=MagickFalse;
708 GetPathComponent(magick_filename,MagickPath,magick_path);
709 if ((*magick_path ==
'\0') && (*next->magick ==
'\0'))
710 (void) CopyMagickString(next->magick,magick,MaxTextExtent);
711 (void) CopyMagickString(next->magick_filename,magick_filename,
713 if (IsBlobTemporary(image) != MagickFalse)
714 (void) CopyMagickString(next->filename,filename,MaxTextExtent);
715 if (next->magick_columns == 0)
716 next->magick_columns=next->columns;
717 if (next->magick_rows == 0)
718 next->magick_rows=next->rows;
719 (void) GetImageProperty(next,
"exif:*");
720 (void) GetImageProperty(next,
"icc:*");
721 (void) GetImageProperty(next,
"iptc:*");
722 (void) GetImageProperty(next,
"xmp:*");
723 value=GetImageProperty(next,
"exif:Orientation");
724 if (value == (
char *) NULL)
725 value=GetImageProperty(next,
"tiff:Orientation");
726 if (value != (
char *) NULL)
728 next->orientation=(OrientationType) StringToLong(value);
729 (void) DeleteImageProperty(next,
"tiff:Orientation");
730 (void) DeleteImageProperty(next,
"exif:Orientation");
732 value=GetImageProperty(next,
"exif:XResolution");
733 if (value != (
char *) NULL)
735 geometry_info.rho=next->x_resolution;
736 geometry_info.sigma=1.0;
737 (void) ParseGeometry(value,&geometry_info);
738 if (geometry_info.sigma != 0)
739 next->x_resolution=geometry_info.rho/geometry_info.sigma;
740 if (strchr(value,
',') != (
char *) NULL)
741 next->x_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
742 (void) DeleteImageProperty(next,
"exif:XResolution");
744 value=GetImageProperty(next,
"exif:YResolution");
745 if (value != (
char *) NULL)
747 geometry_info.rho=next->y_resolution;
748 geometry_info.sigma=1.0;
749 (void) ParseGeometry(value,&geometry_info);
750 if (geometry_info.sigma != 0)
751 next->y_resolution=geometry_info.rho/geometry_info.sigma;
752 if (strchr(value,
',') != (
char *) NULL)
753 next->y_resolution=geometry_info.rho+geometry_info.sigma/1000.0;
754 (void) DeleteImageProperty(next,
"exif:YResolution");
756 value=GetImageProperty(next,
"exif:ResolutionUnit");
757 if (value == (
char *) NULL)
758 value=GetImageProperty(next,
"tiff:ResolutionUnit");
759 if (value != (
char *) NULL)
761 option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
763 if (option_type >= 0)
764 next->units=(ResolutionType) option_type;
765 (void) DeleteImageProperty(next,
"exif:ResolutionUnit");
766 (void) DeleteImageProperty(next,
"tiff:ResolutionUnit");
768 if (next->page.width == 0)
769 next->page.width=next->columns;
770 if (next->page.height == 0)
771 next->page.height=next->rows;
772 option=GetImageOption(read_info,
"caption");
773 if (option != (
const char *) NULL)
775 property=InterpretImageProperties(read_info,next,option);
776 (void) SetImageProperty(next,
"caption",property);
777 property=DestroyString(property);
779 option=GetImageOption(read_info,
"comment");
780 if (option != (
const char *) NULL)
782 property=InterpretImageProperties(read_info,next,option);
783 (void) SetImageProperty(next,
"comment",property);
784 property=DestroyString(property);
786 option=GetImageOption(read_info,
"label");
787 if (option != (
const char *) NULL)
789 property=InterpretImageProperties(read_info,next,option);
790 (void) SetImageProperty(next,
"label",property);
791 property=DestroyString(property);
793 if (LocaleCompare(next->magick,
"TEXT") == 0)
794 (void) ParseAbsoluteGeometry(
"0x0+0+0",&next->page);
795 if ((read_info->extract != (
char *) NULL) &&
796 (read_info->stream == (StreamHandler) NULL))
801 SetGeometry(next,&geometry);
802 flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
803 if ((next->columns != geometry.width) ||
804 (next->rows != geometry.height))
806 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
811 crop_image=CropImage(next,&geometry,exception);
812 if (crop_image != (Image *) NULL)
813 ReplaceImageInList(&next,crop_image);
816 if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
818 (void) ParseRegionGeometry(next,read_info->extract,&geometry,
820 if ((geometry.width != 0) && (geometry.height != 0))
822 Image *resize_image=ResizeImage(next,geometry.width,
823 geometry.height,next->filter,next->blur,exception);
824 if (resize_image != (Image *) NULL)
825 ReplaceImageInList(&next,resize_image);
830 profile=GetImageProfile(next,
"icc");
831 if (profile == (
const StringInfo *) NULL)
832 profile=GetImageProfile(next,
"icm");
833 if (profile != (
const StringInfo *) NULL)
835 next->color_profile.length=GetStringInfoLength(profile);
836 next->color_profile.info=GetStringInfoDatum(profile);
838 profile=GetImageProfile(next,
"iptc");
839 if (profile == (
const StringInfo *) NULL)
840 profile=GetImageProfile(next,
"8bim");
841 if (profile != (
const StringInfo *) NULL)
843 next->iptc_profile.length=GetStringInfoLength(profile);
844 next->iptc_profile.info=GetStringInfoDatum(profile);
846 if (epoch_initialized == MagickFalse)
848 source_date_epoch=getenv(
"SOURCE_DATE_EPOCH");
849 epoch_initialized=MagickTrue;
851 if (source_date_epoch == (
const char *) NULL)
853 (void) FormatMagickTime(image->timestamp,MaxTextExtent,timestamp);
854 (void) SetImageProperty(next,
"date:timestamp",timestamp);
855 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
856 MaxTextExtent,timestamp);
857 (void) SetImageProperty(next,
"date:modify",timestamp);
858 (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
859 MaxTextExtent,timestamp);
860 (void) SetImageProperty(next,
"date:create",timestamp);
862 option=GetImageOption(image_info,
"delay");
863 if (option != (
const char *) NULL)
868 flags=ParseGeometry(option,&geometry_info);
869 if ((flags & GreaterValue) != 0)
871 if (next->delay > (
size_t) floor(geometry_info.rho+0.5))
872 next->delay=(size_t) floor(geometry_info.rho+0.5);
875 if ((flags & LessValue) != 0)
877 if (next->delay < (
size_t) floor(geometry_info.rho+0.5))
878 next->delay=(size_t) floor(geometry_info.rho+0.5);
881 next->delay=(size_t) floor(geometry_info.rho+0.5);
882 if ((flags & SigmaValue) != 0)
883 next->ticks_per_second=CastDoubleToLong(floor(
884 geometry_info.sigma+0.5));
886 option=GetImageOption(image_info,
"dispose");
887 if (option != (
const char *) NULL)
889 option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
891 if (option_type >= 0)
892 next->dispose=(DisposeType) option_type;
894 if (read_info->verbose != MagickFalse)
895 (void) IdentifyImage(next,stderr,MagickFalse);
898 read_info=DestroyImageInfo(read_info);
899 if (GetBlobError(image) != MagickFalse)
900 ThrowReaderException(CorruptImageError,
"UnableToReadImageData");
901 return(GetFirstImageInList(image));
928MagickExport Image *ReadImages(
const ImageInfo *image_info,
929 ExceptionInfo *exception)
932 filename[MaxTextExtent];
944 assert(image_info != (ImageInfo *) NULL);
945 assert(image_info->signature == MagickCoreSignature);
946 assert(exception != (ExceptionInfo *) NULL);
947 if (IsEventLogging() != MagickFalse)
948 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
949 image_info->filename);
950 read_info=CloneImageInfo(image_info);
951 *read_info->magick=
'\0';
952 (void) InterpretImageFilename(read_info,(Image *) NULL,read_info->filename,
953 (
int) read_info->scene,filename);
954 if (LocaleCompare(filename,read_info->filename) != 0)
966 sans=AcquireExceptionInfo();
967 (void) SetImageInfo(read_info,0,sans);
968 sans=DestroyExceptionInfo(sans);
969 if (read_info->number_scenes == 0)
971 read_info=DestroyImageInfo(read_info);
972 return(ReadImage(image_info,exception));
974 (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
975 images=NewImageList();
976 extent=(ssize_t) (read_info->scene+read_info->number_scenes);
977 for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
979 (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(
int)
980 scene,read_info->filename);
981 image=ReadImage(read_info,exception);
982 if (image == (Image *) NULL)
984 AppendImageToList(&images,image);
986 read_info=DestroyImageInfo(read_info);
989 image=ReadImage(read_info,exception);
990 read_info=DestroyImageInfo(read_info);
1024MagickExport Image *ReadInlineImage(
const ImageInfo *image_info,
1025 const char *content,ExceptionInfo *exception)
1045 image=NewImageList();
1046 for (p=content; (*p !=
',') && (*p !=
'\0'); p++) ;
1048 ThrowReaderException(CorruptImageError,
"CorruptImage");
1049 blob=Base64Decode(++p,&length);
1052 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1053 ThrowReaderException(CorruptImageError,
"CorruptImage");
1055 read_info=CloneImageInfo(image_info);
1056 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1058 *read_info->filename=
'\0';
1059 *read_info->magick=
'\0';
1060 for (p=content; (*p !=
'/') && (*p !=
'\0'); p++) ;
1072 if (LocaleNCompare(++p,
"x-",2) == 0)
1074 (void) CopyMagickString(read_info->filename,
"data.",MagickPathExtent);
1075 q=read_info->filename+5;
1076 for (i=0; (*p !=
';') && (*p !=
'\0') && (i < (MagickPathExtent-6)); i++)
1080 image=BlobToImage(read_info,blob,length,exception);
1081 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1082 read_info=DestroyImageInfo(read_info);
1114MagickExport MagickBooleanType WriteImage(
const ImageInfo *image_info,
1118 filename[MaxTextExtent];
1146 assert(image_info != (ImageInfo *) NULL);
1147 assert(image_info->signature == MagickCoreSignature);
1148 assert(image != (Image *) NULL);
1149 assert(image->signature == MagickCoreSignature);
1150 if (IsEventLogging() != MagickFalse)
1151 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1152 image_info->filename);
1153 exception=(&image->exception);
1154 sans_exception=AcquireExceptionInfo();
1155 write_info=CloneImageInfo(image_info);
1156 (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
1157 (void) SetImageInfo(write_info,1,sans_exception);
1158 if (*write_info->magick ==
'\0')
1159 (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
1160 if (LocaleCompare(write_info->magick,
"clipmask") == 0)
1162 if (image->clip_mask == (Image *) NULL)
1164 (void) ThrowMagickException(exception,GetMagickModule(),
1165 OptionError,
"NoClipPathDefined",
"`%s'",image->filename);
1166 write_info=DestroyImageInfo(write_info);
1167 return(MagickFalse);
1169 image=image->clip_mask;
1170 (void) SetImageInfo(write_info,1,sans_exception);
1172 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1173 (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
1177 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1178 if (sans_exception->severity == PolicyError)
1179 magick_info=GetMagickInfo(write_info->magick,exception);
1180 sans_exception=DestroyExceptionInfo(sans_exception);
1181 if (magick_info != (
const MagickInfo *) NULL)
1183 if (GetMagickEndianSupport(magick_info) == MagickFalse)
1184 image->endian=UndefinedEndian;
1186 if ((image_info->endian == UndefinedEndian) &&
1187 (GetMagickRawSupport(magick_info) != MagickFalse))
1193 image->endian=(*(
char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1196 if ((image->ping != MagickFalse) &&
1197 (SyncImagePixelCache(image,exception) == MagickFalse))
1198 return(MagickFalse);
1199 if (SyncImageProfiles(image) == MagickFalse)
1200 return(MagickFalse);
1201 DisassociateImageStream(image);
1202 option=GetImageOption(image_info,
"delegate:bimodal");
1203 if ((option != (
const char *) NULL) &&
1204 (IsMagickTrue(option) != MagickFalse) &&
1205 (write_info->page == (
char *) NULL) &&
1206 (GetPreviousImageInList(image) == (Image *) NULL) &&
1207 (GetNextImageInList(image) == (Image *) NULL) &&
1208 (IsTaintImage(image) == MagickFalse))
1210 delegate_info=GetDelegateInfo(image->magick,write_info->magick,
1212 if ((delegate_info != (
const DelegateInfo *) NULL) &&
1213 (GetDelegateMode(delegate_info) == 0) &&
1214 (IsPathAccessible(image->magick_filename) != MagickFalse))
1219 (void) CopyMagickString(image->filename,image->magick_filename,
1221 status=InvokeDelegate(write_info,image,image->magick,
1222 write_info->magick,exception);
1223 write_info=DestroyImageInfo(write_info);
1224 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1229 temporary=MagickFalse;
1230 if ((magick_info != (
const MagickInfo *) NULL) &&
1231 (GetMagickSeekableStream(magick_info) != MagickFalse))
1234 filename[MaxTextExtent];
1236 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1237 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1238 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1239 if (status != MagickFalse)
1241 if (IsBlobSeekable(image) == MagickFalse)
1246 write_info->adjoin=MagickTrue;
1247 (void) CopyMagickString(write_info->filename,image->filename,
1249 (void) AcquireUniqueFilename(image->filename);
1250 temporary=MagickTrue;
1252 if (CloseBlob(image) == MagickFalse)
1256 if ((magick_info != (
const MagickInfo *) NULL) &&
1257 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1262 thread_support=GetMagickThreadSupport(magick_info);
1263 if ((thread_support & EncoderThreadSupport) == 0)
1264 LockSemaphoreInfo(magick_info->semaphore);
1265 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1266 WritePolicyRights,exception);
1267 if (status != MagickFalse)
1268 status=GetImageEncoder(magick_info)(write_info,image);
1269 if ((thread_support & EncoderThreadSupport) == 0)
1270 UnlockSemaphoreInfo(magick_info->semaphore);
1274 delegate_info=GetDelegateInfo((
char *) NULL,write_info->magick,
1276 if (delegate_info != (DelegateInfo *) NULL)
1281 *write_info->filename=
'\0';
1282 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1283 LockSemaphoreInfo(delegate_info->semaphore);
1284 status=InvokeDelegate(write_info,image,(
char *) NULL,
1285 write_info->magick,exception);
1286 if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1287 UnlockSemaphoreInfo(delegate_info->semaphore);
1288 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1292 sans_exception=AcquireExceptionInfo();
1293 magick_info=GetMagickInfo(write_info->magick,sans_exception);
1294 if (sans_exception->severity == PolicyError)
1295 magick_info=GetMagickInfo(write_info->magick,exception);
1296 sans_exception=DestroyExceptionInfo(sans_exception);
1297 if ((write_info->affirm == MagickFalse) &&
1298 (magick_info == (
const MagickInfo *) NULL))
1300 (void) CopyMagickString(write_info->magick,image->magick,
1302 magick_info=GetMagickInfo(write_info->magick,exception);
1304 if ((magick_info == (
const MagickInfo *) NULL) ||
1305 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1308 extension[MaxTextExtent];
1310 GetPathComponent(image->filename,ExtensionPath,extension);
1311 if (*extension !=
'\0')
1312 magick_info=GetMagickInfo(extension,exception);
1314 magick_info=GetMagickInfo(image->magick,exception);
1315 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1317 if ((magick_info == (
const MagickInfo *) NULL) ||
1318 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1320 magick_info=GetMagickInfo(image->magick,exception);
1321 if ((magick_info == (
const MagickInfo *) NULL) ||
1322 (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1323 (void) ThrowMagickException(exception,GetMagickModule(),
1324 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
1325 "`%s'",write_info->magick);
1327 (
void) ThrowMagickException(exception,GetMagickModule(),
1328 MissingDelegateWarning,
"NoEncodeDelegateForThisImageFormat",
1329 "`%s'",write_info->magick);
1331 if ((magick_info != (
const MagickInfo *) NULL) &&
1332 (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1337 thread_support=GetMagickThreadSupport(magick_info);
1338 if ((thread_support & EncoderThreadSupport) == 0)
1339 LockSemaphoreInfo(magick_info->semaphore);
1340 status=IsCoderAuthorized(magick_info->magick_module,write_info->magick,
1341 WritePolicyRights,exception);
1342 if (status != MagickFalse)
1343 status=GetImageEncoder(magick_info)(write_info,image);
1344 if ((thread_support & EncoderThreadSupport) == 0)
1345 UnlockSemaphoreInfo(magick_info->semaphore);
1349 if (temporary != MagickFalse)
1354 status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1355 if (status != MagickFalse)
1357 (void) RelinquishUniqueFileResource(write_info->filename);
1358 status=ImageToFile(image,write_info->filename,exception);
1360 if (CloseBlob(image) == MagickFalse)
1362 (void) RelinquishUniqueFileResource(image->filename);
1363 (void) CopyMagickString(image->filename,write_info->filename,
1366 if ((LocaleCompare(write_info->magick,
"info") != 0) &&
1367 (write_info->verbose != MagickFalse))
1368 (void) IdentifyImage(image,stderr,MagickFalse);
1369 write_info=DestroyImageInfo(write_info);
1370 if (GetBlobError(image) != MagickFalse)
1371 ThrowWriterException(FileOpenError,
"UnableToWriteFile");
1411MagickExport MagickBooleanType WriteImages(
const ImageInfo *image_info,
1412 Image *images,
const char *filename,ExceptionInfo *exception)
1414#define WriteImageTag "Write/Image"
1428 MagickProgressMonitor
1440 assert(image_info != (
const ImageInfo *) NULL);
1441 assert(image_info->signature == MagickCoreSignature);
1442 assert(images != (Image *) NULL);
1443 assert(images->signature == MagickCoreSignature);
1444 assert(exception != (ExceptionInfo *) NULL);
1445 if (IsEventLogging() != MagickFalse)
1446 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1447 write_info=CloneImageInfo(image_info);
1448 *write_info->magick=
'\0';
1449 images=GetFirstImageInList(images);
1450 if (images == (Image *) NULL)
1451 return(MagickFalse);
1452 if (filename != (
const char *) NULL)
1453 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1454 (
void) CopyMagickString(p->filename,filename,MaxTextExtent);
1455 (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
1456 sans_exception=AcquireExceptionInfo();
1457 (void) SetImageInfo(write_info,(
unsigned int) GetImageListLength(images),
1459 sans_exception=DestroyExceptionInfo(sans_exception);
1460 if (*write_info->magick ==
'\0')
1461 (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
1463 for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1465 if (p->scene >= GetNextImageInList(p)->scene)
1473 i=(ssize_t) images->scene;
1474 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1475 p->scene=(
size_t) i++;
1483 progress_monitor=(MagickProgressMonitor) NULL;
1485 number_images=GetImageListLength(images);
1486 for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1488 if (number_images != 1)
1489 progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1491 status&=WriteImage(write_info,p);
1492 GetImageException(p,exception);
1493 if (number_images != 1)
1494 (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1495 if (write_info->adjoin != MagickFalse)
1497 if (number_images != 1)
1499 proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
1500 if (proceed == MagickFalse)
1504 write_info=DestroyImageInfo(write_info);
1505 return(status != 0 ? MagickTrue : MagickFalse);