% July 1999 %
% %
% %
-% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
/*
Include declarations.
*/
+#ifdef __VMS
+#include <types.h>
+#include <mman.h>
+#endif
#include "MagickCore/studio.h"
#include "MagickCore/blob.h"
#include "MagickCore/blob-private.h"
#include "MagickCore/magick.h"
#include "MagickCore/memory_.h"
#include "MagickCore/nt-base-private.h"
+#include "MagickCore/option.h"
#include "MagickCore/policy.h"
#include "MagickCore/resource_.h"
#include "MagickCore/semaphore.h"
StreamHandler
stream;
+ CustomStreamInfo
+ *custom_stream;
+
unsigned char
*data;
size_t
signature;
};
+
+struct _CustomStreamInfo
+{
+ CustomStreamHandler
+ reader,
+ writer;
+
+ CustomStreamSeeker
+ seeker;
+
+ CustomStreamTeller
+ teller;
+
+ void
+ *data;
+
+ size_t
+ signature;
+};
\f
/*
Forward declarations.
% %
% %
% %
++ A c q u i r e C u s t o m S t r e a m I n f o %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% AcquireCustomStreamInfo() allocates the CustomStreamInfo structure.
+%
+% The format of the AcquireCustomStreamInfo method is:
+%
+% CustomStreamInfo *AcquireCustomStreamInfo(ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport CustomStreamInfo *AcquireCustomStreamInfo(
+ ExceptionInfo *magick_unused(exception))
+{
+ CustomStreamInfo
+ *custom_stream;
+
+ magick_unreferenced(exception);
+ custom_stream=(CustomStreamInfo *) AcquireMagickMemory(
+ sizeof(*custom_stream));
+ if (custom_stream == (CustomStreamInfo *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ (void) ResetMagickMemory(custom_stream,0,sizeof(*custom_stream));
+ custom_stream->signature=MagickCoreSignature;
+ return(custom_stream);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ A t t a c h B l o b %
% %
% %
}
for (i=0; i < length; i+=count)
{
- count=write(file,(const char *) blob+i,MagickMin(length-i,(size_t)
- SSIZE_MAX));
+ count=write(file,(const char *) blob+i,MagickMin(length-i,SSIZE_MAX));
if (count <= 0)
{
count=0;
status;
assert(image_info != (ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
Native blob support for this image format.
*/
(void) CopyMagickString(blob_info->filename,image_info->filename,
- MaxTextExtent);
+ MagickPathExtent);
(void) CopyMagickString(blob_info->magick,image_info->magick,
- MaxTextExtent);
+ MagickPathExtent);
image=ReadImage(blob_info,exception);
if (image != (Image *) NULL)
(void) DetachBlob(image->blob);
return((Image *) NULL);
}
clone_info=CloneImageInfo(blob_info);
- (void) FormatLocaleString(clone_info->filename,MaxTextExtent,"%s:%s",
+ (void) FormatLocaleString(clone_info->filename,MagickPathExtent,"%s:%s",
blob_info->magick,blob_info->filename);
image=ReadImage(clone_info,exception);
if (image != (Image *) NULL)
for (images=GetFirstImageInList(image); images != (Image *) NULL; )
{
(void) CopyMagickString(images->filename,image_info->filename,
- MaxTextExtent);
+ MagickPathExtent);
(void) CopyMagickString(images->magick_filename,image_info->filename,
- MaxTextExtent);
+ MagickPathExtent);
(void) CopyMagickString(images->magick,magick_info->name,
- MaxTextExtent);
+ MagickPathExtent);
images=GetNextImageInList(images);
}
}
clone_info->file_info.file=blob_info->file_info.file;
clone_info->properties=blob_info->properties;
clone_info->stream=blob_info->stream;
+ clone_info->custom_stream=blob_info->custom_stream;
clone_info->data=blob_info->data;
clone_info->debug=IsEventLogging();
clone_info->reference_count=1;
Close image file.
*/
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
}
break;
}
+ case CustomStream:
+ break;
}
image->blob->status=status < 0 ? MagickTrue : MagickFalse;
image->blob->size=GetBlobSize(image);
status=fclose(image->blob->file_info.file);
break;
}
+ case CustomStream:
+ break;
}
(void) DetachBlob(image->blob);
image->blob->status=status < 0 ? MagickTrue : MagickFalse;
destroy;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
- assert(image->blob->signature == MagickSignature);
+ assert(image->blob->signature == MagickCoreSignature);
destroy=MagickFalse;
LockSemaphoreInfo(image->blob->semaphore);
image->blob->reference_count--;
}
if (image->blob->semaphore != (SemaphoreInfo *) NULL)
RelinquishSemaphoreInfo(&image->blob->semaphore);
- image->blob->signature=(~MagickSignature);
+ image->blob->signature=(~MagickCoreSignature);
image->blob=(BlobInfo *) RelinquishMagickMemory(image->blob);
}
\f
% %
% %
% %
++ D e s t r o y C u s t o m S t r e a m I n f o %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DestroyCustomStreamInfo() destroys memory associated with the
+% CustomStreamInfo structure.
+%
+% The format of the DestroyCustomStreamInfo method is:
+%
+% CustomStreamInfo *DestroyCustomStreamInfo(CustomStreamInfo *stream_info)
+%
+% A description of each parameter follows:
+%
+% o custom_stream: the custom stream info.
+%
+*/
+MagickExport CustomStreamInfo *DestroyCustomStreamInfo(
+ CustomStreamInfo *custom_stream)
+{
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->signature == MagickCoreSignature);
+ custom_stream->signature=(~MagickCoreSignature);
+ custom_stream=(CustomStreamInfo *) RelinquishMagickMemory(custom_stream);
+ return(custom_stream);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ D e t a c h B l o b %
% %
% %
data=blob_info->data;
blob_info->data=(unsigned char *) NULL;
blob_info->stream=(StreamHandler) NULL;
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
return(data);
}
\f
% o image: the image.
%
*/
-MagickPrivate void DisassociateBlob(Image *image)
+MagickExport void DisassociateBlob(Image *image)
{
BlobInfo
*blob;
clone;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
- assert(image->blob->signature == MagickSignature);
+ assert(image->blob->signature == MagickCoreSignature);
clone=MagickFalse;
LockSemaphoreInfo(image->blob->semaphore);
assert(image->blob->reference_count >= 0);
buffer[16384];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
+ if (length != (MagickSizeType) ((MagickOffsetType) length))
+ return(MagickFalse);
count=0;
for (i=0; i < (MagickOffsetType) length; i+=count)
{
MagickExport void DuplicateBlob(Image *image,const Image *duplicate)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(duplicate != (Image *) NULL);
- assert(duplicate->signature == MagickSignature);
+ assert(duplicate->signature == MagickCoreSignature);
DestroyBlob(image);
image->blob=ReferenceBlob(duplicate->blob);
}
MagickExport int EOFBlob(const Image *image)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
assert(image->blob != (BlobInfo *) NULL);
}
case BlobStream:
break;
+ case CustomStream:
+ break;
}
return((int) image->blob->eof);
}
% %
% %
% %
-+ F i l e T o B l o b %
+% F i l e T o B l o b %
% %
% %
% %
*/
offset=(MagickOffsetType) lseek(file,0,SEEK_SET);
quantum=(size_t) MagickMaxBufferExtent;
- if ((fstat(file,&file_stats) == 0) && (file_stats.st_size != 0))
- quantum=(size_t) MagickMin((MagickSizeType) file_stats.st_size,
- MagickMaxBufferExtent);
+ if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
+ quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
blob=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*blob));
for (i=0; blob != (unsigned char *) NULL; i+=count)
{
blob[*length]='\0';
return(blob);
}
- *length=(size_t) MagickMin((MagickSizeType) offset,extent);
+ *length=(size_t) MagickMin(offset,(MagickOffsetType)
+ MagickMin(extent,SSIZE_MAX));
blob=(unsigned char *) NULL;
- if (~(*length) >= (MaxTextExtent-1))
- blob=(unsigned char *) AcquireQuantumMemory(*length+MaxTextExtent,
+ if (~(*length) >= (MagickPathExtent-1))
+ blob=(unsigned char *) AcquireQuantumMemory(*length+MagickPathExtent,
sizeof(*blob));
if (blob == (unsigned char *) NULL)
{
(void) lseek(file,0,SEEK_SET);
for (i=0; i < *length; i+=count)
{
- count=read(file,blob+i,(size_t) MagickMin(*length-i,(size_t)
- SSIZE_MAX));
+ count=read(file,blob+i,(size_t) MagickMin(*length-i,SSIZE_MAX));
if (count <= 0)
{
count=0;
assert(image->blob->type != UndefinedStream);
assert(data != NULL);
if (image->blob->type != BlobStream)
- return(WriteBlob(image,length,data));
+ return(WriteBlob(image,length,(const unsigned char *) data));
extent=(MagickSizeType) (image->blob->offset+(MagickOffsetType) length);
if (extent >= image->blob->extent)
{
*blob;
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
assert(filename != (const char *) NULL);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
file=fileno(stdin);
return(MagickFalse);
}
quantum=(size_t) MagickMaxBufferExtent;
- if ((fstat(file,&file_stats) == 0) && (file_stats.st_size != 0))
+ if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
blob=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*blob));
if (blob == (unsigned char *) NULL)
blob=(unsigned char *) RelinquishMagickMemory(blob);
return(MagickTrue);
}
-
-
+\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% o image: the image.
%
*/
-MagickPrivate MagickBooleanType GetBlobError(const Image *image)
+MagickExport MagickBooleanType GetBlobError(const Image *image)
{
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
return(image->blob->status);
MagickExport FILE *GetBlobFileHandle(const Image *image)
{
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
return(image->blob->file_info.file);
}
\f
% o blob_info: Specifies a pointer to a BlobInfo structure.
%
*/
-MagickPrivate void GetBlobInfo(BlobInfo *blob_info)
+MagickExport void GetBlobInfo(BlobInfo *blob_info)
{
assert(blob_info != (BlobInfo *) NULL);
(void) ResetMagickMemory(blob_info,0,sizeof(*blob_info));
blob_info->debug=IsEventLogging();
blob_info->reference_count=1;
blob_info->semaphore=AcquireSemaphoreInfo();
- blob_info->signature=MagickSignature;
+ blob_info->signature=MagickCoreSignature;
}
\f
/*
% o image: the image.
%
*/
-MagickPrivate const struct stat *GetBlobProperties(const Image *image)
+MagickExport const struct stat *GetBlobProperties(const Image *image)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
return(&image->blob->properties);
extent;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
switch (image->blob->type)
{
case UndefinedStream:
- {
- extent=image->blob->size;
- break;
- }
case StandardStream:
{
extent=image->blob->size;
extent=(MagickSizeType) image->blob->length;
break;
}
+ case CustomStream:
+ {
+ if ((image->blob->custom_stream->teller != (CustomStreamTeller) NULL) &&
+ (image->blob->custom_stream->seeker != (CustomStreamSeeker) NULL))
+ {
+ MagickOffsetType
+ offset;
+
+ offset=image->blob->custom_stream->teller(
+ image->blob->custom_stream->data);
+ extent=image->blob->custom_stream->seeker(0,SEEK_END,
+ image->blob->custom_stream->data);
+ image->blob->custom_stream->seeker(offset,SEEK_SET,
+ image->blob->custom_stream->data);
+ }
+ break;
+ }
}
return(extent);
}
MagickExport void *GetBlobStreamData(const Image *image)
{
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
return(image->blob->data);
}
\f
% o image: the image.
%
*/
-MagickPrivate StreamHandler GetBlobStreamHandler(const Image *image)
+MagickExport StreamHandler GetBlobStreamHandler(const Image *image)
{
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
return(image->blob->stream);
MagickBooleanType
status;
- unsigned char
+ void
*blob;
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
assert(exception != (ExceptionInfo *) NULL);
*length=0;
blob=(unsigned char *) NULL;
blob_info->adjoin=MagickFalse;
(void) SetImageInfo(blob_info,1,exception);
if (*blob_info->magick != '\0')
- (void) CopyMagickString(image->magick,blob_info->magick,MaxTextExtent);
+ (void) CopyMagickString(image->magick,blob_info->magick,MagickPathExtent);
magick_info=GetMagickInfo(image->magick,exception);
if (magick_info == (const MagickInfo *) NULL)
{
blob_info=DestroyImageInfo(blob_info);
return(blob);
}
- (void) CopyMagickString(blob_info->magick,image->magick,MaxTextExtent);
+ (void) CopyMagickString(blob_info->magick,image->magick,MagickPathExtent);
if (GetMagickBlobSupport(magick_info) != MagickFalse)
{
/*
*length=image->blob->length;
blob=DetachBlob(image->blob);
if (status == MagickFalse)
- blob=(unsigned char *) RelinquishMagickMemory(blob);
+ blob=RelinquishMagickMemory(blob);
else
- blob=(unsigned char *) ResizeQuantumMemory(blob,*length+1,
- sizeof(*blob));
+ blob=ResizeQuantumMemory(blob,*length+1,sizeof(unsigned char));
}
}
else
{
char
- unique[MaxTextExtent];
+ unique[MagickPathExtent];
int
file;
blob_info->file=fdopen(file,"wb");
if (blob_info->file != (FILE *) NULL)
{
- (void) FormatLocaleString(image->filename,MaxTextExtent,"%s:%s",
- image->magick,unique);
+ (void) FormatLocaleString(image->filename,MagickPathExtent,
+ "%s:%s",image->magick,unique);
status=WriteImage(blob_info,image,exception);
(void) CloseBlob(image);
(void) fclose(blob_info->file);
% %
% %
% %
++ I m a g e T o C u s t o m S t r e a m %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ImageToCustomStream() is the equivalent of WriteImage(), but writes the
+% formatted "file" to the custom stream rather than to an actual file.
+%
+% The format of the ImageToCustomStream method is:
+%
+% void ImageToCustomStream(const ImageInfo *image_info,Image *image,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image_info: the image info.
+%
+% o image: the image.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport void ImageToCustomStream(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
+{
+ const MagickInfo
+ *magick_info;
+
+ ImageInfo
+ *blob_info;
+
+ MagickBooleanType
+ status;
+
+ assert(image_info != (const ImageInfo *) NULL);
+ assert(image_info->signature == MagickCoreSignature);
+ if (image_info->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
+ image_info->filename);
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ assert(image_info->custom_stream != (CustomStreamInfo *) NULL);
+ assert(image_info->custom_stream->signature == MagickCoreSignature);
+ assert(image_info->custom_stream->writer != (CustomStreamHandler) NULL);
+ assert(exception != (ExceptionInfo *) NULL);
+ blob_info=CloneImageInfo(image_info);
+ blob_info->adjoin=MagickFalse;
+ (void) SetImageInfo(blob_info,1,exception);
+ if (*blob_info->magick != '\0')
+ (void) CopyMagickString(image->magick,blob_info->magick,MagickPathExtent);
+ magick_info=GetMagickInfo(image->magick,exception);
+ if (magick_info == (const MagickInfo *) NULL)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'",
+ image->magick);
+ blob_info=DestroyImageInfo(blob_info);
+ return;
+ }
+ (void) CopyMagickString(blob_info->magick,image->magick,MagickPathExtent);
+ if (GetMagickBlobSupport(magick_info) != MagickFalse)
+ {
+ /*
+ Native blob support for this image format.
+ */
+ (void) CloseBlob(image);
+ *image->filename='\0';
+ (void) WriteImage(blob_info,image,exception);
+ (void) CloseBlob(image);
+ }
+ else
+ {
+ char
+ unique[MagickPathExtent];
+
+ int
+ file;
+
+ unsigned char
+ *blob;
+
+ /*
+ Write file to disk in blob image format.
+ */
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
+ blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
+ sizeof(*blob));
+ if (blob == (unsigned char *) NULL)
+ {
+ ThrowFileException(exception,BlobError,"UnableToWriteBlob",
+ image_info->filename);
+ blob_info=DestroyImageInfo(blob_info);
+ return;
+ }
+ file=AcquireUniqueFileResource(unique);
+ if (file == -1)
+ {
+ ThrowFileException(exception,BlobError,"UnableToWriteBlob",
+ image_info->filename);
+ blob=(unsigned char *) RelinquishMagickMemory(blob);
+ blob_info=DestroyImageInfo(blob_info);
+ return;
+ }
+ blob_info->file=fdopen(file,"wb+");
+ if (blob_info->file != (FILE *) NULL)
+ {
+ ssize_t
+ count;
+
+ (void) FormatLocaleString(image->filename,MagickPathExtent,
+ "%s:%s",image->magick,unique);
+ status=WriteImage(blob_info,image,exception);
+ (void) CloseBlob(image);
+ if (status != MagickFalse)
+ {
+ (void) fseek(blob_info->file,0,SEEK_SET);
+ count=(ssize_t) MagickMaxBufferExtent;
+ while (count == (ssize_t) MagickMaxBufferExtent)
+ {
+ count=(ssize_t) fread(blob,sizeof(*blob),MagickMaxBufferExtent,
+ blob_info->file);
+ image_info->custom_stream->writer(blob,count,
+ image_info->custom_stream->data);
+ }
+ }
+ (void) fclose(blob_info->file);
+ }
+ blob=(unsigned char *) RelinquishMagickMemory(blob);
+ (void) RelinquishUniqueFileResource(unique);
+ }
+ blob_info=DestroyImageInfo(blob_info);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% I m a g e T o F i l e %
% %
% %
*buffer;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
assert(image->blob != (BlobInfo *) NULL);
assert(image->blob->type != UndefinedStream);
if (image->debug != MagickFalse)
return(MagickFalse);
}
quantum=(size_t) MagickMaxBufferExtent;
- if ((fstat(file,&file_stats) == 0) && (file_stats.st_size != 0))
- quantum=(size_t) MagickMin((MagickSizeType) file_stats.st_size,
- MagickMaxBufferExtent);
+ if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
+ quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
{
return(MagickFalse);
}
length=0;
- p=ReadBlobStream(image,quantum,buffer,&count);
- for (i=0; count > 0; p=ReadBlobStream(image,quantum,buffer,&count))
+ p=(const unsigned char *) ReadBlobStream(image,quantum,buffer,&count);
+ for (i=0; count > 0; )
{
length=(size_t) count;
for (i=0; i < length; i+=count)
}
if (i < length)
break;
+ p=(const unsigned char *) ReadBlobStream(image,quantum,buffer,&count);
}
if (LocaleCompare(filename,"-") != 0)
file=close(file);
MagickBooleanType
status;
- unsigned char
+ void
*blob;
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(images != (Image *) NULL);
- assert(images->signature == MagickSignature);
+ assert(images->signature == MagickCoreSignature);
assert(exception != (ExceptionInfo *) NULL);
*length=0;
blob=(unsigned char *) NULL;
(void) SetImageInfo(blob_info,(unsigned int) GetImageListLength(images),
exception);
if (*blob_info->magick != '\0')
- (void) CopyMagickString(images->magick,blob_info->magick,MaxTextExtent);
+ (void) CopyMagickString(images->magick,blob_info->magick,MagickPathExtent);
magick_info=GetMagickInfo(images->magick,exception);
if (magick_info == (const MagickInfo *) NULL)
{
blob_info=DestroyImageInfo(blob_info);
return(ImageToBlob(image_info,images,length,exception));
}
- (void) CopyMagickString(blob_info->magick,images->magick,MaxTextExtent);
+ (void) CopyMagickString(blob_info->magick,images->magick,MagickPathExtent);
if (GetMagickBlobSupport(magick_info) != MagickFalse)
{
/*
*length=images->blob->length;
blob=DetachBlob(images->blob);
if (status == MagickFalse)
- blob=(unsigned char *) RelinquishMagickMemory(blob);
+ blob=RelinquishMagickMemory(blob);
else
- blob=(unsigned char *) ResizeQuantumMemory(blob,*length+1,
- sizeof(*blob));
+ blob=ResizeQuantumMemory(blob,*length+1,sizeof(unsigned char));
}
}
else
{
char
- filename[MaxTextExtent],
- unique[MaxTextExtent];
+ filename[MagickPathExtent],
+ unique[MagickPathExtent];
int
file;
blob_info->file=fdopen(file,"wb");
if (blob_info->file != (FILE *) NULL)
{
- (void) FormatLocaleString(filename,MaxTextExtent,"%s:%s",
+ (void) FormatLocaleString(filename,MagickPathExtent,"%s:%s",
images->magick,unique);
status=WriteImages(blob_info,images,filename,exception);
(void) CloseBlob(images);
blob_info=DestroyImageInfo(blob_info);
return(blob);
}
+\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
-% I n j e c t I m a g e B l o b %
++ I m a g e s T o C u s t o m B l o b %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% InjectImageBlob() injects the image with a copy of itself in the specified
-% format (e.g. inject JPEG into a PDF image).
+% ImagesToCustomStream() is the equivalent of WriteImages(), but writes the
+% formatted "file" to the custom stream rather than to an actual file.
%
-% The format of the InjectImageBlob method is:
+% The format of the ImageToCustomStream method is:
%
-% MagickBooleanType InjectImageBlob(const ImageInfo *image_info,
-% Image *image,Image *inject_image,const char *format,
+% void ImagesToCustomStream(const ImageInfo *image_info,Image *images,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
-% o image_info: the image info..
-%
-% o image: the image.
-%
-% o inject_image: inject into the image stream.
+% o image_info: the image info.
%
-% o format: the image format.
+% o images: the image list.
%
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport MagickBooleanType InjectImageBlob(const ImageInfo *image_info,
- Image *image,Image *inject_image,const char *format,ExceptionInfo *exception)
+MagickExport void ImagesToCustomStream(const ImageInfo *image_info,
+ Image *images,ExceptionInfo *exception)
{
- char
- filename[MaxTextExtent];
-
- FILE
- *unique_file;
-
- Image
- *byte_image;
+ const MagickInfo
+ *magick_info;
ImageInfo
- *write_info;
-
- int
- file;
+ *blob_info;
MagickBooleanType
status;
- register ssize_t
- i;
-
- size_t
- quantum;
-
- ssize_t
- count;
-
- struct stat
- file_stats;
-
- unsigned char
- *buffer;
-
- /*
- Write inject image to a temporary file.
- */
- assert(image_info != (ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
- assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- assert(inject_image != (Image *) NULL);
- assert(inject_image->signature == MagickSignature);
+ assert(image_info != (const ImageInfo *) NULL);
+ assert(image_info->signature == MagickCoreSignature);
+ if (image_info->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
+ image_info->filename);
+ assert(images != (Image *) NULL);
+ assert(images->signature == MagickCoreSignature);
+ assert(image_info->custom_stream != (CustomStreamInfo *) NULL);
+ assert(image_info->custom_stream->signature == MagickCoreSignature);
+ assert(image_info->custom_stream->reader != (CustomStreamHandler) NULL);
+ assert(image_info->custom_stream->writer != (CustomStreamHandler) NULL);
assert(exception != (ExceptionInfo *) NULL);
- unique_file=(FILE *) NULL;
- file=AcquireUniqueFileResource(filename);
- if (file != -1)
- unique_file=fdopen(file,"wb");
- if ((file == -1) || (unique_file == (FILE *) NULL))
+ blob_info=CloneImageInfo(image_info);
+ (void) SetImageInfo(blob_info,(unsigned int) GetImageListLength(images),
+ exception);
+ if (*blob_info->magick != '\0')
+ (void) CopyMagickString(images->magick,blob_info->magick,MagickPathExtent);
+ magick_info=GetMagickInfo(images->magick,exception);
+ if (magick_info == (const MagickInfo *) NULL)
{
- (void) CopyMagickString(image->filename,filename,MaxTextExtent);
- ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
- image->filename);
- return(MagickFalse);
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'",
+ images->magick);
+ blob_info=DestroyImageInfo(blob_info);
+ return;
}
- byte_image=CloneImage(inject_image,0,0,MagickFalse,exception);
- if (byte_image == (Image *) NULL)
+ (void) CopyMagickString(blob_info->magick,images->magick,MagickPathExtent);
+ if (GetMagickBlobSupport(magick_info) != MagickFalse)
+ {
+ /*
+ Native blob support for this image format.
+ */
+ (void) CloseBlob(images);
+ *images->filename='\0';
+ (void) WriteImages(blob_info,images,images->filename,exception);
+ (void) CloseBlob(images);
+ }
+ else
+ {
+ char
+ filename[MagickPathExtent],
+ unique[MagickPathExtent];
+
+ int
+ file;
+
+ unsigned char
+ *blob;
+
+ /*
+ Write file to disk in blob image format.
+ */
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
+ blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
+ sizeof(*blob));
+ if (blob == (unsigned char *) NULL)
+ {
+ ThrowFileException(exception,BlobError,"UnableToWriteBlob",
+ image_info->filename);
+ blob_info=DestroyImageInfo(blob_info);
+ return;
+ }
+ file=AcquireUniqueFileResource(unique);
+ if (file == -1)
+ {
+ ThrowFileException(exception,BlobError,"UnableToWriteBlob",
+ image_info->filename);
+ blob=(unsigned char *) RelinquishMagickMemory(blob);
+ blob_info=DestroyImageInfo(blob_info);
+ return;
+ }
+ blob_info->file=fdopen(file,"wb+");
+ if (blob_info->file != (FILE *) NULL)
+ {
+ ssize_t
+ count;
+
+ (void) FormatLocaleString(filename,MagickPathExtent,"%s:%s",
+ images->magick,unique);
+ status=WriteImages(blob_info,images,filename,exception);
+ (void) CloseBlob(images);
+ if (status != MagickFalse)
+ {
+ (void) fseek(blob_info->file,0,SEEK_SET);
+ count=(ssize_t) MagickMaxBufferExtent;
+ while (count == (ssize_t) MagickMaxBufferExtent)
+ {
+ count=(ssize_t) fread(blob,sizeof(*blob),MagickMaxBufferExtent,
+ blob_info->file);
+ image_info->custom_stream->writer(blob,count,
+ image_info->custom_stream->data);
+ }
+ }
+ (void) fclose(blob_info->file);
+ }
+ blob=(unsigned char *) RelinquishMagickMemory(blob);
+ (void) RelinquishUniqueFileResource(unique);
+ }
+ blob_info=DestroyImageInfo(blob_info);
+ return;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% I n j e c t I m a g e B l o b %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% InjectImageBlob() injects the image with a copy of itself in the specified
+% format (e.g. inject JPEG into a PDF image).
+%
+% The format of the InjectImageBlob method is:
+%
+% MagickBooleanType InjectImageBlob(const ImageInfo *image_info,
+% Image *image,Image *inject_image,const char *format,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image_info: the image info..
+%
+% o image: the image.
+%
+% o inject_image: inject into the image stream.
+%
+% o format: the image format.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport MagickBooleanType InjectImageBlob(const ImageInfo *image_info,
+ Image *image,Image *inject_image,const char *format,ExceptionInfo *exception)
+{
+ char
+ filename[MagickPathExtent];
+
+ FILE
+ *unique_file;
+
+ Image
+ *byte_image;
+
+ ImageInfo
+ *write_info;
+
+ int
+ file;
+
+ MagickBooleanType
+ status;
+
+ register ssize_t
+ i;
+
+ size_t
+ quantum;
+
+ ssize_t
+ count;
+
+ struct stat
+ file_stats;
+
+ unsigned char
+ *buffer;
+
+ /*
+ Write inject image to a temporary file.
+ */
+ assert(image_info != (ImageInfo *) NULL);
+ assert(image_info->signature == MagickCoreSignature);
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ if (image->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ assert(inject_image != (Image *) NULL);
+ assert(inject_image->signature == MagickCoreSignature);
+ assert(exception != (ExceptionInfo *) NULL);
+ unique_file=(FILE *) NULL;
+ file=AcquireUniqueFileResource(filename);
+ if (file != -1)
+ unique_file=fdopen(file,"wb");
+ if ((file == -1) || (unique_file == (FILE *) NULL))
+ {
+ (void) CopyMagickString(image->filename,filename,MagickPathExtent);
+ ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
+ image->filename);
+ return(MagickFalse);
+ }
+ byte_image=CloneImage(inject_image,0,0,MagickFalse,exception);
+ if (byte_image == (Image *) NULL)
{
(void) fclose(unique_file);
(void) RelinquishUniqueFileResource(filename);
return(MagickFalse);
}
- (void) FormatLocaleString(byte_image->filename,MaxTextExtent,"%s:%s",format,
- filename);
+ (void) FormatLocaleString(byte_image->filename,MagickPathExtent,"%s:%s",
+ format,filename);
DestroyBlob(byte_image);
byte_image->blob=CloneBlobInfo((BlobInfo *) NULL);
write_info=CloneImageInfo(image_info);
return(MagickFalse);
}
quantum=(size_t) MagickMaxBufferExtent;
- if ((fstat(file,&file_stats) == 0) && (file_stats.st_size != 0))
+ if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
% %
% %
% %
-+ I s B l o b E x e m p t %
+% I s B l o b E x e m p t %
% %
% %
% %
% o image: the image.
%
*/
-MagickPrivate MagickBooleanType IsBlobExempt(const Image *image)
+MagickExport MagickBooleanType IsBlobExempt(const Image *image)
{
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
return(image->blob->exempt);
% %
% %
% %
-+ I s B l o b S e e k a b l e %
+% I s B l o b S e e k a b l e %
% %
% %
% %
% o image: the image.
%
*/
-MagickPrivate MagickBooleanType IsBlobSeekable(const Image *image)
+MagickExport MagickBooleanType IsBlobSeekable(const Image *image)
{
MagickBooleanType
seekable;
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
switch (image->blob->type)
seekable=MagickTrue;
break;
}
+ case UndefinedStream:
+ case StandardStream:
+ case BZipStream:
+ case FifoStream:
+ case PipeStream:
default:
{
seekable=MagickFalse;
break;
}
+ case CustomStream:
+ {
+ if ((image->blob->custom_stream->seeker != (CustomStreamSeeker) NULL) &&
+ (image->blob->custom_stream->teller != (CustomStreamTeller) NULL))
+ seekable=MagickTrue;
+ else
+ seekable=MagickFalse;
+ break;
+ }
}
return(seekable);
}
% %
% %
% %
-+ I s B l o b T e m p o r a r y %
+% I s B l o b T e m p o r a r y %
% %
% %
% %
% o image: the image.
%
*/
-MagickPrivate MagickBooleanType IsBlobTemporary(const Image *image)
+MagickExport MagickBooleanType IsBlobTemporary(const Image *image)
{
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
return(image->blob->temporary);
% o mode: the mode for opening the file.
%
*/
+
+static inline MagickBooleanType SetStreamBuffering(const ImageInfo *image_info,
+ Image *image)
+{
+ const char
+ *option;
+
+ int
+ status;
+
+ size_t
+ size;
+
+ size=16384;
+ option=GetImageOption(image_info,"stream:buffer-size");
+ if (option != (const char *) NULL)
+ size=StringToUnsignedLong(option);
+ status=setvbuf(image->blob->file_info.file,(char *) NULL,size == 0 ?
+ _IONBF : _IOFBF,size);
+ return(status == 0 ? MagickTrue : MagickFalse);
+}
+
MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info,
Image *image,const BlobMode mode,ExceptionInfo *exception)
{
char
- extension[MaxTextExtent],
- filename[MaxTextExtent];
+ extension[MagickPathExtent],
+ filename[MagickPathExtent];
const char
*type;
rights;
assert(image_info != (ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image_info->blob != (void *) NULL)
{
if (image_info->stream != (StreamHandler) NULL)
AttachBlob(image->blob,image_info->blob,image_info->length);
return(MagickTrue);
}
+ if ((image_info->custom_stream != (CustomStreamInfo *) NULL) &&
+ (*image->filename == '\0'))
+ {
+ image->blob->type=CustomStream;
+ image->blob->custom_stream=image_info->custom_stream;
+ return(MagickTrue);
+ }
(void) DetachBlob(image->blob);
switch (mode)
{
image->blob->synchronize=image_info->synchronize;
if (image_info->stream != (StreamHandler) NULL)
{
- image->blob->stream=(StreamHandler) image_info->stream;
+ image->blob->stream=image_info->stream;
if (*type == 'w')
{
image->blob->type=FifoStream;
Open image file.
*/
*filename='\0';
- (void) CopyMagickString(filename,image->filename,MaxTextExtent);
+ (void) CopyMagickString(filename,image->filename,MagickPathExtent);
rights=ReadPolicyRights;
if (*type == 'w')
rights=WritePolicyRights;
image->blob->file_info.file=(*type == 'r') ? stdin : stdout;
#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__)
if (strchr(type,'b') != (char *) NULL)
- setmode(_fileno(image->blob->file_info.file),_O_BINARY);
+ setmode(fileno(image->blob->file_info.file),_O_BINARY);
#endif
image->blob->type=StandardStream;
image->blob->exempt=MagickTrue;
- return(MagickTrue);
+ return(SetStreamBuffering(image_info,image));
}
if (LocaleNCompare(filename,"fd:",3) == 0)
{
char
- mode[MaxTextExtent];
+ fileMode[MagickPathExtent];
- *mode=(*type);
- mode[1]='\0';
- image->blob->file_info.file=fdopen(StringToLong(filename+3),mode);
+ *fileMode =(*type);
+ fileMode[1]='\0';
+ image->blob->file_info.file=fdopen(StringToLong(filename+3),fileMode);
#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__)
if (strchr(type,'b') != (char *) NULL)
- setmode(_fileno(image->blob->file_info.file),_O_BINARY);
+ setmode(fileno(image->blob->file_info.file),_O_BINARY);
#endif
image->blob->type=StandardStream;
image->blob->exempt=MagickTrue;
- return(MagickTrue);
+ return(SetStreamBuffering(image_info,image));
}
-#if defined(MAGICKCORE_HAVE_POPEN)
+#if defined(MAGICKCORE_HAVE_POPEN) && defined(MAGICKCORE_PIPES_SUPPORT)
if (*filename == '|')
{
char
- mode[MaxTextExtent];
+ fileMode[MagickPathExtent],
+ *sanitize_command;
/*
Pipe image to or from a system command.
if (*type == 'w')
(void) signal(SIGPIPE,SIG_IGN);
#endif
- *mode=(*type);
- mode[1]='\0';
- image->blob->file_info.file=(FILE *) popen_utf8(filename+1,mode);
+ *fileMode =(*type);
+ fileMode[1]='\0';
+ sanitize_command=SanitizeString(filename+1);
+ image->blob->file_info.file=(FILE *) popen_utf8(sanitize_command,
+ fileMode);
+ sanitize_command=DestroyString(sanitize_command);
if (image->blob->file_info.file == (FILE *) NULL)
{
ThrowFileException(exception,BlobError,"UnableToOpenBlob",filename);
}
image->blob->type=PipeStream;
image->blob->exempt=MagickTrue;
- return(MagickTrue);
+ return(SetStreamBuffering(image_info,image));
}
#endif
status=GetPathAttributes(filename,&image->blob->properties);
}
image->blob->type=FileStream;
image->blob->exempt=MagickTrue;
- return(MagickTrue);
+ return(SetStreamBuffering(image_info,image));
}
#endif
GetPathComponent(image->filename,ExtensionPath,extension);
if (*type == 'w')
{
- (void) CopyMagickString(filename,image->filename,MaxTextExtent);
+ (void) CopyMagickString(filename,image->filename,MagickPathExtent);
if ((image_info->adjoin == MagickFalse) ||
(strchr(filename,'%') != (char *) NULL))
{
(GetNextImageInList(image) != (Image *) NULL)))
{
char
- path[MaxTextExtent];
+ path[MagickPathExtent];
GetPathComponent(image->filename,RootPath,path);
if (*extension == '\0')
- (void) FormatLocaleString(filename,MaxTextExtent,"%s-%.20g",
+ (void) FormatLocaleString(filename,MagickPathExtent,"%s-%.20g",
path,(double) image->scene);
else
- (void) FormatLocaleString(filename,MaxTextExtent,"%s-%.20g.%s",
- path,(double) image->scene,extension);
+ (void) FormatLocaleString(filename,MagickPathExtent,
+ "%s-%.20g.%s",path,(double) image->scene,extension);
}
- (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+ (void) CopyMagickString(image->filename,filename,MagickPathExtent);
#if defined(macintosh)
SetApplicationType(filename,image_info->magick,'8BIM');
#endif
magick[3];
image->blob->type=FileStream;
-#if defined(MAGICKCORE_HAVE_SETVBUF)
- (void) setvbuf(image->blob->file_info.file,(char *) NULL,(int)
- _IOFBF,16384);
-#endif
+ (void) SetStreamBuffering(image_info,image);
(void) ResetMagickMemory(magick,0,sizeof(magick));
count=fread(magick,1,sizeof(magick),image->blob->file_info.file);
(void) fseek(image->blob->file_info.file,-((off_t) count),SEEK_CUR);
+#if defined(MAGICKCORE_POSIX_SUPPORT)
(void) fflush(image->blob->file_info.file);
+#endif
(void) LogMagickEvent(BlobEvent,GetMagickModule(),
" read %.20g magic header bytes",(double) count);
#if defined(MAGICKCORE_ZLIB_DELEGATE)
if (image->blob->file_info.file != (FILE *) NULL)
{
image->blob->type=FileStream;
-#if defined(MAGICKCORE_HAVE_SETVBUF)
- (void) setvbuf(image->blob->file_info.file,(char *) NULL,(int)
- _IOFBF,16384);
-#endif
+ (void) SetStreamBuffering(image_info,image);
}
}
image->blob->status=MagickFalse;
static size_t PingStream(const Image *magick_unused(image),
const void *magick_unused(pixels),const size_t columns)
{
+ magick_unreferenced(image);
+ magick_unreferenced(pixels);
return(columns);
}
*ping_info;
assert(image_info != (ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
count;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
assert(image->blob != (BlobInfo *) NULL);
assert(image->blob->type != UndefinedStream);
if (length == 0)
return(0);
assert(data != (void *) NULL);
count=0;
- q=data;
+ q=(unsigned char *) data;
switch (image->blob->type)
{
case UndefinedStream:
break;
case StandardStream:
- {
- register ssize_t
- i;
-
- for (i=0; i < (ssize_t) length; i+=count)
- {
- count=read(fileno(image->blob->file_info.file),q+i,MagickMin(length-i,
- (size_t) SSIZE_MAX));
- if (count <= 0)
- {
- count=0;
- if (errno != EINTR)
- break;
- }
- }
- count=i;
- break;
- }
case FileStream:
case PipeStream:
{
count=(ssize_t) fread(q,1,length,image->blob->file_info.file);
break;
}
+ case 4:
+ {
+ c=getc(image->blob->file_info.file);
+ if (c == EOF)
+ break;
+ *q++=(unsigned char) c;
+ count++;
+ }
+ case 3:
+ {
+ c=getc(image->blob->file_info.file);
+ if (c == EOF)
+ break;
+ *q++=(unsigned char) c;
+ count++;
+ }
case 2:
{
c=getc(image->blob->file_info.file);
(unsigned int) length);
break;
}
+ case 4:
+ {
+ c=gzgetc(image->blob->file_info.gzfile);
+ if (c == EOF)
+ break;
+ *q++=(unsigned char) c;
+ count++;
+ }
+ case 3:
+ {
+ c=gzgetc(image->blob->file_info.gzfile);
+ if (c == EOF)
+ break;
+ *q++=(unsigned char) c;
+ count++;
+ }
case 2:
{
c=gzgetc(image->blob->file_info.gzfile);
break;
}
p=image->blob->data+image->blob->offset;
- count=(ssize_t) MagickMin((MagickOffsetType) length,image->blob->length-
- image->blob->offset);
+ count=(ssize_t) MagickMin(length,image->blob->length-image->blob->offset);
image->blob->offset+=count;
if (count != (ssize_t) length)
image->blob->eof=MagickTrue;
(void) memcpy(q,p,(size_t) count);
break;
}
+ case CustomStream:
+ {
+ if (image->blob->custom_stream->reader != (CustomStreamHandler) NULL)
+ count=image->blob->custom_stream->reader(q,length,
+ image->blob->custom_stream->data);
+ break;
+ }
}
return(count);
}
buffer[1];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- p=ReadBlobStream(image,1,buffer,&count);
+ assert(image->signature == MagickCoreSignature);
+ p=(const unsigned char *) ReadBlobStream(image,1,buffer,&count);
if (count != 1)
return(EOF);
return((int) (*p));
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% ReadBlobLong() reads a ssize_t value as a 32-bit quantity in the byte-order
-% specified by the endian member of the image structure.
+% ReadBlobLong() reads a unsigned int value as a 32-bit quantity in the
+% byte-order specified by the endian member of the image structure.
%
% The format of the ReadBlobLong method is:
%
value;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,4,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,4,buffer,&count);
if (count != 4)
return(0UL);
if (image->endian == LSBEndian)
{
value=(unsigned int) (*p++);
- value|=((unsigned int) (*p++)) << 8;
- value|=((unsigned int) (*p++)) << 16;
- value|=((unsigned int) (*p++)) << 24;
- return(value);
+ value|=(unsigned int) (*p++) << 8;
+ value|=(unsigned int) (*p++) << 16;
+ value|=(unsigned int) (*p++) << 24;
+ return(value & 0xffffffff);
}
- value=((unsigned int) (*p++)) << 24;
- value|=((unsigned int) (*p++)) << 16;
- value|=((unsigned int) (*p++)) << 8;
- value|=((unsigned int) (*p++));
- return(value);
+ value=(unsigned int) (*p++) << 24;
+ value|=(unsigned int) (*p++) << 16;
+ value|=(unsigned int) (*p++) << 8;
+ value|=(unsigned int) (*p++);
+ return(value & 0xffffffff);
}
\f
/*
buffer[8];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,8,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,8,buffer,&count);
if (count != 8)
return(MagickULLConstant(0));
if (image->endian == LSBEndian)
{
value=(MagickSizeType) (*p++);
- value|=((MagickSizeType) (*p++)) << 8;
- value|=((MagickSizeType) (*p++)) << 16;
- value|=((MagickSizeType) (*p++)) << 24;
- value|=((MagickSizeType) (*p++)) << 32;
- value|=((MagickSizeType) (*p++)) << 40;
- value|=((MagickSizeType) (*p++)) << 48;
- value|=((MagickSizeType) (*p++)) << 56;
+ value|=(MagickSizeType) (*p++) << 8;
+ value|=(MagickSizeType) (*p++) << 16;
+ value|=(MagickSizeType) (*p++) << 24;
+ value|=(MagickSizeType) (*p++) << 32;
+ value|=(MagickSizeType) (*p++) << 40;
+ value|=(MagickSizeType) (*p++) << 48;
+ value|=(MagickSizeType) (*p++) << 56;
return(value & MagickULLConstant(0xffffffffffffffff));
}
- value=((MagickSizeType) (*p++)) << 56;
- value|=((MagickSizeType) (*p++)) << 48;
- value|=((MagickSizeType) (*p++)) << 40;
- value|=((MagickSizeType) (*p++)) << 32;
- value|=((MagickSizeType) (*p++)) << 24;
- value|=((MagickSizeType) (*p++)) << 16;
- value|=((MagickSizeType) (*p++)) << 8;
- value|=((MagickSizeType) (*p++));
+ value=(MagickSizeType) (*p++) << 56;
+ value|=(MagickSizeType) (*p++) << 48;
+ value|=(MagickSizeType) (*p++) << 40;
+ value|=(MagickSizeType) (*p++) << 32;
+ value|=(MagickSizeType) (*p++) << 24;
+ value|=(MagickSizeType) (*p++) << 16;
+ value|=(MagickSizeType) (*p++) << 8;
+ value|=(MagickSizeType) (*p++);
return(value & MagickULLConstant(0xffffffffffffffff));
}
\f
register const unsigned char
*p;
- register unsigned int
+ register unsigned short
value;
ssize_t
buffer[2];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,2,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,2,buffer,&count);
if (count != 2)
return((unsigned short) 0U);
if (image->endian == LSBEndian)
{
- value=(unsigned int) (*p++);
- value|=((unsigned int) (*p++)) << 8;
- return((unsigned short) (value & 0xffff));
+ value=(unsigned short) (*p++);
+ value|=(unsigned short) (*p++) << 8;
+ return(value);
}
- value=(unsigned int) ((*p++) << 8);
- value|=(unsigned int) (*p++);
- return((unsigned short) (value & 0xffff));
+ value=(unsigned short) (*p++) << 8;
+ value|=(unsigned short) (*p++);
+ return(value);
}
\f
/*
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% ReadBlobLSBLong() reads a ssize_t value as a 32-bit quantity in
+% ReadBlobLSBLong() reads a unsigned int value as a 32-bit quantity in
% least-significant byte first order.
%
% The format of the ReadBlobLSBLong method is:
buffer[4];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,4,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,4,buffer,&count);
if (count != 4)
return(0U);
value=(unsigned int) (*p++);
- value|=((unsigned int) (*p++)) << 8;
- value|=((unsigned int) (*p++)) << 16;
- value|=((unsigned int) (*p++)) << 24;
- return(value);
+ value|=(unsigned int) (*p++) << 8;
+ value|=(unsigned int) (*p++) << 16;
+ value|=(unsigned int) (*p++) << 24;
+ return(value & 0xffffffff);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ R e a d B l o b L S B S i g n e d L o n g %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReadBlobLSBSignedLong() reads a signed int value as a 32-bit quantity in
+% least-significant byte first order.
+%
+% The format of the ReadBlobLSBSignedLong method is:
+%
+% signed int ReadBlobLSBSignedLong(Image *image)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+*/
+MagickExport signed int ReadBlobLSBSignedLong(Image *image)
+{
+ union
+ {
+ unsigned int
+ unsigned_value;
+
+ signed int
+ signed_value;
+ } quantum;
+
+ quantum.unsigned_value=ReadBlobLSBLong(image);
+ return(quantum.signed_value);
}
\f
/*
register const unsigned char
*p;
- register unsigned int
+ register unsigned short
value;
ssize_t
buffer[2];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,2,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,2,buffer,&count);
if (count != 2)
return((unsigned short) 0U);
value=(unsigned int) (*p++);
- value|=((unsigned int) ((*p++)) << 8);
- return((unsigned short) (value & 0xffff));
+ value|=(unsigned int) (*p++) << 8;
+ return(value & 0xffff);
}
\f
/*
% %
% %
% %
-+ R e a d B l o b M S B L o n g %
++ R e a d B l o b L S B S i g n e d S h o r t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% ReadBlobMSBLong() reads a ssize_t value as a 32-bit quantity in
-% most-significant byte first order.
+% ReadBlobLSBSignedShort() reads a signed short value as a 16-bit quantity in
+% least-significant byte-order.
%
-% The format of the ReadBlobMSBLong method is:
+% The format of the ReadBlobLSBSignedShort method is:
%
-% unsigned int ReadBlobMSBLong(Image *image)
+% signed short ReadBlobLSBSignedShort(Image *image)
%
% A description of each parameter follows.
%
% o image: the image.
%
*/
-MagickExport unsigned int ReadBlobMSBLong(Image *image)
+MagickExport signed short ReadBlobLSBSignedShort(Image *image)
+{
+ union
+ {
+ unsigned short
+ unsigned_value;
+
+ signed short
+ signed_value;
+ } quantum;
+
+ quantum.unsigned_value=ReadBlobLSBShort(image);
+ return(quantum.signed_value);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ R e a d B l o b M S B L o n g %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReadBlobMSBLong() reads a unsigned int value as a 32-bit quantity in
+% most-significant byte first order.
+%
+% The format of the ReadBlobMSBLong method is:
+%
+% unsigned int ReadBlobMSBLong(Image *image)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+*/
+MagickExport unsigned int ReadBlobMSBLong(Image *image)
{
register const unsigned char
*p;
buffer[4];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,4,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,4,buffer,&count);
if (count != 4)
return(0UL);
- value=((unsigned int) (*p++) << 24);
- value|=((unsigned int) (*p++) << 16);
- value|=((unsigned int) (*p++) << 8);
+ value=(unsigned int) (*p++) << 24;
+ value|=(unsigned int) (*p++) << 16;
+ value|=(unsigned int) (*p++) << 8;
value|=(unsigned int) (*p++);
return(value);
}
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% ReadBlobMSBLongLong() reads a ssize_t value as a 64-bit quantity in
-% most-significant byte first order.
+% ReadBlobMSBLongLong() reads a unsigned long long value as a 64-bit quantity
+% in most-significant byte first order.
%
% The format of the ReadBlobMSBLongLong method is:
%
buffer[8];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,8,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,8,buffer,&count);
if (count != 8)
return(MagickULLConstant(0));
- value=((MagickSizeType) (*p++)) << 56;
- value|=((MagickSizeType) (*p++)) << 48;
- value|=((MagickSizeType) (*p++)) << 40;
- value|=((MagickSizeType) (*p++)) << 32;
- value|=((MagickSizeType) (*p++)) << 24;
- value|=((MagickSizeType) (*p++)) << 16;
- value|=((MagickSizeType) (*p++)) << 8;
- value|=((MagickSizeType) (*p++));
+ value=(MagickSizeType) (*p++) << 56;
+ value|=(MagickSizeType) (*p++) << 48;
+ value|=(MagickSizeType) (*p++) << 40;
+ value|=(MagickSizeType) (*p++) << 32;
+ value|=(MagickSizeType) (*p++) << 24;
+ value|=(MagickSizeType) (*p++) << 16;
+ value|=(MagickSizeType) (*p++) << 8;
+ value|=(MagickSizeType) (*p++);
return(value & MagickULLConstant(0xffffffffffffffff));
}
\f
register const unsigned char
*p;
- register unsigned int
+ register unsigned short
value;
ssize_t
buffer[2];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
*buffer='\0';
- p=ReadBlobStream(image,2,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,2,buffer,&count);
if (count != 2)
return((unsigned short) 0U);
- value=(unsigned int) ((*p++) << 8);
- value|=(unsigned int) (*p++);
- return((unsigned short) (value & 0xffff));
+ value=(unsigned short) (*p++) << 8;
+ value|=(unsigned short) (*p++);
+ return(value & 0xffff);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ R e a d B l o b M S B S i g n e d L o n g %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReadBlobMSBSignedLong() reads a signed int value as a 32-bit quantity in
+% most-significant byte-order.
+%
+% The format of the ReadBlobMSBSignedLong method is:
+%
+% signed int ReadBlobMSBSignedLong(Image *image)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+*/
+MagickExport signed int ReadBlobMSBSignedLong(Image *image)
+{
+ union
+ {
+ unsigned int
+ unsigned_value;
+
+ signed int
+ signed_value;
+ } quantum;
+
+ quantum.unsigned_value=ReadBlobMSBLong(image);
+ return(quantum.signed_value);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ R e a d B l o b M S B S i g n e d S h o r t %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReadBlobMSBSignedShort() reads a signed short value as a 16-bit quantity in
+% most-significant byte-order.
+%
+% The format of the ReadBlobMSBSignedShort method is:
+%
+% signed short ReadBlobMSBSignedShort(Image *image)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+*/
+MagickExport signed short ReadBlobMSBSignedShort(Image *image)
+{
+ union
+ {
+ unsigned short
+ unsigned_value;
+
+ signed short
+ signed_value;
+ } quantum;
+
+ quantum.unsigned_value=ReadBlobMSBShort(image);
+ return(quantum.signed_value);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ R e a d B l o b S i g n e d L o n g %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReadBlobSignedLong() reads a signed int value as a 32-bit quantity in the
+% byte-order specified by the endian member of the image structure.
+%
+% The format of the ReadBlobSignedLong method is:
+%
+% signed int ReadBlobSignedLong(Image *image)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+*/
+MagickExport signed int ReadBlobSignedLong(Image *image)
+{
+ union
+ {
+ unsigned int
+ unsigned_value;
+
+ signed int
+ signed_value;
+ } quantum;
+
+ quantum.unsigned_value=ReadBlobLong(image);
+ return(quantum.signed_value);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ R e a d B l o b S i g n e d S h o r t %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReadBlobSignedShort() reads a signed short value as a 16-bit quantity in the
+% byte-order specified by the endian member of the image structure.
+%
+% The format of the ReadBlobSignedShort method is:
+%
+% signed short ReadBlobSignedShort(Image *image)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+*/
+MagickExport signed short ReadBlobSignedShort(Image *image)
+{
+ union
+ {
+ unsigned short
+ unsigned_value;
+
+ signed short
+ signed_value;
+ } quantum;
+
+ quantum.unsigned_value=ReadBlobShort(image);
+ return(quantum.signed_value);
}
\f
/*
void *data,ssize_t *count)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
assert(image->blob != (BlobInfo *) NULL);
assert(image->blob->type != UndefinedStream);
assert(count != (ssize_t *) NULL);
if (image->blob->type != BlobStream)
{
assert(data != NULL);
- *count=ReadBlob(image,length,data);
+ *count=ReadBlob(image,length,(unsigned char *) data);
return(data);
}
if (image->blob->offset >= (MagickOffsetType) image->blob->length)
return(data);
}
data=image->blob->data+image->blob->offset;
- *count=(ssize_t) MagickMin((MagickOffsetType) length,image->blob->length-
- image->blob->offset);
+ *count=(ssize_t) MagickMin(length,image->blob->length-image->blob->offset);
image->blob->offset+=(*count);
if (*count != (ssize_t) length)
image->blob->eof=MagickTrue;
buffer[1];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- for (i=0; i < (MaxTextExtent-1L); i++)
+ assert(image->signature == MagickCoreSignature);
+ for (i=0; i < (MagickPathExtent-1L); i++)
{
- p=ReadBlobStream(image,1,buffer,&count);
+ p=(const unsigned char *) ReadBlobStream(image,1,buffer,&count);
if (count != 1)
{
if (i == 0)
return((char *) NULL);
+ string[i]='\0';
break;
}
string[i]=(char) (*p);
MagickExport BlobInfo *ReferenceBlob(BlobInfo *blob)
{
assert(blob != (BlobInfo *) NULL);
- assert(blob->signature == MagickSignature);
+ assert(blob->signature == MagickCoreSignature);
if (blob->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
LockSemaphoreInfo(blob->semaphore);
const MagickOffsetType offset,const int whence)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
case UndefinedStream:
break;
case StandardStream:
+ case PipeStream:
return(-1);
case FileStream:
{
- if ((whence == SEEK_SET) && (offset < 0))
+ if ((offset < 0) && (whence == SEEK_SET))
return(-1);
if (fseek(image->blob->file_info.file,offset,whence) < 0)
return(-1);
image->blob->offset=TellBlob(image);
break;
}
- case PipeStream:
case ZipStream:
{
#if defined(MAGICKCORE_ZLIB_DELEGATE)
image->blob->eof=MagickFalse;
break;
}
- if (image->blob->mapped != MagickFalse)
- return(-1);
if (image->blob->offset < (MagickOffsetType)
((off_t) image->blob->extent))
break;
+ if (image->blob->mapped != MagickFalse)
+ {
+ image->blob->eof=MagickTrue;
+ return(-1);
+ }
image->blob->extent=(size_t) (image->blob->offset+image->blob->quantum);
image->blob->quantum<<=1;
image->blob->data=(unsigned char *) ResizeQuantumMemory(image->blob->data,
}
break;
}
+ case CustomStream:
+ {
+ if (image->blob->custom_stream->seeker == (CustomStreamSeeker) NULL)
+ return(-1);
+ image->blob->offset=image->blob->custom_stream->seeker(offset,whence,
+ image->blob->custom_stream->data);
+ break;
+ }
}
return(image->blob->offset);
}
% o exempt: Set to true if this blob is exempt from being closed.
%
*/
-MagickPrivate void SetBlobExempt(Image *image,const MagickBooleanType exempt)
+MagickExport void SetBlobExempt(Image *image,const MagickBooleanType exempt)
{
assert(image != (const Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
image->blob->exempt=exempt;
% o extent: the blob maximum extent.
%
*/
-MagickPrivate MagickBooleanType SetBlobExtent(Image *image,
+MagickExport MagickBooleanType SetBlobExtent(Image *image,
const MagickSizeType extent)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
}
break;
}
+ case CustomStream:
+ break;
}
return(MagickTrue);
}
% %
% %
% %
++ S e t C u s t o m S t r e a m D a t a %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetCustomStreamData() sets the stream info data member.
+%
+% The format of the SetCustomStreamData method is:
+%
+% void SetCustomStreamData(CustomStreamInfo *custom_stream,void *)
+%
+% A description of each parameter follows:
+%
+% o custom_stream: your custom stream.
+%
+% o void: your data.
+%
+*/
+MagickExport void SetCustomStreamData(CustomStreamInfo *custom_stream,
+ void *data)
+{
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->signature == MagickCoreSignature);
+ custom_stream->data=data;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ S e t C u s t o m S t r e a m R e a d e r %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetCustomStreamReader() sets the stream info reader member.
+%
+% The format of the SetCustomStreamReader method is:
+%
+% void SetCustomStreamReader(CustomStreamInfo *custom_stream,
+% CustomStreamHandler reader)
+%
+% A description of each parameter follows:
+%
+% o custom_stream: your custom stream.
+%
+% o reader: your custom stream reader.
+%
+*/
+MagickExport void SetCustomStreamReader(CustomStreamInfo *custom_stream,
+ CustomStreamHandler reader)
+{
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->signature == MagickCoreSignature);
+ custom_stream->reader=reader;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ S e t C u s t o m S t r e a m S e e k e r %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetCustomStreamSeeker() sets the stream info seeker member.
+%
+% The format of the SetCustomStreamReader method is:
+%
+% void SetCustomStreamSeeker(CustomStreamInfo *custom_stream,
+% CustomStreamSeeker seeker)
+%
+% A description of each parameter follows:
+%
+% o custom_stream: your custom stream.
+%
+% o seeker: your custom stream seeker.
+%
+*/
+MagickExport void SetCustomStreamSeeker(CustomStreamInfo *custom_stream,
+ CustomStreamSeeker seeker)
+{
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->signature == MagickCoreSignature);
+ custom_stream->seeker=seeker;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ S e t C u s t o m S t r e a m T e l l e r %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetCustomStreamTeller() sets the stream info teller member.
+%
+% The format of the SetCustomStreamTeller method is:
+%
+% void SetCustomStreamTeller(CustomStreamInfo *custom_stream,
+% CustomStreamTeller *teller)
+%
+% A description of each parameter follows:
+%
+% o custom_stream: your custom stream.
+%
+% o teller: your custom stream teller.
+%
+*/
+MagickExport void SetCustomStreamTeller(CustomStreamInfo *custom_stream,
+ CustomStreamTeller teller)
+{
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->signature == MagickCoreSignature);
+ custom_stream->teller=teller;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ S e t C u s t o m S t r e a m W r i t e r %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetCustomStreamWriter() sets the stream info writer member.
+%
+% The format of the SetCustomStreamWriter method is:
+%
+% void SetCustomStreamWriter(CustomStreamInfo *custom_stream,
+% CustomStreamHandler *writer)
+%
+% A description of each parameter follows:
+%
+% o custom_stream: your custom stream.
+%
+% o writer: your custom stream writer.
+%
+*/
+MagickExport void SetCustomStreamWriter(CustomStreamInfo *custom_stream,
+ CustomStreamHandler writer)
+{
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->signature == MagickCoreSignature);
+ custom_stream->writer=writer;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ S y n c B l o b %
% %
% %
status;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
break;
case BlobStream:
break;
+ case CustomStream:
+ break;
}
return(status);
}
offset;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(image->blob != (BlobInfo *) NULL);
offset=image->blob->offset;
break;
}
+ case CustomStream:
+ {
+ if (image->blob->custom_stream->teller != (CustomStreamTeller) NULL)
+ offset=image->blob->custom_stream->teller(image->blob->custom_stream->data);
+ break;
+ }
}
return(offset);
}
% %
% %
% %
+% C u s t o m S t r e a m T o I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% CustomStreamToImage() is the equivalent of ReadImage(), but reads the
+% formatted "file" from the suplied method rather than to an actual file.
+%
+% The format of the CustomStreamToImage method is:
+%
+% Image *CustomStreamToImage(const ImageInfo *image_info,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image_info: the image info.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *CustomStreamToImage(const ImageInfo *image_info,
+ ExceptionInfo *exception)
+{
+ const MagickInfo
+ *magick_info;
+
+ Image
+ *image;
+
+ ImageInfo
+ *blob_info;
+
+ assert(image_info != (ImageInfo *) NULL);
+ assert(image_info->signature == MagickCoreSignature);
+ if (image_info->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
+ image_info->filename);
+ assert(image_info->custom_stream != (CustomStreamInfo *) NULL);
+ assert(image_info->custom_stream->signature == MagickCoreSignature);
+ assert(image_info->custom_stream->reader != (CustomStreamHandler) NULL);
+ assert(exception != (ExceptionInfo *) NULL);
+ blob_info=CloneImageInfo(image_info);
+ if (*blob_info->magick == '\0')
+ (void) SetImageInfo(blob_info,0,exception);
+ magick_info=GetMagickInfo(blob_info->magick,exception);
+ if (magick_info == (const MagickInfo *) NULL)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
+ blob_info->magick);
+ blob_info=DestroyImageInfo(blob_info);
+ return((Image *) NULL);
+ }
+ image=(Image *) NULL;
+ if ((GetMagickBlobSupport(magick_info) != MagickFalse) ||
+ (blob_info->custom_stream == (CustomStreamInfo *) NULL))
+ {
+ /*
+ Native blob support for this image format or SetImageInfo changed the
+ blob to a file.
+ */
+ image=ReadImage(blob_info,exception);
+ if (image != (Image *) NULL)
+ (void) CloseBlob(image);
+ }
+ else
+ {
+ char
+ unique[MagickPathExtent];
+
+ int
+ file;
+
+ ImageInfo
+ *clone_info;
+
+ unsigned char
+ *blob;
+
+ /*
+ Write data to file on disk.
+ */
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
+ blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
+ sizeof(*blob));
+ if (blob == (unsigned char *) NULL)
+ {
+ ThrowFileException(exception,BlobError,"UnableToReadBlob",
+ image_info->filename);
+ blob_info=DestroyImageInfo(blob_info);
+ return((Image *) NULL);
+ }
+ file=AcquireUniqueFileResource(unique);
+ if (file == -1)
+ {
+ ThrowFileException(exception,BlobError,"UnableToReadBlob",
+ image_info->filename);
+ blob=(unsigned char *) RelinquishMagickMemory(blob);
+ blob_info=DestroyImageInfo(blob_info);
+ return((Image *) NULL);
+ }
+ clone_info=CloneImageInfo(blob_info);
+ blob_info->file=fdopen(file,"wb+");
+ if (blob_info->file != (FILE *) NULL)
+ {
+ ssize_t
+ count;
+
+ count=(ssize_t) MagickMaxBufferExtent;
+ while (count == (ssize_t) MagickMaxBufferExtent)
+ {
+ count=image_info->custom_stream->reader(blob,MagickMaxBufferExtent,
+ image_info->custom_stream->data);
+ count=(ssize_t) write(file,(const char *) blob,count);
+ }
+ (void) fclose(blob_info->file);
+ (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
+ "%s:%s",blob_info->magick,unique);
+ image=ReadImage(clone_info,exception);
+ if (image != (Image *) NULL)
+ {
+ Image
+ *images;
+
+ /*
+ Restore original filenames and image format.
+ */
+ for (images=GetFirstImageInList(image); images != (Image *) NULL; )
+ {
+ (void) CopyMagickString(images->filename,image_info->filename,
+ MagickPathExtent);
+ (void) CopyMagickString(images->magick_filename,
+ image_info->filename,MagickPathExtent);
+ (void) CopyMagickString(images->magick,magick_info->name,
+ MagickPathExtent);
+ (void) CloseBlob(images);
+ images=GetNextImageInList(images);
+ }
+ }
+ }
+ clone_info=DestroyImageInfo(clone_info);
+ blob=(unsigned char *) RelinquishMagickMemory(blob);
+ (void) RelinquishUniqueFileResource(unique);
+ }
+ blob_info=DestroyImageInfo(blob_info);
+ return(image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ W r i t e B l o b %
% %
% %
%
% The format of the WriteBlob method is:
%
-% ssize_t WriteBlob(Image *image,const size_t length,
-% const unsigned char *data)
+% ssize_t WriteBlob(Image *image,const size_t length,const void *data)
%
% A description of each parameter follows:
%
%
*/
MagickExport ssize_t WriteBlob(Image *image,const size_t length,
- const unsigned char *data)
+ const void *data)
{
int
c;
count;
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- assert(data != (const unsigned char *) NULL);
+ assert(image->signature == MagickCoreSignature);
assert(image->blob != (BlobInfo *) NULL);
assert(image->blob->type != UndefinedStream);
if (length == 0)
return(0);
+ assert(data != (const void *) NULL);
count=0;
- p=data;
+ p=(const unsigned char *) data;
switch (image->blob->type)
{
case UndefinedStream:
break;
+ case StandardStream:
case FileStream:
case PipeStream:
{
if (image->blob->offset >= (MagickOffsetType) image->blob->length)
image->blob->length=(size_t) image->blob->offset;
count=(ssize_t) length;
+ break;
+ }
+ case CustomStream:
+ {
+ if (image->blob->custom_stream->writer != (CustomStreamHandler) NULL)
+ count=image->blob->custom_stream->writer((const unsigned char *) data,
+ length,image->blob->custom_stream->data);
+ break;
}
}
return(count);
MagickExport ssize_t WriteBlobByte(Image *image,const unsigned char value)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
return(WriteBlobStream(image,1,&value));
}
\f
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% WriteBlobLong() writes a ssize_t value as a 32-bit quantity in the byte-order
-% specified by the endian member of the image structure.
+% WriteBlobLong() writes a unsigned int value as a 32-bit quantity in the
+% byte-order specified by the endian member of the image structure.
%
% The format of the WriteBlobLong method is:
%
buffer[4];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->endian == LSBEndian)
{
buffer[0]=(unsigned char) value;
buffer[2];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->endian == LSBEndian)
{
buffer[0]=(unsigned char) value;
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% WriteBlobLSBLong() writes a ssize_t value as a 32-bit quantity in
+% WriteBlobLSBLong() writes a unsigned int value as a 32-bit quantity in
% least-significant byte first order.
%
% The format of the WriteBlobLSBLong method is:
buffer[4];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
buffer[0]=(unsigned char) value;
buffer[1]=(unsigned char) (value >> 8);
buffer[2]=(unsigned char) (value >> 16);
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% WriteBlobLSBShort() writes a ssize_t value as a 16-bit quantity in
+% WriteBlobLSBShort() writes a unsigned short value as a 16-bit quantity in
% least-significant byte first order.
%
% The format of the WriteBlobLSBShort method is:
buffer[2];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
buffer[0]=(unsigned char) value;
buffer[1]=(unsigned char) (value >> 8);
return(WriteBlobStream(image,2,buffer));
% %
% %
% %
++ W r i t e B l o b L S B S i g n e d L o n g %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% WriteBlobLSBSignedLong() writes a signed value as a 32-bit quantity in
+% least-significant byte first order.
+%
+% The format of the WriteBlobLSBSignedLong method is:
+%
+% ssize_t WriteBlobLSBSignedLong(Image *image,const signed int value)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+% o value: Specifies the value to write.
+%
+*/
+MagickExport ssize_t WriteBlobLSBSignedLong(Image *image,const signed int value)
+{
+ union
+ {
+ unsigned int
+ unsigned_value;
+
+ signed int
+ signed_value;
+ } quantum;
+
+ unsigned char
+ buffer[4];
+
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ quantum.signed_value=value;
+ buffer[0]=(unsigned char) quantum.unsigned_value;
+ buffer[1]=(unsigned char) (quantum.unsigned_value >> 8);
+ buffer[2]=(unsigned char) (quantum.unsigned_value >> 16);
+ buffer[3]=(unsigned char) (quantum.unsigned_value >> 24);
+ return(WriteBlobStream(image,4,buffer));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ W r i t e B l o b L S B S i g n e d S h o r t %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% WriteBlobLSBSignedShort() writes a signed short value as a 16-bit quantity
+% in least-significant byte first order.
+%
+% The format of the WriteBlobLSBSignedShort method is:
+%
+% ssize_t WriteBlobLSBSignedShort(Image *image,const signed short value)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+% o value: Specifies the value to write.
+%
+*/
+MagickExport ssize_t WriteBlobLSBSignedShort(Image *image,
+ const signed short value)
+{
+ union
+ {
+ unsigned short
+ unsigned_value;
+
+ signed short
+ signed_value;
+ } quantum;
+
+ unsigned char
+ buffer[2];
+
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ quantum.signed_value=value;
+ buffer[0]=(unsigned char) quantum.unsigned_value;
+ buffer[1]=(unsigned char) (quantum.unsigned_value >> 8);
+ return(WriteBlobStream(image,2,buffer));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ W r i t e B l o b M S B L o n g %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% WriteBlobMSBLong() writes a ssize_t value as a 32-bit quantity in
+% WriteBlobMSBLong() writes a unsigned int value as a 32-bit quantity in
% most-significant byte first order.
%
% The format of the WriteBlobMSBLong method is:
buffer[4];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
buffer[0]=(unsigned char) (value >> 24);
buffer[1]=(unsigned char) (value >> 16);
buffer[2]=(unsigned char) (value >> 8);
buffer[8];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
buffer[0]=(unsigned char) (value >> 56);
buffer[1]=(unsigned char) (value >> 48);
buffer[2]=(unsigned char) (value >> 40);
% %
% %
% %
++ W r i t e B l o b M S B S i g n e d L o n g %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% WriteBlobMSBSignedLong() writes a signed value as a 32-bit quantity in
+% most-significant byte first order.
+%
+% The format of the WriteBlobMSBSignedLong method is:
+%
+% ssize_t WriteBlobMSBSignedLong(Image *image,const signed int value)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+% o value: Specifies the value to write.
+%
+*/
+MagickExport ssize_t WriteBlobMSBSignedLong(Image *image,const signed int value)
+{
+ union
+ {
+ unsigned int
+ unsigned_value;
+
+ signed int
+ signed_value;
+ } quantum;
+
+ unsigned char
+ buffer[4];
+
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ quantum.signed_value=value;
+ buffer[0]=(unsigned char) (quantum.unsigned_value >> 24);
+ buffer[1]=(unsigned char) (quantum.unsigned_value >> 16);
+ buffer[2]=(unsigned char) (quantum.unsigned_value >> 8);
+ buffer[3]=(unsigned char) quantum.unsigned_value;
+ return(WriteBlobStream(image,4,buffer));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ W r i t e B l o b M S B S i g n e d S h o r t %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% WriteBlobMSBSignedShort() writes a signed short value as a 16-bit quantity
+% in most-significant byte first order.
+%
+% The format of the WriteBlobMSBSignedShort method is:
+%
+% ssize_t WriteBlobMSBSignedShort(Image *image,const signed short value)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+% o value: Specifies the value to write.
+%
+*/
+MagickExport ssize_t WriteBlobMSBSignedShort(Image *image,
+ const signed short value)
+{
+ union
+ {
+ unsigned short
+ unsigned_value;
+
+ signed short
+ signed_value;
+ } quantum;
+
+ unsigned char
+ buffer[2];
+
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickCoreSignature);
+ quantum.signed_value=value;
+ buffer[0]=(unsigned char) (quantum.unsigned_value >> 8);
+ buffer[1]=(unsigned char) quantum.unsigned_value;
+ return(WriteBlobStream(image,2,buffer));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ W r i t e B l o b M S B S h o r t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% WriteBlobMSBShort() writes a ssize_t value as a 16-bit quantity in
+% WriteBlobMSBShort() writes a unsigned short value as a 16-bit quantity in
% most-significant byte first order.
%
% The format of the WriteBlobMSBShort method is:
buffer[2];
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
buffer[0]=(unsigned char) (value >> 8);
buffer[1]=(unsigned char) value;
return(WriteBlobStream(image,2,buffer));
MagickExport ssize_t WriteBlobString(Image *image,const char *string)
{
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
assert(string != (const char *) NULL);
return(WriteBlobStream(image,strlen(string),(const unsigned char *) string));
}