47#include "MagickCore/studio.h"
48#include "MagickCore/blob.h"
49#include "MagickCore/blob-private.h"
50#include "MagickCore/cache.h"
51#include "MagickCore/client.h"
52#include "MagickCore/constitute.h"
53#include "MagickCore/delegate.h"
54#include "MagickCore/exception.h"
55#include "MagickCore/exception-private.h"
56#include "MagickCore/geometry.h"
57#include "MagickCore/image-private.h"
58#include "MagickCore/list.h"
59#include "MagickCore/locale_.h"
60#include "MagickCore/log.h"
61#include "MagickCore/magick.h"
62#include "MagickCore/memory_.h"
63#include "MagickCore/memory-private.h"
64#include "MagickCore/nt-base-private.h"
65#include "MagickCore/option.h"
66#include "MagickCore/policy.h"
67#include "MagickCore/resource_.h"
68#include "MagickCore/semaphore.h"
69#include "MagickCore/string_.h"
70#include "MagickCore/string-private.h"
71#include "MagickCore/timer-private.h"
72#include "MagickCore/token.h"
73#include "MagickCore/utility.h"
74#include "MagickCore/utility-private.h"
75#if defined(MAGICKCORE_ZLIB_DELEGATE)
78#if defined(MAGICKCORE_BZLIB_DELEGATE)
85#define MagickMaxBlobExtent (8*8192)
86#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
87# define MAP_ANONYMOUS MAP_ANON
89#if !defined(MAP_FAILED)
90#define MAP_FAILED ((void *) -1)
94#define _O_BINARY O_BINARY
96#if defined(MAGICKCORE_WINDOWS_SUPPORT)
101# define MAGICKCORE_HAVE_MMAP 1
102# define mmap(address,length,protection,access,file,offset) \
103 NTMapMemory(address,length,protection,access,file,offset)
106# define munmap(address,length) NTUnmapMemory(address,length)
109# define pclose _pclose
124#if defined(MAGICKCORE_ZLIB_DELEGATE)
129#if defined(MAGICKCORE_BZLIB_DELEGATE)
221 SyncBlob(
const Image *);
251 magick_unreferenced(exception);
253 sizeof(*custom_stream));
254 (void) memset(custom_stream,0,
sizeof(*custom_stream));
255 custom_stream->signature=MagickCoreSignature;
256 return(custom_stream);
286MagickExport
void AttachBlob(
BlobInfo *blob_info,
const void *blob,
289 assert(blob_info != (
BlobInfo *) NULL);
290 if (IsEventLogging() != MagickFalse)
291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
292 blob_info->length=length;
293 blob_info->extent=length;
294 blob_info->quantum=(size_t) MagickMaxBlobExtent;
296 blob_info->type=BlobStream;
297 blob_info->file_info.file=(FILE *) NULL;
298 blob_info->data=(
unsigned char *) blob;
299 blob_info->mapped=MagickFalse;
327MagickExport
void AttachCustomStream(
BlobInfo *blob_info,
330 assert(blob_info != (
BlobInfo *) NULL);
332 assert(custom_stream->signature == MagickCoreSignature);
333 if (IsEventLogging() != MagickFalse)
334 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
335 blob_info->type=CustomStream;
336 blob_info->custom_stream=custom_stream;
369MagickExport MagickBooleanType BlobToFile(
char *filename,
const void *blob,
381 assert(filename != (
const char *) NULL);
382 assert(blob != (
const void *) NULL);
383 if (IsEventLogging() != MagickFalse)
384 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
385 if (*filename ==
'\0')
386 file=AcquireUniqueFileResource(filename);
388 file=open_utf8(filename,O_RDWR | O_CREAT | O_EXCL | O_BINARY,S_MODE);
391 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",filename);
394 for (i=0; i < length; i+=(size_t) count)
396 count=write(file,(
const char *) blob+i,MagickMin(length-i,(
size_t)
397 MagickMaxBufferExtent));
406 if ((file == -1) || (i < length))
408 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",filename);
445MagickExport
Image *BlobToImage(
const ImageInfo *image_info,
const void *blob,
461 assert(image_info != (
ImageInfo *) NULL);
462 assert(image_info->signature == MagickCoreSignature);
464 if (IsEventLogging() != MagickFalse)
465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
466 image_info->filename);
467 if ((blob == (
const void *) NULL) || (length == 0))
469 (void) ThrowMagickException(exception,GetMagickModule(),BlobError,
470 "ZeroLengthBlobNotPermitted",
"`%s'",image_info->filename);
471 return((
Image *) NULL);
473 blob_info=CloneImageInfo(image_info);
474 blob_info->blob=(
void *) blob;
475 blob_info->length=length;
476 if (*blob_info->magick ==
'\0')
477 (void) SetImageInfo(blob_info,0,exception);
478 magick_info=GetMagickInfo(blob_info->magick,exception);
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
484 blob_info=DestroyImageInfo(blob_info);
485 return((
Image *) NULL);
487 if (GetMagickBlobSupport(magick_info) != MagickFalse)
490 filename[MagickPathExtent];
495 (void) CopyMagickString(filename,blob_info->filename,MagickPathExtent);
496 (void) FormatLocaleString(blob_info->filename,MagickPathExtent,
"%s:%s",
497 blob_info->magick,filename);
498 image=ReadImage(blob_info,exception);
499 if (image != (
Image *) NULL)
500 (void) DetachBlob(image->blob);
501 blob_info=DestroyImageInfo(blob_info);
507 blob_info->blob=(
void *) NULL;
509 *blob_info->filename=
'\0';
510 status=BlobToFile(blob_info->filename,blob,length,exception);
511 if (status == MagickFalse)
513 (void) RelinquishUniqueFileResource(blob_info->filename);
514 blob_info=DestroyImageInfo(blob_info);
515 return((
Image *) NULL);
517 clone_info=CloneImageInfo(blob_info);
518 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
"%s:%s",
519 blob_info->magick,blob_info->filename);
520 image=ReadImage(clone_info,exception);
521 if (image != (
Image *) NULL)
529 for (images=GetFirstImageInList(image); images != (
Image *) NULL; )
531 (void) CopyMagickString(images->filename,image_info->filename,
533 (void) CopyMagickString(images->magick_filename,image_info->filename,
535 (void) CopyMagickString(images->magick,magick_info->name,
537 images=GetNextImageInList(images);
540 clone_info=DestroyImageInfo(clone_info);
541 (void) RelinquishUniqueFileResource(blob_info->filename);
542 blob_info=DestroyImageInfo(blob_info);
577 clone_info=(
BlobInfo *) AcquireCriticalMemory(
sizeof(*clone_info));
578 GetBlobInfo(clone_info);
581 semaphore=clone_info->semaphore;
582 (void) memcpy(clone_info,blob_info,
sizeof(*clone_info));
583 if (blob_info->mapped != MagickFalse)
584 (void) AcquireMagickResource(MapResource,blob_info->length);
585 clone_info->semaphore=semaphore;
586 LockSemaphoreInfo(clone_info->semaphore);
587 clone_info->reference_count=1;
588 UnlockSemaphoreInfo(clone_info->semaphore);
615static inline void ThrowBlobException(
BlobInfo *blob_info)
617 if ((blob_info->status == 0) && (errno != 0))
618 blob_info->error_number=errno;
619 blob_info->status=(-1);
622MagickExport MagickBooleanType CloseBlob(
Image *image)
625 *magick_restrict blob_info;
633 assert(image != (
Image *) NULL);
634 assert(image->signature == MagickCoreSignature);
635 if (IsEventLogging() != MagickFalse)
636 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
637 blob_info=image->blob;
638 if ((blob_info == (
BlobInfo *) NULL) || (blob_info->type == UndefinedStream))
640 (void) SyncBlob(image);
641 status=blob_info->status;
642 switch (blob_info->type)
644 case UndefinedStream:
650 if (blob_info->synchronize != MagickFalse)
652 status=fflush(blob_info->file_info.file);
654 ThrowBlobException(blob_info);
655 status=fsync(fileno(blob_info->file_info.file));
657 ThrowBlobException(blob_info);
659 if ((status != 0) && (ferror(blob_info->file_info.file) != 0))
660 ThrowBlobException(blob_info);
665#if defined(MAGICKCORE_ZLIB_DELEGATE)
667 (void) gzerror(blob_info->file_info.gzfile,&status);
669 ThrowBlobException(blob_info);
675#if defined(MAGICKCORE_BZLIB_DELEGATE)
677 (void) BZ2_bzerror(blob_info->file_info.bzfile,&status);
679 ThrowBlobException(blob_info);
687 if (blob_info->file_info.file != (FILE *) NULL)
689 if (blob_info->synchronize != MagickFalse)
691 status=fflush(blob_info->file_info.file);
693 ThrowBlobException(blob_info);
694 status=fsync(fileno(blob_info->file_info.file));
696 ThrowBlobException(blob_info);
698 if ((status != 0) && (ferror(blob_info->file_info.file) != 0))
699 ThrowBlobException(blob_info);
706 blob_info->size=GetBlobSize(image);
707 image->extent=blob_info->size;
708 blob_info->eof=MagickFalse;
710 blob_info->mode=UndefinedBlobMode;
711 if (blob_info->exempt != MagickFalse)
713 blob_info->type=UndefinedStream;
714 return(blob_info->status != 0 ? MagickFalse : MagickTrue);
716 switch (blob_info->type)
718 case UndefinedStream:
723 if (blob_info->file_info.file != (FILE *) NULL)
725 status=fclose(blob_info->file_info.file);
727 ThrowBlobException(blob_info);
733#if defined(MAGICKCORE_HAVE_PCLOSE)
734 status=pclose(blob_info->file_info.file);
736 ThrowBlobException(blob_info);
742#if defined(MAGICKCORE_ZLIB_DELEGATE)
743 status=gzclose(blob_info->file_info.gzfile);
745 ThrowBlobException(blob_info);
751#if defined(MAGICKCORE_BZLIB_DELEGATE)
752 BZ2_bzclose(blob_info->file_info.bzfile);
760 if (blob_info->file_info.file != (FILE *) NULL)
762 status=fclose(blob_info->file_info.file);
764 ThrowBlobException(blob_info);
771 (void) DetachBlob(blob_info);
772 return(blob_info->status != 0 ? MagickFalse : MagickTrue);
801MagickExport
Image *CustomStreamToImage(
const ImageInfo *image_info,
813 assert(image_info != (
ImageInfo *) NULL);
814 assert(image_info->signature == MagickCoreSignature);
816 assert(image_info->custom_stream->signature == MagickCoreSignature);
817 assert(image_info->custom_stream->reader != (CustomStreamHandler) NULL);
819 if (IsEventLogging() != MagickFalse)
820 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
821 image_info->filename);
822 blob_info=CloneImageInfo(image_info);
823 if (*blob_info->magick ==
'\0')
824 (void) SetImageInfo(blob_info,0,exception);
825 magick_info=GetMagickInfo(blob_info->magick,exception);
828 (void) ThrowMagickException(exception,GetMagickModule(),
829 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
831 blob_info=DestroyImageInfo(blob_info);
832 return((
Image *) NULL);
834 image=(
Image *) NULL;
835 if ((GetMagickBlobSupport(magick_info) != MagickFalse) ||
836 (*blob_info->filename !=
'\0'))
839 filename[MagickPathExtent];
845 (void) CopyMagickString(filename,blob_info->filename,MagickPathExtent);
846 (void) FormatLocaleString(blob_info->filename,MagickPathExtent,
"%s:%s",
847 blob_info->magick,filename);
848 image=ReadImage(blob_info,exception);
853 unique[MagickPathExtent];
868 blob=(
unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
870 if (blob == (
unsigned char *) NULL)
872 ThrowFileException(exception,BlobError,
"UnableToReadBlob",
873 image_info->filename);
874 blob_info=DestroyImageInfo(blob_info);
875 return((
Image *) NULL);
877 file=AcquireUniqueFileResource(unique);
880 ThrowFileException(exception,BlobError,
"UnableToReadBlob",
881 image_info->filename);
882 blob=(
unsigned char *) RelinquishMagickMemory(blob);
883 blob_info=DestroyImageInfo(blob_info);
884 return((
Image *) NULL);
886 clone_info=CloneImageInfo(blob_info);
887 blob_info->file=fdopen(file,
"wb+");
888 if (blob_info->file != (FILE *) NULL)
893 count=(ssize_t) MagickMaxBufferExtent;
894 while (count == (ssize_t) MagickMaxBufferExtent)
896 count=image_info->custom_stream->reader(blob,MagickMaxBufferExtent,
897 image_info->custom_stream->data);
898 count=(ssize_t) write(file,(
const char *) blob,(
size_t) count);
900 (void) fclose(blob_info->file);
901 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
902 "%s:%s",blob_info->magick,unique);
903 image=ReadImage(clone_info,exception);
904 if (image != (
Image *) NULL)
912 for (images=GetFirstImageInList(image); images != (
Image *) NULL; )
914 (void) CopyMagickString(images->filename,image_info->filename,
916 (void) CopyMagickString(images->magick_filename,
917 image_info->filename,MagickPathExtent);
918 (void) CopyMagickString(images->magick,magick_info->name,
920 images=GetNextImageInList(images);
924 clone_info=DestroyImageInfo(clone_info);
925 blob=(
unsigned char *) RelinquishMagickMemory(blob);
926 (void) RelinquishUniqueFileResource(unique);
928 blob_info=DestroyImageInfo(blob_info);
929 if (image != (
Image *) NULL)
930 if (CloseBlob(image) == MagickFalse)
931 image=DestroyImageList(image);
957MagickExport
void DestroyBlob(
Image *image)
960 *magick_restrict blob_info;
965 assert(image != (
Image *) NULL);
966 assert(image->signature == MagickCoreSignature);
967 assert(image->blob != (
BlobInfo *) NULL);
968 assert(image->blob->signature == MagickCoreSignature);
969 if (IsEventLogging() != MagickFalse)
970 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
971 blob_info=image->blob;
973 LockSemaphoreInfo(blob_info->semaphore);
974 blob_info->reference_count--;
975 assert(blob_info->reference_count >= 0);
976 if (blob_info->reference_count == 0)
978 UnlockSemaphoreInfo(blob_info->semaphore);
979 if (destroy == MagickFalse)
984 (void) CloseBlob(image);
985 if (blob_info->mapped != MagickFalse)
987 (void) UnmapBlob(blob_info->data,blob_info->length);
988 RelinquishMagickResource(MapResource,blob_info->length);
991 RelinquishSemaphoreInfo(&blob_info->semaphore);
992 blob_info->signature=(~MagickCoreSignature);
993 image->blob=(
BlobInfo *) RelinquishMagickMemory(blob_info);
1023 assert(custom_stream->signature == MagickCoreSignature);
1024 if (IsEventLogging() != MagickFalse)
1025 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1026 custom_stream->signature=(~MagickCoreSignature);
1028 return(custom_stream);
1053MagickExport
void *DetachBlob(
BlobInfo *blob_info)
1058 assert(blob_info != (
BlobInfo *) NULL);
1059 if (IsEventLogging() != MagickFalse)
1060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1061 if (blob_info->mapped != MagickFalse)
1063 (void) UnmapBlob(blob_info->data,blob_info->length);
1064 blob_info->data=NULL;
1065 RelinquishMagickResource(MapResource,blob_info->length);
1067 blob_info->mapped=MagickFalse;
1068 blob_info->length=0;
1073 blob_info->offset=0;
1074 blob_info->mode=UndefinedBlobMode;
1075 blob_info->eof=MagickFalse;
1077 blob_info->exempt=MagickFalse;
1078 blob_info->type=UndefinedStream;
1079 blob_info->file_info.file=(FILE *) NULL;
1080 data=blob_info->data;
1081 blob_info->data=(
unsigned char *) NULL;
1082 blob_info->stream=(StreamHandler) NULL;
1111MagickExport
void DisassociateBlob(
Image *image)
1114 *magick_restrict blob_info,
1120 assert(image != (
Image *) NULL);
1121 assert(image->signature == MagickCoreSignature);
1122 assert(image->blob != (
BlobInfo *) NULL);
1123 assert(image->blob->signature == MagickCoreSignature);
1124 if (IsEventLogging() != MagickFalse)
1125 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1126 blob_info=image->blob;
1128 LockSemaphoreInfo(blob_info->semaphore);
1129 assert(blob_info->reference_count >= 0);
1130 if (blob_info->reference_count > 1)
1132 UnlockSemaphoreInfo(blob_info->semaphore);
1133 if (clone == MagickFalse)
1135 clone_info=CloneBlobInfo(blob_info);
1137 image->blob=clone_info;
1165MagickExport MagickBooleanType DiscardBlobBytes(
Image *image,
1166 const MagickSizeType length)
1178 buffer[MagickMinBufferExtent >> 1];
1180 assert(image != (
Image *) NULL);
1181 assert(image->signature == MagickCoreSignature);
1182 if (length != (MagickSizeType) ((MagickOffsetType) length))
1183 return(MagickFalse);
1185 for (i=0; i < length; i+=(MagickSizeType) count)
1187 quantum=(size_t) MagickMin(length-i,
sizeof(buffer));
1188 (void) ReadBlobStream(image,quantum,buffer,&count);
1196 return(i < (MagickSizeType) length ? MagickFalse : MagickTrue);
1223MagickExport
void DuplicateBlob(
Image *image,
const Image *duplicate)
1225 assert(image != (
Image *) NULL);
1226 assert(image->signature == MagickCoreSignature);
1227 assert(duplicate != (
Image *) NULL);
1228 assert(duplicate->signature == MagickCoreSignature);
1229 if (IsEventLogging() != MagickFalse)
1230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1232 image->blob=ReferenceBlob(duplicate->blob);
1258MagickExport
int EOFBlob(
const Image *image)
1261 *magick_restrict blob_info;
1263 assert(image != (
Image *) NULL);
1264 assert(image->signature == MagickCoreSignature);
1265 assert(image->blob != (
BlobInfo *) NULL);
1266 assert(image->blob->type != UndefinedStream);
1267 if (IsEventLogging() != MagickFalse)
1268 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1269 blob_info=image->blob;
1270 switch (blob_info->type)
1272 case UndefinedStream:
1273 case StandardStream:
1278 blob_info->eof=feof(blob_info->file_info.file) != 0 ? MagickTrue :
1284#if defined(MAGICKCORE_ZLIB_DELEGATE)
1285 blob_info->eof=gzeof(blob_info->file_info.gzfile) != 0 ? MagickTrue :
1292#if defined(MAGICKCORE_BZLIB_DELEGATE)
1297 (void) BZ2_bzerror(blob_info->file_info.bzfile,&status);
1298 blob_info->eof=status == BZ_UNEXPECTED_EOF ? MagickTrue : MagickFalse;
1304 blob_info->eof=MagickFalse;
1312 return((
int) blob_info->eof);
1338MagickExport
int ErrorBlob(
const Image *image)
1341 *magick_restrict blob_info;
1343 assert(image != (
Image *) NULL);
1344 assert(image->signature == MagickCoreSignature);
1345 assert(image->blob != (
BlobInfo *) NULL);
1346 assert(image->blob->type != UndefinedStream);
1347 if (IsEventLogging() != MagickFalse)
1348 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1349 blob_info=image->blob;
1350 switch (blob_info->type)
1352 case UndefinedStream:
1353 case StandardStream:
1358 blob_info->error=ferror(blob_info->file_info.file);
1363#if defined(MAGICKCORE_ZLIB_DELEGATE)
1364 (void) gzerror(blob_info->file_info.gzfile,&blob_info->error);
1370#if defined(MAGICKCORE_BZLIB_DELEGATE)
1371 (void) BZ2_bzerror(blob_info->file_info.bzfile,&blob_info->error);
1385 return(blob_info->error);
1423MagickExport
void *FileToBlob(
const char *filename,
const size_t extent,
1450 assert(filename != (
const char *) NULL);
1452 assert(exception->signature == MagickCoreSignature);
1453 if (IsEventLogging() != MagickFalse)
1454 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
1456 status=IsRightsAuthorized(PathPolicyDomain,ReadPolicyRights,filename);
1457 if (status == MagickFalse)
1460 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1461 "NotAuthorized",
"`%s'",filename);
1465 if (LocaleCompare(filename,
"-") != 0)
1467 status=GetPathAttributes(filename,&attributes);
1468 if ((status == MagickFalse) || (S_ISDIR(attributes.st_mode) != 0))
1470 ThrowFileException(exception,BlobError,
"UnableToReadBlob",filename);
1473 file=open_utf8(filename,O_RDONLY | O_BINARY,0);
1477 ThrowFileException(exception,BlobError,
"UnableToOpenFile",filename);
1480 offset=(MagickOffsetType) lseek(file,0,SEEK_END);
1482 if ((file == fileno(stdin)) || (offset < 0) ||
1483 (offset != (MagickOffsetType) ((ssize_t) offset)))
1494 offset=(MagickOffsetType) lseek(file,0,SEEK_SET);
1495 quantum=(size_t) MagickMaxBufferExtent;
1496 if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
1497 quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
1498 blob=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*blob));
1499 for (i=0; blob != (
unsigned char *) NULL; i+=(size_t) count)
1501 count=read(file,blob+i,quantum);
1508 if (~i < ((
size_t) count+quantum+1))
1510 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1513 blob=(
unsigned char *) ResizeQuantumMemory(blob,i+(
size_t) count+
1514 quantum+1,
sizeof(*blob));
1515 if ((i+(
size_t) count) >= extent)
1518 if (LocaleCompare(filename,
"-") != 0)
1520 if (blob == (
unsigned char *) NULL)
1522 (void) ThrowMagickException(exception,GetMagickModule(),
1523 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1528 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1529 ThrowFileException(exception,BlobError,
"UnableToReadBlob",filename);
1532 *length=(size_t) MagickMin(i+(
size_t) count,extent);
1536 *length=(size_t) MagickMin(offset,(MagickOffsetType)
1537 MagickMin(extent,(
size_t) MAGICK_SSIZE_MAX));
1538 blob=(
unsigned char *) NULL;
1539 if (~(*length) >= (MagickPathExtent-1))
1540 blob=(
unsigned char *) AcquireQuantumMemory(*length+MagickPathExtent,
1542 if (blob == (
unsigned char *) NULL)
1545 (void) ThrowMagickException(exception,GetMagickModule(),
1546 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1549 map=MapBlob(file,ReadMode,0,*length);
1550 if (map != (
unsigned char *) NULL)
1552 (void) memcpy(blob,map,*length);
1553 (void) UnmapBlob(map,*length);
1557 (void) lseek(file,0,SEEK_SET);
1558 for (i=0; i < *length; i+=(size_t) count)
1560 count=read(file,blob+i,(
size_t) MagickMin(*length-i,(
size_t)
1561 MagickMaxBufferExtent));
1572 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1573 ThrowFileException(exception,BlobError,
"UnableToReadBlob",filename);
1578 if (LocaleCompare(filename,
"-") != 0)
1582 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1583 ThrowFileException(exception,BlobError,
"UnableToReadBlob",filename);
1612static inline ssize_t WriteBlobStream(
Image *image,
const size_t length,
1613 const void *magick_restrict data)
1616 *magick_restrict blob_info;
1624 assert(image->blob != (
BlobInfo *) NULL);
1625 assert(image->blob->type != UndefinedStream);
1626 assert(data != NULL);
1627 blob_info=image->blob;
1628 if (blob_info->type != BlobStream)
1629 return(WriteBlob(image,length,(
const unsigned char *) data));
1630 extent=(MagickSizeType) (blob_info->offset+(MagickOffsetType) length);
1631 if (extent >= blob_info->extent)
1633 extent=blob_info->extent+blob_info->quantum+length;
1634 blob_info->quantum<<=1;
1635 if (SetBlobExtent(image,extent) == MagickFalse)
1638 q=blob_info->data+blob_info->offset;
1639 (void) memcpy(q,data,length);
1640 blob_info->offset+=(MagickOffsetType) length;
1641 if (blob_info->offset >= (MagickOffsetType) blob_info->length)
1642 blob_info->length=(size_t) blob_info->offset;
1643 return((ssize_t) length);
1646MagickExport MagickBooleanType FileToImage(
Image *image,
const char *filename,
1668 assert(image != (
const Image *) NULL);
1669 assert(image->signature == MagickCoreSignature);
1670 assert(filename != (
const char *) NULL);
1671 if (IsEventLogging() != MagickFalse)
1672 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
1673 status=IsRightsAuthorized(PathPolicyDomain,WritePolicyRights,filename);
1674 if (status == MagickFalse)
1677 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1678 "NotAuthorized",
"`%s'",filename);
1679 return(MagickFalse);
1682 if (LocaleCompare(filename,
"-") != 0)
1683 file=open_utf8(filename,O_RDONLY | O_BINARY,0);
1686 ThrowFileException(exception,BlobError,
"UnableToOpenBlob",filename);
1687 return(MagickFalse);
1689 quantum=(size_t) MagickMaxBufferExtent;
1690 if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
1691 quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
1692 blob=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*blob));
1693 if (blob == (
unsigned char *) NULL)
1696 ThrowFileException(exception,ResourceLimitError,
"MemoryAllocationFailed",
1698 return(MagickFalse);
1702 count=read(file,blob,quantum);
1709 length=(size_t) count;
1710 count=WriteBlobStream(image,length,blob);
1711 if (count != (ssize_t) length)
1713 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",filename);
1719 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",filename);
1720 blob=(
unsigned char *) RelinquishMagickMemory(blob);
1747MagickExport MagickBooleanType GetBlobError(
const Image *image)
1749 assert(image != (
const Image *) NULL);
1750 assert(image->signature == MagickCoreSignature);
1751 if (IsEventLogging() != MagickFalse)
1752 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1753 if ((image->blob->status != 0) && (image->blob->error_number != 0))
1754 errno=image->blob->error_number;
1755 return(image->blob->status == 0 ? MagickFalse : MagickTrue);
1780MagickExport FILE *GetBlobFileHandle(
const Image *image)
1782 assert(image != (
const Image *) NULL);
1783 assert(image->signature == MagickCoreSignature);
1784 return(image->blob->file_info.file);
1809MagickExport
void GetBlobInfo(
BlobInfo *blob_info)
1811 assert(blob_info != (
BlobInfo *) NULL);
1812 (void) memset(blob_info,0,
sizeof(*blob_info));
1813 blob_info->type=UndefinedStream;
1814 blob_info->quantum=(size_t) MagickMaxBlobExtent;
1815 blob_info->properties.st_mtime=GetMagickTime();
1816 blob_info->properties.st_ctime=blob_info->properties.st_mtime;
1817 blob_info->debug=GetLogEventMask() & BlobEvent ? MagickTrue : MagickFalse;
1818 blob_info->reference_count=1;
1819 blob_info->semaphore=AcquireSemaphoreInfo();
1820 blob_info->signature=MagickCoreSignature;
1845MagickExport
const struct stat *GetBlobProperties(
const Image *image)
1847 assert(image != (
Image *) NULL);
1848 assert(image->signature == MagickCoreSignature);
1849 if (IsEventLogging() != MagickFalse)
1850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1851 return(&image->blob->properties);
1877MagickExport MagickSizeType GetBlobSize(
const Image *image)
1880 *magick_restrict blob_info;
1885 assert(image != (
Image *) NULL);
1886 assert(image->signature == MagickCoreSignature);
1887 assert(image->blob != (
BlobInfo *) NULL);
1888 if (IsEventLogging() != MagickFalse)
1889 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1890 blob_info=image->blob;
1892 switch (blob_info->type)
1894 case UndefinedStream:
1895 case StandardStream:
1897 extent=blob_info->size;
1905 extent=(MagickSizeType) blob_info->properties.st_size;
1907 extent=blob_info->size;
1908 file_descriptor=fileno(blob_info->file_info.file);
1909 if (file_descriptor == -1)
1911 if (fstat(file_descriptor,&blob_info->properties) == 0)
1912 extent=(MagickSizeType) blob_info->properties.st_size;
1917 extent=blob_info->size;
1926 status=GetPathAttributes(image->filename,&blob_info->properties);
1927 if (status != MagickFalse)
1928 extent=(MagickSizeType) blob_info->properties.st_size;
1935 extent=(MagickSizeType) blob_info->length;
1940 if ((blob_info->custom_stream->teller != (CustomStreamTeller) NULL) &&
1941 (blob_info->custom_stream->seeker != (CustomStreamSeeker) NULL))
1946 offset=blob_info->custom_stream->teller(
1947 blob_info->custom_stream->data);
1948 extent=(MagickSizeType) blob_info->custom_stream->seeker(0,SEEK_END,
1949 blob_info->custom_stream->data);
1950 (void) blob_info->custom_stream->seeker(offset,SEEK_SET,
1951 blob_info->custom_stream->data);
1981MagickExport
void *GetBlobStreamData(
const Image *image)
1983 assert(image != (
const Image *) NULL);
1984 assert(image->signature == MagickCoreSignature);
1985 return(image->blob->data);
2010MagickExport StreamHandler GetBlobStreamHandler(
const Image *image)
2012 assert(image != (
const Image *) NULL);
2013 assert(image->signature == MagickCoreSignature);
2014 if (IsEventLogging() != MagickFalse)
2015 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2016 return(image->blob->stream);
2052MagickExport
void *ImageToBlob(
const ImageInfo *image_info,
2067 assert(image_info != (
const ImageInfo *) NULL);
2068 assert(image_info->signature == MagickCoreSignature);
2069 assert(image != (
Image *) NULL);
2070 assert(image->signature == MagickCoreSignature);
2072 assert(exception->signature == MagickCoreSignature);
2073 if (IsEventLogging() != MagickFalse)
2074 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2075 image_info->filename);
2077 blob=(
unsigned char *) NULL;
2078 blob_info=CloneImageInfo(image_info);
2079 blob_info->adjoin=MagickFalse;
2080 (void) SetImageInfo(blob_info,1,exception);
2081 if (*blob_info->magick !=
'\0')
2082 (void) CopyMagickString(image->magick,blob_info->magick,MagickPathExtent);
2083 magick_info=GetMagickInfo(image->magick,exception);
2084 if (magick_info == (
const MagickInfo *) NULL)
2086 (void) ThrowMagickException(exception,GetMagickModule(),
2087 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
"`%s'",
2089 blob_info=DestroyImageInfo(blob_info);
2092 (void) CopyMagickString(blob_info->magick,image->magick,MagickPathExtent);
2093 if (GetMagickBlobSupport(magick_info) != MagickFalse)
2098 blob_info->length=0;
2099 blob_info->blob=AcquireQuantumMemory(MagickMaxBlobExtent,
2100 sizeof(
unsigned char));
2101 if (blob_info->blob == NULL)
2102 (void) ThrowMagickException(exception,GetMagickModule(),
2103 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",image->filename);
2106 (void) CloseBlob(image);
2107 image->blob->exempt=MagickTrue;
2108 image->blob->extent=0;
2109 *image->filename=
'\0';
2110 status=WriteImage(blob_info,image,exception);
2111 *length=image->blob->length;
2112 blob=DetachBlob(image->blob);
2113 if (blob != (
void *) NULL)
2115 if (status == MagickFalse)
2116 blob=RelinquishMagickMemory(blob);
2118 blob=ResizeQuantumMemory(blob,*length+1,
sizeof(
unsigned char));
2120 else if ((status == MagickFalse) && (image->blob->extent == 0))
2121 blob_info->blob=RelinquishMagickMemory(blob_info->blob);
2127 unique[MagickPathExtent];
2135 file=AcquireUniqueFileResource(unique);
2138 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",
2139 image_info->filename);
2143 blob_info->file=fdopen(file,
"wb");
2144 if (blob_info->file != (FILE *) NULL)
2146 (void) FormatLocaleString(image->filename,MagickPathExtent,
2147 "%s:%s",image->magick,unique);
2148 status=WriteImage(blob_info,image,exception);
2149 (void) fclose(blob_info->file);
2150 if (status != MagickFalse)
2151 blob=FileToBlob(unique,SIZE_MAX,length,exception);
2153 (void) RelinquishUniqueFileResource(unique);
2156 blob_info=DestroyImageInfo(blob_info);
2188MagickExport
void ImageToCustomStream(
const ImageInfo *image_info,
Image *image,
2201 assert(image_info != (
const ImageInfo *) NULL);
2202 assert(image_info->signature == MagickCoreSignature);
2203 assert(image != (
Image *) NULL);
2204 assert(image->signature == MagickCoreSignature);
2206 assert(image_info->custom_stream->signature == MagickCoreSignature);
2207 assert(image_info->custom_stream->writer != (CustomStreamHandler) NULL);
2209 if (IsEventLogging() != MagickFalse)
2210 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2211 image_info->filename);
2212 clone_info=CloneImageInfo(image_info);
2213 clone_info->adjoin=MagickFalse;
2214 (void) SetImageInfo(clone_info,1,exception);
2215 if (*clone_info->magick !=
'\0')
2216 (void) CopyMagickString(image->magick,clone_info->magick,MagickPathExtent);
2217 magick_info=GetMagickInfo(image->magick,exception);
2218 if (magick_info == (
const MagickInfo *) NULL)
2220 (void) ThrowMagickException(exception,GetMagickModule(),
2221 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
"`%s'",
2223 clone_info=DestroyImageInfo(clone_info);
2226 (void) CopyMagickString(clone_info->magick,image->magick,MagickPathExtent);
2227 blob_support=GetMagickBlobSupport(magick_info);
2228 if ((blob_support != MagickFalse) &&
2229 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
2231 if ((clone_info->custom_stream->seeker == (CustomStreamSeeker) NULL) ||
2232 (clone_info->custom_stream->teller == (CustomStreamTeller) NULL))
2233 blob_support=MagickFalse;
2235 if (blob_support != MagickFalse)
2240 (void) CloseBlob(image);
2241 *image->filename=
'\0';
2242 (void) WriteImage(clone_info,image,exception);
2247 unique[MagickPathExtent];
2259 blob=(
unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
2261 if (blob == (
unsigned char *) NULL)
2263 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",
2264 image_info->filename);
2265 clone_info=DestroyImageInfo(clone_info);
2268 file=AcquireUniqueFileResource(unique);
2271 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",
2272 image_info->filename);
2273 blob=(
unsigned char *) RelinquishMagickMemory(blob);
2274 clone_info=DestroyImageInfo(clone_info);
2277 clone_info->file=fdopen(file,
"wb+");
2278 if (clone_info->file != (FILE *) NULL)
2283 (void) FormatLocaleString(image->filename,MagickPathExtent,
2284 "%s:%s",image->magick,unique);
2285 status=WriteImage(clone_info,image,exception);
2286 if (status != MagickFalse)
2288 (void) fseek(clone_info->file,0,SEEK_SET);
2289 count=(ssize_t) MagickMaxBufferExtent;
2290 while (count == (ssize_t) MagickMaxBufferExtent)
2292 count=(ssize_t) fread(blob,
sizeof(*blob),MagickMaxBufferExtent,
2294 (void) image_info->custom_stream->writer(blob,(
size_t) count,
2295 image_info->custom_stream->data);
2298 (void) fclose(clone_info->file);
2300 blob=(
unsigned char *) RelinquishMagickMemory(blob);
2301 (void) RelinquishUniqueFileResource(unique);
2303 clone_info=DestroyImageInfo(clone_info);
2334MagickExport MagickBooleanType ImageToFile(
Image *image,
char *filename,
2359 assert(image != (
Image *) NULL);
2360 assert(image->signature == MagickCoreSignature);
2361 assert(image->blob != (
BlobInfo *) NULL);
2362 assert(image->blob->type != UndefinedStream);
2363 assert(filename != (
const char *) NULL);
2364 if (IsEventLogging() != MagickFalse)
2365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
2366 if (*filename ==
'\0')
2367 file=AcquireUniqueFileResource(filename);
2369 if (LocaleCompare(filename,
"-") == 0)
2370 file=fileno(stdout);
2372 file=open_utf8(filename,O_RDWR | O_CREAT | O_EXCL | O_BINARY,S_MODE);
2375 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",filename);
2376 return(MagickFalse);
2378 quantum=(size_t) MagickMaxBufferExtent;
2379 if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
2380 quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
2381 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
2382 if (buffer == (
unsigned char *) NULL)
2385 (void) ThrowMagickException(exception,GetMagickModule(),
2386 ResourceLimitError,
"MemoryAllocationError",
"`%s'",filename);
2387 return(MagickFalse);
2390 p=(
const unsigned char *) ReadBlobStream(image,quantum,buffer,&count);
2391 for (i=0; count > 0; )
2393 length=(size_t) count;
2394 for (i=0; i < length; i+=(size_t) count)
2396 count=write(file,p+i,(
size_t) (length-i));
2406 p=(
const unsigned char *) ReadBlobStream(image,quantum,buffer,&count);
2408 if (LocaleCompare(filename,
"-") != 0)
2410 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
2411 if ((file == -1) || (i < length))
2415 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",filename);
2416 return(MagickFalse);
2456MagickExport
void *ImagesToBlob(
const ImageInfo *image_info,
Image *images,
2471 assert(image_info != (
const ImageInfo *) NULL);
2472 assert(image_info->signature == MagickCoreSignature);
2473 assert(images != (
Image *) NULL);
2474 assert(images->signature == MagickCoreSignature);
2476 if (IsEventLogging() != MagickFalse)
2477 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2478 image_info->filename);
2480 blob=(
unsigned char *) NULL;
2481 blob_info=CloneImageInfo(image_info);
2482 (void) SetImageInfo(blob_info,(
unsigned int) GetImageListLength(images),
2484 if (*blob_info->magick !=
'\0')
2485 (void) CopyMagickString(images->magick,blob_info->magick,MagickPathExtent);
2486 magick_info=GetMagickInfo(images->magick,exception);
2487 if (magick_info == (
const MagickInfo *) NULL)
2489 (void) ThrowMagickException(exception,GetMagickModule(),
2490 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
"`%s'",
2492 blob_info=DestroyImageInfo(blob_info);
2495 if (GetMagickAdjoin(magick_info) == MagickFalse)
2497 blob_info=DestroyImageInfo(blob_info);
2498 return(ImageToBlob(image_info,images,length,exception));
2500 (void) CopyMagickString(blob_info->magick,images->magick,MagickPathExtent);
2501 if (GetMagickBlobSupport(magick_info) != MagickFalse)
2506 blob_info->length=0;
2507 blob_info->blob=AcquireQuantumMemory(MagickMaxBlobExtent,
2508 sizeof(
unsigned char));
2509 if (blob_info->blob == (
void *) NULL)
2510 (void) ThrowMagickException(exception,GetMagickModule(),
2511 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",images->filename);
2514 (void) CloseBlob(images);
2515 images->blob->exempt=MagickTrue;
2516 images->blob->extent=0;
2517 *images->filename=
'\0';
2518 status=WriteImages(blob_info,images,images->filename,exception);
2519 *length=images->blob->length;
2520 blob=DetachBlob(images->blob);
2521 if (blob != (
void *) NULL)
2523 if (status == MagickFalse)
2524 blob=RelinquishMagickMemory(blob);
2526 blob=ResizeQuantumMemory(blob,*length+1,
sizeof(
unsigned char));
2528 else if ((status == MagickFalse) && (images->blob->extent == 0))
2529 blob_info->blob=RelinquishMagickMemory(blob_info->blob);
2535 filename[MagickPathExtent],
2536 unique[MagickPathExtent];
2544 file=AcquireUniqueFileResource(unique);
2547 ThrowFileException(exception,FileOpenError,
"UnableToWriteBlob",
2548 image_info->filename);
2552 blob_info->file=fdopen(file,
"wb");
2553 if (blob_info->file != (FILE *) NULL)
2555 (void) FormatLocaleString(filename,MagickPathExtent,
"%s:%s",
2556 images->magick,unique);
2557 status=WriteImages(blob_info,images,filename,exception);
2558 (void) fclose(blob_info->file);
2559 if (status != MagickFalse)
2560 blob=FileToBlob(unique,SIZE_MAX,length,exception);
2562 (void) RelinquishUniqueFileResource(unique);
2565 blob_info=DestroyImageInfo(blob_info);
2597MagickExport
void ImagesToCustomStream(
const ImageInfo *image_info,
2610 assert(image_info != (
const ImageInfo *) NULL);
2611 assert(image_info->signature == MagickCoreSignature);
2612 assert(images != (
Image *) NULL);
2613 assert(images->signature == MagickCoreSignature);
2615 assert(image_info->custom_stream->signature == MagickCoreSignature);
2616 assert(image_info->custom_stream->writer != (CustomStreamHandler) NULL);
2618 if (IsEventLogging() != MagickFalse)
2619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2620 image_info->filename);
2621 clone_info=CloneImageInfo(image_info);
2622 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(images),
2624 if (*clone_info->magick !=
'\0')
2625 (void) CopyMagickString(images->magick,clone_info->magick,MagickPathExtent);
2626 magick_info=GetMagickInfo(images->magick,exception);
2627 if (magick_info == (
const MagickInfo *) NULL)
2629 (void) ThrowMagickException(exception,GetMagickModule(),
2630 MissingDelegateError,
"NoEncodeDelegateForThisImageFormat",
"`%s'",
2632 clone_info=DestroyImageInfo(clone_info);
2635 (void) CopyMagickString(clone_info->magick,images->magick,MagickPathExtent);
2636 blob_support=GetMagickBlobSupport(magick_info);
2637 if ((blob_support != MagickFalse) &&
2638 (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
2640 if ((clone_info->custom_stream->seeker == (CustomStreamSeeker) NULL) ||
2641 (clone_info->custom_stream->teller == (CustomStreamTeller) NULL))
2642 blob_support=MagickFalse;
2644 if (blob_support != MagickFalse)
2649 (void) CloseBlob(images);
2650 *images->filename=
'\0';
2651 (void) WriteImages(clone_info,images,images->filename,exception);
2656 filename[MagickPathExtent],
2657 unique[MagickPathExtent];
2669 blob=(
unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
2671 if (blob == (
unsigned char *) NULL)
2673 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",
2674 image_info->filename);
2675 clone_info=DestroyImageInfo(clone_info);
2678 file=AcquireUniqueFileResource(unique);
2681 ThrowFileException(exception,BlobError,
"UnableToWriteBlob",
2682 image_info->filename);
2683 blob=(
unsigned char *) RelinquishMagickMemory(blob);
2684 clone_info=DestroyImageInfo(clone_info);
2687 clone_info->file=fdopen(file,
"wb+");
2688 if (clone_info->file != (FILE *) NULL)
2693 (void) FormatLocaleString(filename,MagickPathExtent,
"%s:%s",
2694 images->magick,unique);
2695 status=WriteImages(clone_info,images,filename,exception);
2696 if (status != MagickFalse)
2698 (void) fseek(clone_info->file,0,SEEK_SET);
2699 count=(ssize_t) MagickMaxBufferExtent;
2700 while (count == (ssize_t) MagickMaxBufferExtent)
2702 count=(ssize_t) fread(blob,
sizeof(*blob),MagickMaxBufferExtent,
2704 (void) image_info->custom_stream->writer(blob,(
size_t) count,
2705 image_info->custom_stream->data);
2708 (void) fclose(clone_info->file);
2710 blob=(
unsigned char *) RelinquishMagickMemory(blob);
2711 (void) RelinquishUniqueFileResource(unique);
2713 clone_info=DestroyImageInfo(clone_info);
2749MagickExport MagickBooleanType InjectImageBlob(
const ImageInfo *image_info,
2753 filename[MagickPathExtent];
2782 assert(image_info != (
ImageInfo *) NULL);
2783 assert(image_info->signature == MagickCoreSignature);
2784 assert(image != (
Image *) NULL);
2785 assert(image->signature == MagickCoreSignature);
2786 assert(inject_image != (
Image *) NULL);
2787 assert(inject_image->signature == MagickCoreSignature);
2789 if (IsEventLogging() != MagickFalse)
2790 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2791 unique_file=(FILE *) NULL;
2792 file=AcquireUniqueFileResource(filename);
2794 unique_file=fdopen(file,
"wb");
2795 if ((file == -1) || (unique_file == (FILE *) NULL))
2797 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
2798 ThrowFileException(exception,FileOpenError,
"UnableToCreateTemporaryFile",
2800 return(MagickFalse);
2802 byte_image=CloneImage(inject_image,0,0,MagickFalse,exception);
2803 if (byte_image == (
Image *) NULL)
2805 (void) fclose(unique_file);
2806 (void) RelinquishUniqueFileResource(filename);
2807 return(MagickFalse);
2809 (void) FormatLocaleString(byte_image->filename,MagickPathExtent,
"%s:%s",
2811 DestroyBlob(byte_image);
2812 byte_image->blob=CloneBlobInfo((
BlobInfo *) NULL);
2813 write_info=CloneImageInfo(image_info);
2814 SetImageInfoFile(write_info,unique_file);
2815 status=WriteImage(write_info,byte_image,exception);
2816 write_info=DestroyImageInfo(write_info);
2817 byte_image=DestroyImage(byte_image);
2818 (void) fclose(unique_file);
2819 if (status == MagickFalse)
2821 (void) RelinquishUniqueFileResource(filename);
2822 return(MagickFalse);
2827 file=open_utf8(filename,O_RDONLY | O_BINARY,0);
2830 (void) RelinquishUniqueFileResource(filename);
2831 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
2832 image_info->filename);
2833 return(MagickFalse);
2835 quantum=(size_t) MagickMaxBufferExtent;
2836 if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
2837 quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
2838 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
2839 if (buffer == (
unsigned char *) NULL)
2841 (void) RelinquishUniqueFileResource(filename);
2843 ThrowBinaryException(ResourceLimitError,
"MemoryAllocationFailed",
2848 ssize_t count = read(file,buffer,quantum);
2855 status=WriteBlobStream(image,(
size_t) count,buffer) == count ? MagickTrue :
2860 ThrowFileException(exception,FileOpenError,
"UnableToWriteBlob",filename);
2861 (void) RelinquishUniqueFileResource(filename);
2862 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
2888MagickExport MagickBooleanType IsBlobExempt(
const Image *image)
2890 assert(image != (
const Image *) NULL);
2891 assert(image->signature == MagickCoreSignature);
2892 if (IsEventLogging() != MagickFalse)
2893 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2894 return(image->blob->exempt);
2919MagickExport MagickBooleanType IsBlobSeekable(
const Image *image)
2922 *magick_restrict blob_info;
2924 assert(image != (
const Image *) NULL);
2925 assert(image->signature == MagickCoreSignature);
2926 if (IsEventLogging() != MagickFalse)
2927 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2928 blob_info=image->blob;
2929 switch (blob_info->type)
2938 if (blob_info->file_info.file == (FILE *) NULL)
2939 return(MagickFalse);
2940 status=fseek(blob_info->file_info.file,0,SEEK_CUR);
2941 return(status == -1 ? MagickFalse : MagickTrue);
2945#if defined(MAGICKCORE_ZLIB_DELEGATE)
2949 if (blob_info->file_info.gzfile == (gzFile) NULL)
2950 return(MagickFalse);
2951 offset=gzseek(blob_info->file_info.gzfile,0,SEEK_CUR);
2952 return(offset < 0 ? MagickFalse : MagickTrue);
2957 case UndefinedStream:
2961 case StandardStream:
2965 if ((blob_info->custom_stream->seeker != (CustomStreamSeeker) NULL) &&
2966 (blob_info->custom_stream->teller != (CustomStreamTeller) NULL))
2973 return(MagickFalse);
2998MagickExport MagickBooleanType IsBlobTemporary(
const Image *image)
3000 assert(image != (
const Image *) NULL);
3001 assert(image->signature == MagickCoreSignature);
3002 if (IsEventLogging() != MagickFalse)
3003 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
3004 return(image->blob->temporary);
3036MagickExport
void *MapBlob(
int file,
const MapMode mode,
3037 const MagickOffsetType offset,
const size_t length)
3039#if defined(MAGICKCORE_HAVE_MMAP)
3052#if defined(MAP_ANONYMOUS)
3053 flags|=MAP_ANONYMOUS;
3062 protection=PROT_READ;
3068 protection=PROT_WRITE;
3074 protection=PROT_READ | PROT_WRITE;
3079#if !defined(MAGICKCORE_HAVE_HUGEPAGES) || !defined(MAP_HUGETLB)
3080 map=mmap((
char *) NULL,length,protection,flags,file,offset);
3082 map=mmap((
char *) NULL,length,protection,flags | MAP_HUGETLB,file,offset);
3083 if (map == MAP_FAILED)
3084 map=mmap((
char *) NULL,length,protection,flags,file,offset);
3086 if (map == MAP_FAILED)
3123MagickExport
void MSBOrderLong(
unsigned char *buffer,
const size_t length)
3132 assert(buffer != (
unsigned char *) NULL);
3139 *buffer++=(
unsigned char) c;
3143 *buffer++=(
unsigned char) c;
3173MagickExport
void MSBOrderShort(
unsigned char *p,
const size_t length)
3181 assert(p != (
unsigned char *) NULL);
3188 *p++=(
unsigned char) c;
3224static inline MagickBooleanType SetStreamBuffering(
const ImageInfo *image_info,
3236 size=MagickMinBufferExtent;
3237 option=GetImageOption(image_info,
"stream:buffer-size");
3238 if (option != (
const char *) NULL)
3239 size=StringToUnsignedLong(option);
3240 status=setvbuf(blob_info->file_info.file,(
char *) NULL,size == 0 ?
3241 _IONBF : _IOFBF,size);
3242 return(status == 0 ? MagickTrue : MagickFalse);
3245#if defined(MAGICKCORE_ZLIB_DELEGATE)
3246static inline gzFile gzopen_utf8(
const char *path,
const char *mode)
3248#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
3249 return(gzopen(path,mode));
3257 path_wide=create_wchar_path(path);
3258 if (path_wide == (
wchar_t *) NULL)
3259 return((gzFile) NULL);
3260 file=gzopen_w(path_wide,mode);
3261 path_wide=(
wchar_t *) RelinquishMagickMemory(path_wide);
3267MagickExport MagickBooleanType OpenBlob(
const ImageInfo *image_info,
3271 *magick_restrict blob_info;
3274 extension[MagickPathExtent],
3275 filename[MagickPathExtent];
3286 assert(image_info != (
ImageInfo *) NULL);
3287 assert(image_info->signature == MagickCoreSignature);
3288 assert(image != (
Image *) NULL);
3289 assert(image->signature == MagickCoreSignature);
3290 if (IsEventLogging() != MagickFalse)
3291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3292 image_info->filename);
3293 blob_info=image->blob;
3294 if (image_info->blob != (
void *) NULL)
3296 if (image_info->stream != (StreamHandler) NULL)
3297 blob_info->stream=(StreamHandler) image_info->stream;
3298 AttachBlob(blob_info,image_info->blob,image_info->length);
3302 (*image->filename ==
'\0'))
3304 blob_info->type=CustomStream;
3305 blob_info->custom_stream=image_info->custom_stream;
3308 (void) DetachBlob(blob_info);
3309 blob_info->mode=mode;
3312 default: type=
"r";
break;
3313 case ReadBlobMode: type=
"r";
break;
3314 case ReadBinaryBlobMode: type=
"rb";
break;
3315 case WriteBlobMode: type=
"w";
break;
3316 case WriteBinaryBlobMode: type=
"w+b";
break;
3317 case AppendBlobMode: type=
"a";
break;
3318 case AppendBinaryBlobMode: type=
"a+b";
break;
3321 blob_info->synchronize=image_info->synchronize;
3322 if (image_info->stream != (StreamHandler) NULL)
3324 blob_info->stream=image_info->stream;
3327 blob_info->type=FifoStream;
3335 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
3336 rights=ReadPolicyRights;
3338 rights=WritePolicyRights;
3339 if (IsRightsAuthorized(PathPolicyDomain,rights,filename) == MagickFalse)
3342 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
3343 "NotAuthorized",
"`%s'",filename);
3344 return(MagickFalse);
3346 if ((LocaleCompare(filename,
"-") == 0) ||
3347 ((*filename ==
'\0') && (image_info->file == (FILE *) NULL)))
3349 blob_info->file_info.file=(*type ==
'r') ? stdin : stdout;
3350#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__)
3351 if (strchr(type,
'b') != (
char *) NULL)
3352 (void) setmode(fileno(blob_info->file_info.file),_O_BINARY);
3354 blob_info->type=StandardStream;
3355 blob_info->exempt=MagickTrue;
3356 return(SetStreamBuffering(image_info,blob_info));
3358 if ((LocaleNCompare(filename,
"fd:",3) == 0) &&
3359 (IsGeometry(filename+3) != MagickFalse))
3366 blob_info->file_info.file=fdopen(StringToLong(filename+3),fileMode);
3367 if (blob_info->file_info.file == (FILE *) NULL)
3369 ThrowFileException(exception,BlobError,
"UnableToOpenBlob",filename);
3370 return(MagickFalse);
3372#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__)
3373 if (strchr(type,
'b') != (
char *) NULL)
3374 (void) setmode(fileno(blob_info->file_info.file),_O_BINARY);
3376 blob_info->type=FileStream;
3377 blob_info->exempt=MagickTrue;
3378 return(SetStreamBuffering(image_info,blob_info));
3380#if defined(MAGICKCORE_HAVE_POPEN) && defined(MAGICKCORE_PIPES_SUPPORT)
3381 if (*filename ==
'|')
3384 fileMode[MagickPathExtent],
3392 (void) signal(SIGPIPE,SIG_IGN);
3396 sanitize_command=SanitizeString(filename+1);
3397 blob_info->file_info.file=(FILE *) popen_utf8(sanitize_command,fileMode);
3398 sanitize_command=DestroyString(sanitize_command);
3399 if (blob_info->file_info.file == (FILE *) NULL)
3401 ThrowFileException(exception,BlobError,
"UnableToOpenBlob",filename);
3402 return(MagickFalse);
3404 blob_info->type=PipeStream;
3405 blob_info->exempt=MagickTrue;
3406 return(SetStreamBuffering(image_info,blob_info));
3409 status=GetPathAttributes(filename,&blob_info->properties);
3410#if defined(S_ISFIFO)
3411 if ((status != MagickFalse) && S_ISFIFO(blob_info->properties.st_mode))
3413 blob_info->file_info.file=(FILE *) fopen_utf8(filename,type);
3414 if (blob_info->file_info.file == (FILE *) NULL)
3416 ThrowFileException(exception,BlobError,
"UnableToOpenBlob",filename);
3417 return(MagickFalse);
3419 blob_info->type=FileStream;
3420 blob_info->exempt=MagickTrue;
3421 return(SetStreamBuffering(image_info,blob_info));
3424 GetPathComponent(image->filename,ExtensionPath,extension);
3427 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
3428 if ((image_info->adjoin == MagickFalse) ||
3429 (strchr(filename,
'%') != (
char *) NULL))
3434 (void) InterpretImageFilename(image_info,image,image->filename,(
int)
3435 image->scene,filename,exception);
3436 if ((LocaleCompare(filename,image->filename) == 0) &&
3437 ((GetPreviousImageInList(image) != (
Image *) NULL) ||
3438 (GetNextImageInList(image) != (
Image *) NULL)))
3441 path[MagickPathExtent];
3443 GetPathComponent(image->filename,RootPath,path);
3444 if (*extension ==
'\0')
3445 (void) FormatLocaleString(filename,MagickPathExtent,
"%s-%.20g",
3446 path,(
double) image->scene);
3448 (
void) FormatLocaleString(filename,MagickPathExtent,
3449 "%s-%.20g.%s",path,(
double) image->scene,extension);
3451 (void) CopyMagickString(image->filename,filename,MagickPathExtent);
3454 if (image_info->file != (FILE *) NULL)
3456 blob_info->file_info.file=image_info->file;
3457 blob_info->type=FileStream;
3458 blob_info->exempt=MagickTrue;
3463 blob_info->file_info.file=(FILE *) fopen_utf8(filename,type);
3464 if (blob_info->file_info.file != (FILE *) NULL)
3472 blob_info->type=FileStream;
3473 (void) SetStreamBuffering(image_info,blob_info);
3474 (void) memset(magick,0,
sizeof(magick));
3475 count=fread(magick,1,
sizeof(magick),blob_info->file_info.file);
3476 (void) fseek(blob_info->file_info.file,-((off_t) count),SEEK_CUR);
3477#if defined(MAGICKCORE_POSIX_SUPPORT)
3478 (void) fflush(blob_info->file_info.file);
3480 (void) LogMagickEvent(BlobEvent,GetMagickModule(),
3481 " read %.20g magic header bytes",(
double) count);
3482#if defined(MAGICKCORE_ZLIB_DELEGATE)
3483 if (((
int) magick[0] == 0x1F) && ((
int) magick[1] == 0x8B) &&
3484 ((
int) magick[2] == 0x08))
3487 gzfile = gzopen_utf8(filename,
"rb");
3489 if (gzfile != (gzFile) NULL)
3491 if (blob_info->file_info.file != (FILE *) NULL)
3492 (void) fclose(blob_info->file_info.file);
3493 blob_info->file_info.file=(FILE *) NULL;
3494 blob_info->file_info.gzfile=gzfile;
3495 blob_info->type=ZipStream;
3499#if defined(MAGICKCORE_BZLIB_DELEGATE)
3500 if (strncmp((
char *) magick,
"BZh",3) == 0)
3503 *bzfile = BZ2_bzopen(filename,
"r");
3505 if (bzfile != (BZFILE *) NULL)
3507 if (blob_info->file_info.file != (FILE *) NULL)
3508 (void) fclose(blob_info->file_info.file);
3509 blob_info->file_info.file=(FILE *) NULL;
3510 blob_info->file_info.bzfile=bzfile;
3511 blob_info->type=BZipStream;
3515 if (blob_info->type == FileStream)
3526 sans_exception=AcquireExceptionInfo();
3527 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3528 sans_exception=DestroyExceptionInfo(sans_exception);
3529 length=(size_t) blob_info->properties.st_size;
3530 if ((magick_info != (
const MagickInfo *) NULL) &&
3531 (GetMagickBlobSupport(magick_info) != MagickFalse) &&
3532 (length > MagickMaxBufferExtent) &&
3533 (AcquireMagickResource(MapResource,length) != MagickFalse))
3538 blob=MapBlob(fileno(blob_info->file_info.file),ReadMode,0,
3540 if (blob == (
void *) NULL)
3541 RelinquishMagickResource(MapResource,length);
3547 if (image_info->file != (FILE *) NULL)
3548 blob_info->exempt=MagickFalse;
3551 (void) fclose(blob_info->file_info.file);
3552 blob_info->file_info.file=(FILE *) NULL;
3554 AttachBlob(blob_info,blob,length);
3555 blob_info->mapped=MagickTrue;
3562#if defined(MAGICKCORE_ZLIB_DELEGATE)
3563 if ((LocaleCompare(extension,
"gz") == 0) ||
3564 (LocaleCompare(extension,
"wmz") == 0) ||
3565 (LocaleCompare(extension,
"svgz") == 0))
3567 blob_info->file_info.gzfile=gzopen_utf8(filename,
"wb");
3568 if (blob_info->file_info.gzfile != (gzFile) NULL)
3569 blob_info->type=ZipStream;
3573#if defined(MAGICKCORE_BZLIB_DELEGATE)
3574 if (LocaleCompare(extension,
"bz2") == 0)
3576 blob_info->file_info.bzfile=BZ2_bzopen(filename,
"w");
3577 if (blob_info->file_info.bzfile != (BZFILE *) NULL)
3578 blob_info->type=BZipStream;
3583 blob_info->file_info.file=(FILE *) fopen_utf8(filename,type);
3584 if (blob_info->file_info.file != (FILE *) NULL)
3586 blob_info->type=FileStream;
3587 (void) SetStreamBuffering(image_info,blob_info);
3590 blob_info->status=0;
3591 blob_info->error_number=0;
3592 if (blob_info->type != UndefinedStream)
3593 blob_info->size=GetBlobSize(image);
3596 ThrowFileException(exception,BlobError,
"UnableToOpenBlob",filename);
3597 return(MagickFalse);
3636#if defined(__cplusplus) || defined(c_plusplus)
3640static size_t PingStream(
const Image *magick_unused(image),
3641 const void *magick_unused(pixels),
const size_t columns)
3643 magick_unreferenced(image);
3644 magick_unreferenced(pixels);
3648#if defined(__cplusplus) || defined(c_plusplus)
3652MagickExport
Image *PingBlob(
const ImageInfo *image_info,
const void *blob,
3668 assert(image_info != (
ImageInfo *) NULL);
3669 assert(image_info->signature == MagickCoreSignature);
3671 if (IsEventLogging() != MagickFalse)
3672 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
3673 image_info->filename);
3674 if ((blob == (
const void *) NULL) || (length == 0))
3676 (void) ThrowMagickException(exception,GetMagickModule(),BlobError,
3677 "ZeroLengthBlobNotPermitted",
"`%s'",image_info->filename);
3678 return((
Image *) NULL);
3680 ping_info=CloneImageInfo(image_info);
3681 ping_info->blob=(
void *) blob;
3682 ping_info->length=length;
3683 ping_info->ping=MagickTrue;
3684 if (*ping_info->magick ==
'\0')
3685 (void) SetImageInfo(ping_info,0,exception);
3686 magick_info=GetMagickInfo(ping_info->magick,exception);
3687 if (magick_info == (
const MagickInfo *) NULL)
3689 (void) ThrowMagickException(exception,GetMagickModule(),
3690 MissingDelegateError,
"NoDecodeDelegateForThisImageFormat",
"`%s'",
3692 ping_info=DestroyImageInfo(ping_info);
3693 return((
Image *) NULL);
3695 if (GetMagickBlobSupport(magick_info) != MagickFalse)
3698 filename[MagickPathExtent];
3703 (void) CopyMagickString(filename,ping_info->filename,MagickPathExtent);
3704 (void) FormatLocaleString(ping_info->filename,MagickPathExtent,
"%s:%s",
3705 ping_info->magick,filename);
3706 image=ReadStream(ping_info,&PingStream,exception);
3707 if (image != (
Image *) NULL)
3708 (void) DetachBlob(image->blob);
3709 ping_info=DestroyImageInfo(ping_info);
3715 ping_info->blob=(
void *) NULL;
3716 ping_info->length=0;
3717 *ping_info->filename=
'\0';
3718 status=BlobToFile(ping_info->filename,blob,length,exception);
3719 if (status == MagickFalse)
3721 (void) RelinquishUniqueFileResource(ping_info->filename);
3722 ping_info=DestroyImageInfo(ping_info);
3723 return((
Image *) NULL);
3725 clone_info=CloneImageInfo(ping_info);
3726 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
"%s:%s",
3727 ping_info->magick,ping_info->filename);
3728 image=ReadStream(clone_info,&PingStream,exception);
3729 if (image != (
Image *) NULL)
3737 for (images=GetFirstImageInList(image); images != (
Image *) NULL; )
3739 (void) CopyMagickString(images->filename,image_info->filename,
3741 (void) CopyMagickString(images->magick_filename,image_info->filename,
3743 (void) CopyMagickString(images->magick,magick_info->name,
3745 images=GetNextImageInList(images);
3748 clone_info=DestroyImageInfo(clone_info);
3749 (void) RelinquishUniqueFileResource(ping_info->filename);
3750 ping_info=DestroyImageInfo(ping_info);
3785MagickExport ssize_t ReadBlob(
Image *image,
const size_t length,
void *data)
3788 *magick_restrict blob_info;
3799 assert(image != (
Image *) NULL);
3800 assert(image->signature == MagickCoreSignature);
3801 assert(image->blob != (
BlobInfo *) NULL);
3802 assert(image->blob->type != UndefinedStream);
3805 assert(data != (
void *) NULL);
3806 blob_info=image->blob;
3808 q=(
unsigned char *) data;
3809 switch (blob_info->type)
3811 case UndefinedStream:
3813 case StandardStream:
3821 count=(ssize_t) fread(q,1,length,blob_info->file_info.file);
3826 c=getc(blob_info->file_info.file);
3829 *q++=(
unsigned char) c;
3835 c=getc(blob_info->file_info.file);
3838 *q++=(
unsigned char) c;
3844 c=getc(blob_info->file_info.file);
3847 *q++=(
unsigned char) c;
3853 c=getc(blob_info->file_info.file);
3856 *q++=(
unsigned char) c;
3863 if ((count != (ssize_t) length) &&
3864 (ferror(blob_info->file_info.file) != 0))
3865 ThrowBlobException(blob_info);
3870#if defined(MAGICKCORE_ZLIB_DELEGATE)
3881 for (i=0; i < length; i+=(size_t) count)
3883 count=(ssize_t) gzread(blob_info->file_info.gzfile,q+i,
3884 (
unsigned int) MagickMin(length-i,MagickMaxBufferExtent));
3897 c=gzgetc(blob_info->file_info.gzfile);
3900 *q++=(
unsigned char) c;
3906 c=gzgetc(blob_info->file_info.gzfile);
3909 *q++=(
unsigned char) c;
3915 c=gzgetc(blob_info->file_info.gzfile);
3918 *q++=(
unsigned char) c;
3924 c=gzgetc(blob_info->file_info.gzfile);
3927 *q++=(
unsigned char) c;
3934 (void) gzerror(blob_info->file_info.gzfile,&status);
3935 if ((count != (ssize_t) length) && (status != Z_OK))
3936 ThrowBlobException(blob_info);
3937 if (blob_info->eof == MagickFalse)
3938 blob_info->eof=gzeof(blob_info->file_info.gzfile) != 0 ? MagickTrue :
3945#if defined(MAGICKCORE_BZLIB_DELEGATE)
3952 for (i=0; i < length; i+=(size_t) count)
3954 count=(ssize_t) BZ2_bzread(blob_info->file_info.bzfile,q+i,(
int)
3955 MagickMin(length-i,MagickMaxBufferExtent));
3965 (void) BZ2_bzerror(blob_info->file_info.bzfile,&status);
3966 if ((count != (ssize_t) length) && (status != BZ_OK))
3967 ThrowBlobException(blob_info);
3978 if (blob_info->offset >= (MagickOffsetType) blob_info->length)
3980 blob_info->eof=MagickTrue;
3983 p=blob_info->data+blob_info->offset;
3984 count=(ssize_t) MagickMin((MagickOffsetType) length,(MagickOffsetType)
3985 blob_info->length-blob_info->offset);
3986 blob_info->offset+=count;
3987 if (count != (ssize_t) length)
3988 blob_info->eof=MagickTrue;
3989 (void) memcpy(q,p,(
size_t) count);
3994 if (blob_info->custom_stream->reader != (CustomStreamHandler) NULL)
3995 count=blob_info->custom_stream->reader(q,length,
3996 blob_info->custom_stream->data);
4025MagickExport
int ReadBlobByte(
Image *image)
4028 *magick_restrict blob_info;
4033 assert(image != (
Image *) NULL);
4034 assert(image->signature == MagickCoreSignature);
4035 assert(image->blob != (
BlobInfo *) NULL);
4036 assert(image->blob->type != UndefinedStream);
4037 blob_info=image->blob;
4038 switch (blob_info->type)
4040 case StandardStream:
4044 c=getc(blob_info->file_info.file);
4047 if (ferror(blob_info->file_info.file) != 0)
4048 ThrowBlobException(blob_info);
4055 if (blob_info->offset >= (MagickOffsetType) blob_info->length)
4057 blob_info->eof=MagickTrue;
4060 c=(int) (*((
unsigned char *) blob_info->data+blob_info->offset));
4061 blob_info->offset++;
4072 count=ReadBlob(image,1,buffer);
4105MagickExport
double ReadBlobDouble(
Image *image)
4116 quantum.double_value=0.0;
4117 quantum.unsigned_value=ReadBlobLongLong(image);
4118 return(quantum.double_value);
4144MagickExport
float ReadBlobFloat(
Image *image)
4155 quantum.float_value=0.0;
4156 quantum.unsigned_value=ReadBlobLong(image);
4157 return(quantum.float_value);
4183MagickExport
unsigned int ReadBlobLong(
Image *image)
4197 assert(image != (
Image *) NULL);
4198 assert(image->signature == MagickCoreSignature);
4200 p=(
const unsigned char *) ReadBlobStream(image,4,buffer,&count);
4203 if (image->endian == LSBEndian)
4205 value=(
unsigned int) (*p++);
4206 value|=(
unsigned int) (*p++) << 8;
4207 value|=(
unsigned int) (*p++) << 16;
4208 value|=(
unsigned int) (*p++) << 24;
4211 value=(
unsigned int) (*p++) << 24;
4212 value|=(
unsigned int) (*p++) << 16;
4213 value|=(
unsigned int) (*p++) << 8;
4214 value|=(
unsigned int) (*p++);
4241MagickExport MagickSizeType ReadBlobLongLong(
Image *image)
4255 assert(image != (
Image *) NULL);
4256 assert(image->signature == MagickCoreSignature);
4258 p=(
const unsigned char *) ReadBlobStream(image,8,buffer,&count);
4260 return(MagickULLConstant(0));
4261 if (image->endian == LSBEndian)
4263 value=(MagickSizeType) (*p++);
4264 value|=(MagickSizeType) (*p++) << 8;
4265 value|=(MagickSizeType) (*p++) << 16;
4266 value|=(MagickSizeType) (*p++) << 24;
4267 value|=(MagickSizeType) (*p++) << 32;
4268 value|=(MagickSizeType) (*p++) << 40;
4269 value|=(MagickSizeType) (*p++) << 48;
4270 value|=(MagickSizeType) (*p++) << 56;
4273 value=(MagickSizeType) (*p++) << 56;
4274 value|=(MagickSizeType) (*p++) << 48;
4275 value|=(MagickSizeType) (*p++) << 40;
4276 value|=(MagickSizeType) (*p++) << 32;
4277 value|=(MagickSizeType) (*p++) << 24;
4278 value|=(MagickSizeType) (*p++) << 16;
4279 value|=(MagickSizeType) (*p++) << 8;
4280 value|=(MagickSizeType) (*p++);
4307MagickExport
unsigned short ReadBlobShort(
Image *image)
4321 assert(image != (
Image *) NULL);
4322 assert(image->signature == MagickCoreSignature);
4324 p=(
const unsigned char *) ReadBlobStream(image,2,buffer,&count);
4326 return((
unsigned short) 0U);
4327 if (image->endian == LSBEndian)
4329 value=(
unsigned short) (*p++);
4330 value|=(
unsigned short) (*p++) << 8;
4333 value=(
unsigned short) ((
unsigned short) (*p++) << 8);
4334 value|=(
unsigned short) (*p++);
4361MagickExport
unsigned int ReadBlobLSBLong(
Image *image)
4375 assert(image != (
Image *) NULL);
4376 assert(image->signature == MagickCoreSignature);
4378 p=(
const unsigned char *) ReadBlobStream(image,4,buffer,&count);
4381 value=(
unsigned int) (*p++);
4382 value|=(
unsigned int) (*p++) << 8;
4383 value|=(
unsigned int) (*p++) << 16;
4384 value|=(
unsigned int) (*p++) << 24;
4411MagickExport
signed int ReadBlobLSBSignedLong(
Image *image)
4422 quantum.unsigned_value=ReadBlobLSBLong(image);
4423 return(quantum.signed_value);
4449MagickExport
unsigned short ReadBlobLSBShort(
Image *image)
4463 assert(image != (
Image *) NULL);
4464 assert(image->signature == MagickCoreSignature);
4466 p=(
const unsigned char *) ReadBlobStream(image,2,buffer,&count);
4468 return((
unsigned short) 0U);
4469 value=(
unsigned short) (*p++);
4470 value|=(
unsigned short) (*p++) << 8;
4497MagickExport
signed short ReadBlobLSBSignedShort(
Image *image)
4508 quantum.unsigned_value=ReadBlobLSBShort(image);
4509 return(quantum.signed_value);
4535MagickExport
unsigned int ReadBlobMSBLong(
Image *image)
4549 assert(image != (
Image *) NULL);
4550 assert(image->signature == MagickCoreSignature);
4552 p=(
const unsigned char *) ReadBlobStream(image,4,buffer,&count);
4555 value=(
unsigned int) (*p++) << 24;
4556 value|=(
unsigned int) (*p++) << 16;
4557 value|=(
unsigned int) (*p++) << 8;
4558 value|=(
unsigned int) (*p++);
4585MagickExport MagickSizeType ReadBlobMSBLongLong(
Image *image)
4599 assert(image != (
Image *) NULL);
4600 assert(image->signature == MagickCoreSignature);
4602 p=(
const unsigned char *) ReadBlobStream(image,8,buffer,&count);
4604 return(MagickULLConstant(0));
4605 value=(MagickSizeType) (*p++) << 56;
4606 value|=(MagickSizeType) (*p++) << 48;
4607 value|=(MagickSizeType) (*p++) << 40;
4608 value|=(MagickSizeType) (*p++) << 32;
4609 value|=(MagickSizeType) (*p++) << 24;
4610 value|=(MagickSizeType) (*p++) << 16;
4611 value|=(MagickSizeType) (*p++) << 8;
4612 value|=(MagickSizeType) (*p++);
4639MagickExport
unsigned short ReadBlobMSBShort(
Image *image)
4653 assert(image != (
Image *) NULL);
4654 assert(image->signature == MagickCoreSignature);
4656 p=(
const unsigned char *) ReadBlobStream(image,2,buffer,&count);
4658 return((
unsigned short) 0U);
4659 value=(
unsigned short) ((*p++) << 8);
4660 value|=(
unsigned short) (*p++);
4661 return((
unsigned short) (value & 0xffff));
4687MagickExport
signed int ReadBlobMSBSignedLong(
Image *image)
4698 quantum.unsigned_value=ReadBlobMSBLong(image);
4699 return(quantum.signed_value);
4725MagickExport
signed short ReadBlobMSBSignedShort(
Image *image)
4736 quantum.unsigned_value=ReadBlobMSBShort(image);
4737 return(quantum.signed_value);
4763MagickExport
signed int ReadBlobSignedLong(
Image *image)
4774 quantum.unsigned_value=ReadBlobLong(image);
4775 return(quantum.signed_value);
4801MagickExport
signed short ReadBlobSignedShort(
Image *image)
4812 quantum.unsigned_value=ReadBlobShort(image);
4813 return(quantum.signed_value);
4851MagickExport magick_hot_spot
const void *ReadBlobStream(
Image *image,
4852 const size_t length,
void *magick_restrict data,ssize_t *count)
4855 *magick_restrict blob_info;
4857 assert(image != (
Image *) NULL);
4858 assert(image->signature == MagickCoreSignature);
4859 assert(image->blob != (
BlobInfo *) NULL);
4860 assert(image->blob->type != UndefinedStream);
4861 assert(count != (ssize_t *) NULL);
4862 blob_info=image->blob;
4863 if (blob_info->type != BlobStream)
4865 assert(data != NULL);
4866 *count=ReadBlob(image,length,(
unsigned char *) data);
4869 if (blob_info->offset >= (MagickOffsetType) blob_info->length)
4872 blob_info->eof=MagickTrue;
4875 data=blob_info->data+blob_info->offset;
4876 *count=(ssize_t) MagickMin((MagickOffsetType) length,(MagickOffsetType)
4877 blob_info->length-blob_info->offset);
4878 blob_info->offset+=(*count);
4879 if (*count != (ssize_t) length)
4880 blob_info->eof=MagickTrue;
4909MagickExport
char *ReadBlobString(
Image *image,
char *
string)
4912 *magick_restrict blob_info;
4920 assert(image != (
Image *) NULL);
4921 assert(image->signature == MagickCoreSignature);
4922 assert(image->blob != (
BlobInfo *) NULL);
4923 assert(image->blob->type != UndefinedStream);
4924 if (IsEventLogging() != MagickFalse)
4925 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
4927 blob_info=image->blob;
4928 switch (blob_info->type)
4930 case UndefinedStream:
4932 case StandardStream:
4935 char *p = fgets(
string,MagickPathExtent,blob_info->file_info.file);
4936 if (p == (
char *) NULL)
4938 if (ferror(blob_info->file_info.file) != 0)
4939 ThrowBlobException(blob_info);
4940 return((
char *) NULL);
4947#if defined(MAGICKCORE_ZLIB_DELEGATE)
4948 char *p = gzgets(blob_info->file_info.gzfile,
string,MagickPathExtent);
4949 if (p == (
char *) NULL)
4952 (void) gzerror(blob_info->file_info.gzfile,&status);
4954 ThrowBlobException(blob_info);
4955 return((
char *) NULL);
4965 c=ReadBlobByte(image);
4968 blob_info->eof=MagickTrue;
4974 }
while (i < (MaxTextExtent-2));
4982 if ((
string[i] ==
'\r') || (
string[i] ==
'\n'))
4985 if ((
string[i-1] ==
'\r') || (
string[i-1] ==
'\n'))
4987 if ((*
string ==
'\0') && (blob_info->eof != MagickFalse))
4988 return((
char *) NULL);
5018 assert(blob->signature == MagickCoreSignature);
5019 if (IsEventLogging() != MagickFalse)
5020 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
5021 LockSemaphoreInfo(blob->semaphore);
5022 blob->reference_count++;
5023 UnlockSemaphoreInfo(blob->semaphore);
5060MagickExport MagickOffsetType SeekBlob(
Image *image,
5061 const MagickOffsetType offset,
const int whence)
5064 *magick_restrict blob_info;
5066 assert(image != (
Image *) NULL);
5067 assert(image->signature == MagickCoreSignature);
5068 assert(image->blob != (
BlobInfo *) NULL);
5069 assert(image->blob->type != UndefinedStream);
5070 if (IsEventLogging() != MagickFalse)
5071 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5072 blob_info=image->blob;
5073 switch (blob_info->type)
5075 case UndefinedStream:
5077 case StandardStream:
5082 if ((offset < 0) && (whence == SEEK_SET))
5084 if (fseek(blob_info->file_info.file,offset,whence) < 0)
5086 blob_info->offset=TellBlob(image);
5091#if defined(MAGICKCORE_ZLIB_DELEGATE)
5092 if (gzseek(blob_info->file_info.gzfile,offset,whence) < 0)
5095 blob_info->offset=TellBlob(image);
5111 blob_info->offset=offset;
5116 if (((offset > 0) && (blob_info->offset > (MAGICK_SSIZE_MAX-offset))) ||
5117 ((offset < 0) && (blob_info->offset < (MAGICK_SSIZE_MIN-offset))))
5122 if ((blob_info->offset+offset) < 0)
5124 blob_info->offset+=offset;
5129 if (((MagickOffsetType) blob_info->length+offset) < 0)
5131 blob_info->offset=(MagickOffsetType) blob_info->length+offset;
5135 if (blob_info->offset < (MagickOffsetType) ((off_t) blob_info->length))
5137 blob_info->eof=MagickFalse;
5144 if (blob_info->custom_stream->seeker == (CustomStreamSeeker) NULL)
5146 blob_info->offset=blob_info->custom_stream->seeker(offset,whence,
5147 blob_info->custom_stream->data);
5151 return(blob_info->offset);
5179MagickExport
void SetBlobExempt(
Image *image,
const MagickBooleanType exempt)
5181 assert(image != (
const Image *) NULL);
5182 assert(image->signature == MagickCoreSignature);
5183 if (IsEventLogging() != MagickFalse)
5184 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5185 image->blob->exempt=exempt;
5214MagickExport MagickBooleanType SetBlobExtent(
Image *image,
5215 const MagickSizeType extent)
5218 *magick_restrict blob_info;
5220 assert(image != (
Image *) NULL);
5221 assert(image->signature == MagickCoreSignature);
5222 assert(image->blob != (
BlobInfo *) NULL);
5223 assert(image->blob->type != UndefinedStream);
5224 if (IsEventLogging() != MagickFalse)
5225 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5226 blob_info=image->blob;
5227 switch (blob_info->type)
5229 case UndefinedStream:
5231 case StandardStream:
5232 return(MagickFalse);
5241 if (extent != (MagickSizeType) ((off_t) extent))
5242 return(MagickFalse);
5243 offset=SeekBlob(image,0,SEEK_END);
5245 return(MagickFalse);
5246 if ((MagickSizeType) offset >= extent)
5248 offset=SeekBlob(image,(MagickOffsetType) extent-1,SEEK_SET);
5251 count=(ssize_t) fwrite((
const unsigned char *)
"",1,1,
5252 blob_info->file_info.file);
5253#if defined(MAGICKCORE_HAVE_POSIX_FALLOCATE)
5254 if (blob_info->synchronize != MagickFalse)
5259 file=fileno(blob_info->file_info.file);
5260 if ((file == -1) || (offset < 0))
5261 return(MagickFalse);
5262 (void) posix_fallocate(file,offset,(MagickOffsetType) extent-offset);
5265 offset=SeekBlob(image,offset,SEEK_SET);
5267 return(MagickFalse);
5272 return(MagickFalse);
5274 return(MagickFalse);
5276 return(MagickFalse);
5279 if (extent != (MagickSizeType) ((
size_t) extent))
5280 return(MagickFalse);
5281 if (blob_info->mapped != MagickFalse)
5289 (void) UnmapBlob(blob_info->data,blob_info->length);
5290 RelinquishMagickResource(MapResource,blob_info->length);
5291 if (extent != (MagickSizeType) ((off_t) extent))
5292 return(MagickFalse);
5293 offset=SeekBlob(image,0,SEEK_END);
5295 return(MagickFalse);
5296 if ((MagickSizeType) offset >= extent)
5298 offset=SeekBlob(image,(MagickOffsetType) extent-1,SEEK_SET);
5299 count=(ssize_t) fwrite((
const unsigned char *)
"",1,1,
5300 blob_info->file_info.file);
5301#if defined(MAGICKCORE_HAVE_POSIX_FALLOCATE)
5302 if (blob_info->synchronize != MagickFalse)
5307 file=fileno(blob_info->file_info.file);
5308 if ((file == -1) || (offset < 0))
5309 return(MagickFalse);
5310 (void) posix_fallocate(file,offset,(MagickOffsetType) extent-
5314 offset=SeekBlob(image,offset,SEEK_SET);
5316 return(MagickFalse);
5317 (void) AcquireMagickResource(MapResource,extent);
5318 blob_info->data=(
unsigned char*) MapBlob(fileno(
5319 blob_info->file_info.file),WriteMode,0,(
size_t) extent);
5320 blob_info->extent=(size_t) extent;
5321 blob_info->length=(size_t) extent;
5322 (void) SyncBlob(image);
5325 blob_info->extent=(size_t) extent;
5326 blob_info->data=(
unsigned char *) ResizeQuantumMemory(blob_info->data,
5327 blob_info->extent+1,
sizeof(*blob_info->data));
5328 (void) SyncBlob(image);
5329 if (blob_info->data == (
unsigned char *) NULL)
5331 (void) DetachBlob(blob_info);
5332 return(MagickFalse);
5370 assert(custom_stream->signature == MagickCoreSignature);
5371 custom_stream->data=data;
5400 CustomStreamHandler reader)
5403 assert(custom_stream->signature == MagickCoreSignature);
5404 custom_stream->reader=reader;
5433 CustomStreamSeeker seeker)
5436 assert(custom_stream->signature == MagickCoreSignature);
5437 custom_stream->seeker=seeker;
5466 CustomStreamTeller teller)
5469 assert(custom_stream->signature == MagickCoreSignature);
5470 custom_stream->teller=teller;
5499 CustomStreamHandler writer)
5502 assert(custom_stream->signature == MagickCoreSignature);
5503 custom_stream->writer=writer;
5530static int SyncBlob(
const Image *image)
5533 *magick_restrict blob_info;
5538 assert(image != (
Image *) NULL);
5539 assert(image->signature == MagickCoreSignature);
5540 assert(image->blob != (
BlobInfo *) NULL);
5541 if (IsEventLogging() != MagickFalse)
5542 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5543 if (EOFBlob(image) != 0)
5545 blob_info=image->blob;
5547 switch (blob_info->type)
5549 case UndefinedStream:
5550 case StandardStream:
5555 status=fflush(blob_info->file_info.file);
5560#if defined(MAGICKCORE_ZLIB_DELEGATE)
5561 (void) gzflush(blob_info->file_info.gzfile,Z_SYNC_FLUSH);
5567#if defined(MAGICKCORE_BZLIB_DELEGATE)
5568 status=BZ2_bzflush(blob_info->file_info.bzfile);
5604MagickExport MagickOffsetType TellBlob(
const Image *image)
5607 *magick_restrict blob_info;
5612 assert(image != (
Image *) NULL);
5613 assert(image->signature == MagickCoreSignature);
5614 assert(image->blob != (
BlobInfo *) NULL);
5615 assert(image->blob->type != UndefinedStream);
5616 if (IsEventLogging() != MagickFalse)
5617 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
5618 blob_info=image->blob;
5620 switch (blob_info->type)
5622 case UndefinedStream:
5623 case StandardStream:
5627 offset=ftell(blob_info->file_info.file);
5634#if defined(MAGICKCORE_ZLIB_DELEGATE)
5635 offset=(MagickOffsetType) gztell(blob_info->file_info.gzfile);
5645 offset=blob_info->offset;
5650 if (blob_info->custom_stream->teller != (CustomStreamTeller) NULL)
5651 offset=blob_info->custom_stream->teller(blob_info->custom_stream->data);
5683MagickExport MagickBooleanType UnmapBlob(
void *map,
const size_t length)
5685#if defined(MAGICKCORE_HAVE_MMAP)
5689 status=munmap(map,length);
5690 return(status == -1 ? MagickFalse : MagickTrue);
5694 return(MagickFalse);
5726MagickExport ssize_t WriteBlob(
Image *image,
const size_t length,
5730 *magick_restrict blob_info;
5744 assert(image != (
Image *) NULL);
5745 assert(image->signature == MagickCoreSignature);
5746 assert(image->blob != (
BlobInfo *) NULL);
5747 assert(image->blob->type != UndefinedStream);
5750 assert(data != (
const void *) NULL);
5751 blob_info=image->blob;
5753 p=(
const unsigned char *) data;
5754 q=(
unsigned char *) data;
5755 switch (blob_info->type)
5757 case UndefinedStream:
5759 case StandardStream:
5767 count=(ssize_t) fwrite((
const char *) data,1,length,
5768 blob_info->file_info.file);
5773 c=putc((
int) *p++,blob_info->file_info.file);
5781 c=putc((
int) *p++,blob_info->file_info.file);
5789 c=putc((
int) *p++,blob_info->file_info.file);
5797 c=putc((
int) *p++,blob_info->file_info.file);
5806 if ((count != (ssize_t) length) &&
5807 (ferror(blob_info->file_info.file) != 0))
5808 ThrowBlobException(blob_info);
5813#if defined(MAGICKCORE_ZLIB_DELEGATE)
5824 for (i=0; i < length; i+=(size_t) count)
5826 count=(ssize_t) gzwrite(blob_info->file_info.gzfile,q+i,
5827 (
unsigned int) MagickMin(length-i,MagickMaxBufferExtent));
5840 c=gzputc(blob_info->file_info.gzfile,(
int) *p++);
5848 c=gzputc(blob_info->file_info.gzfile,(
int) *p++);
5856 c=gzputc(blob_info->file_info.gzfile,(
int) *p++);
5864 c=gzputc(blob_info->file_info.gzfile,(
int) *p++);
5874 (void) gzerror(blob_info->file_info.gzfile,&status);
5875 if ((count != (ssize_t) length) && (status != Z_OK))
5876 ThrowBlobException(blob_info);
5882#if defined(MAGICKCORE_BZLIB_DELEGATE)
5889 for (i=0; i < length; i+=(size_t) count)
5891 count=(ssize_t) BZ2_bzwrite(blob_info->file_info.bzfile,q+i,
5892 (
int) MagickMin(length-i,MagickMaxBufferExtent));
5902 (void) BZ2_bzerror(blob_info->file_info.bzfile,&status);
5903 if ((count != (ssize_t) length) && (status != BZ_OK))
5904 ThrowBlobException(blob_info);
5910 count=(ssize_t) blob_info->stream(image,data,length);
5915 if ((blob_info->offset+(MagickOffsetType) length) >=
5916 (MagickOffsetType) blob_info->extent)
5918 if (blob_info->mapped != MagickFalse)
5920 blob_info->extent+=length+blob_info->quantum;
5921 blob_info->quantum<<=1;
5922 blob_info->data=(
unsigned char *) ResizeQuantumMemory(
5923 blob_info->data,blob_info->extent+1,
sizeof(*blob_info->data));
5924 (void) SyncBlob(image);
5925 if (blob_info->data == (
unsigned char *) NULL)
5927 (void) DetachBlob(blob_info);
5931 q=blob_info->data+blob_info->offset;
5932 (void) memcpy(q,p,length);
5933 blob_info->offset+=(MagickOffsetType) length;
5934 if (blob_info->offset >= (MagickOffsetType) blob_info->length)
5935 blob_info->length=(size_t) blob_info->offset;
5936 count=(ssize_t) length;
5941 if (blob_info->custom_stream->writer != (CustomStreamHandler) NULL)
5942 count=blob_info->custom_stream->writer((
unsigned char *) data,
5943 length,blob_info->custom_stream->data);
5975MagickExport ssize_t WriteBlobByte(
Image *image,
const unsigned char value)
5978 *magick_restrict blob_info;
5983 assert(image != (
Image *) NULL);
5984 assert(image->signature == MagickCoreSignature);
5985 assert(image->blob != (
BlobInfo *) NULL);
5986 assert(image->blob->type != UndefinedStream);
5987 blob_info=image->blob;
5989 switch (blob_info->type)
5991 case StandardStream:
5998 c=putc((
int) value,blob_info->file_info.file);
6001 if (ferror(blob_info->file_info.file) != 0)
6002 ThrowBlobException(blob_info);
6010 count=WriteBlobStream(image,1,&value);
6042MagickExport ssize_t WriteBlobFloat(
Image *image,
const float value)
6053 quantum.unsigned_value=0U;
6054 quantum.float_value=value;
6055 return(WriteBlobLong(image,quantum.unsigned_value));
6083MagickExport ssize_t WriteBlobLong(
Image *image,
const unsigned int value)
6088 assert(image != (
Image *) NULL);
6089 assert(image->signature == MagickCoreSignature);
6090 if (image->endian == LSBEndian)
6092 buffer[0]=(
unsigned char) value;
6093 buffer[1]=(
unsigned char) (value >> 8);
6094 buffer[2]=(
unsigned char) (value >> 16);
6095 buffer[3]=(
unsigned char) (value >> 24);
6096 return(WriteBlobStream(image,4,buffer));
6098 buffer[0]=(
unsigned char) (value >> 24);
6099 buffer[1]=(
unsigned char) (value >> 16);
6100 buffer[2]=(
unsigned char) (value >> 8);
6101 buffer[3]=(
unsigned char) value;
6102 return(WriteBlobStream(image,4,buffer));
6130MagickExport ssize_t WriteBlobLongLong(
Image *image,
const MagickSizeType value)
6135 assert(image != (
Image *) NULL);
6136 assert(image->signature == MagickCoreSignature);
6137 if (image->endian == LSBEndian)
6139 buffer[0]=(
unsigned char) value;
6140 buffer[1]=(
unsigned char) (value >> 8);
6141 buffer[2]=(
unsigned char) (value >> 16);
6142 buffer[3]=(
unsigned char) (value >> 24);
6143 buffer[4]=(
unsigned char) (value >> 32);
6144 buffer[5]=(
unsigned char) (value >> 40);
6145 buffer[6]=(
unsigned char) (value >> 48);
6146 buffer[7]=(
unsigned char) (value >> 56);
6147 return(WriteBlobStream(image,8,buffer));
6149 buffer[0]=(
unsigned char) (value >> 56);
6150 buffer[1]=(
unsigned char) (value >> 48);
6151 buffer[2]=(
unsigned char) (value >> 40);
6152 buffer[3]=(
unsigned char) (value >> 32);
6153 buffer[4]=(
unsigned char) (value >> 24);
6154 buffer[5]=(
unsigned char) (value >> 16);
6155 buffer[6]=(
unsigned char) (value >> 8);
6156 buffer[7]=(
unsigned char) value;
6157 return(WriteBlobStream(image,8,buffer));
6185MagickExport ssize_t WriteBlobShort(
Image *image,
const unsigned short value)
6190 assert(image != (
Image *) NULL);
6191 assert(image->signature == MagickCoreSignature);
6192 if (image->endian == LSBEndian)
6194 buffer[0]=(
unsigned char) value;
6195 buffer[1]=(
unsigned char) (value >> 8);
6196 return(WriteBlobStream(image,2,buffer));
6198 buffer[0]=(
unsigned char) (value >> 8);
6199 buffer[1]=(
unsigned char) value;
6200 return(WriteBlobStream(image,2,buffer));
6228MagickExport ssize_t WriteBlobSignedLong(
Image *image,
const signed int value)
6242 assert(image != (
Image *) NULL);
6243 assert(image->signature == MagickCoreSignature);
6244 quantum.signed_value=value;
6245 if (image->endian == LSBEndian)
6247 buffer[0]=(
unsigned char) quantum.unsigned_value;
6248 buffer[1]=(
unsigned char) (quantum.unsigned_value >> 8);
6249 buffer[2]=(
unsigned char) (quantum.unsigned_value >> 16);
6250 buffer[3]=(
unsigned char) (quantum.unsigned_value >> 24);
6251 return(WriteBlobStream(image,4,buffer));
6253 buffer[0]=(
unsigned char) (quantum.unsigned_value >> 24);
6254 buffer[1]=(
unsigned char) (quantum.unsigned_value >> 16);
6255 buffer[2]=(
unsigned char) (quantum.unsigned_value >> 8);
6256 buffer[3]=(
unsigned char) quantum.unsigned_value;
6257 return(WriteBlobStream(image,4,buffer));
6285MagickExport ssize_t WriteBlobLSBLong(
Image *image,
const unsigned int value)
6290 assert(image != (
Image *) NULL);
6291 assert(image->signature == MagickCoreSignature);
6292 buffer[0]=(
unsigned char) value;
6293 buffer[1]=(
unsigned char) (value >> 8);
6294 buffer[2]=(
unsigned char) (value >> 16);
6295 buffer[3]=(
unsigned char) (value >> 24);
6296 return(WriteBlobStream(image,4,buffer));
6324MagickExport ssize_t WriteBlobLSBShort(
Image *image,
const unsigned short value)
6329 assert(image != (
Image *) NULL);
6330 assert(image->signature == MagickCoreSignature);
6331 buffer[0]=(
unsigned char) value;
6332 buffer[1]=(
unsigned char) (value >> 8);
6333 return(WriteBlobStream(image,2,buffer));
6361MagickExport ssize_t WriteBlobLSBSignedLong(
Image *image,
const signed int value)
6375 assert(image != (
Image *) NULL);
6376 assert(image->signature == MagickCoreSignature);
6377 quantum.signed_value=value;
6378 buffer[0]=(
unsigned char) quantum.unsigned_value;
6379 buffer[1]=(
unsigned char) (quantum.unsigned_value >> 8);
6380 buffer[2]=(
unsigned char) (quantum.unsigned_value >> 16);
6381 buffer[3]=(
unsigned char) (quantum.unsigned_value >> 24);
6382 return(WriteBlobStream(image,4,buffer));
6410MagickExport ssize_t WriteBlobLSBSignedShort(
Image *image,
6411 const signed short value)
6425 assert(image != (
Image *) NULL);
6426 assert(image->signature == MagickCoreSignature);
6427 quantum.signed_value=value;
6428 buffer[0]=(
unsigned char) quantum.unsigned_value;
6429 buffer[1]=(
unsigned char) (quantum.unsigned_value >> 8);
6430 return(WriteBlobStream(image,2,buffer));
6458MagickExport ssize_t WriteBlobMSBLong(
Image *image,
const unsigned int value)
6463 assert(image != (
Image *) NULL);
6464 assert(image->signature == MagickCoreSignature);
6465 buffer[0]=(
unsigned char) (value >> 24);
6466 buffer[1]=(
unsigned char) (value >> 16);
6467 buffer[2]=(
unsigned char) (value >> 8);
6468 buffer[3]=(
unsigned char) value;
6469 return(WriteBlobStream(image,4,buffer));
6497MagickExport ssize_t WriteBlobMSBSignedShort(
Image *image,
6498 const signed short value)
6512 assert(image != (
Image *) NULL);
6513 assert(image->signature == MagickCoreSignature);
6514 quantum.signed_value=value;
6515 buffer[0]=(
unsigned char) (quantum.unsigned_value >> 8);
6516 buffer[1]=(
unsigned char) quantum.unsigned_value;
6517 return(WriteBlobStream(image,2,buffer));
6545MagickExport ssize_t WriteBlobMSBShort(
Image *image,
const unsigned short value)
6550 assert(image != (
Image *) NULL);
6551 assert(image->signature == MagickCoreSignature);
6552 buffer[0]=(
unsigned char) (value >> 8);
6553 buffer[1]=(
unsigned char) value;
6554 return(WriteBlobStream(image,2,buffer));
6582MagickExport ssize_t WriteBlobString(
Image *image,
const char *
string)
6584 assert(image != (
Image *) NULL);
6585 assert(image->signature == MagickCoreSignature);
6586 assert(
string != (
const char *) NULL);
6587 return(WriteBlobStream(image,strlen(
string),(
const unsigned char *)
string));