/*
Typedef declarations.
*/
+typedef ssize_t
+ (*BlobHandler)(const unsigned char *,const size_t,const void *);
+
+typedef size_t
+ (*BlobSeeker)(const MagickOffsetType offset,const int whence,const void *);
+
+typedef MagickOffsetType
+ (*BlobTeller)(const void *);
+
+struct _CustomStreamInfo
+{
+ BlobHandler
+ reader,
+ writer;
+
+ BlobSeeker
+ seeker;
+
+ BlobTeller
+ teller;
+
+ void
+ *data;
+};
+
typedef union FileInfo
{
FILE
StreamHandler
stream;
- CustomBlobInfo
- *custom_info;
+ CustomStreamInfo
+ *custom_stream;
unsigned char
*data;
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_info=blob_info->custom_info;
+ clone_info->custom_stream=blob_info->custom_stream;
clone_info->data=blob_info->data;
clone_info->debug=IsEventLogging();
clone_info->reference_count=1;
data=blob_info->data;
blob_info->data=(unsigned char *) NULL;
blob_info->stream=(StreamHandler) NULL;
- blob_info->custom_info=(CustomBlobInfo *) NULL;
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
return(data);
}
\f
% %
% %
% %
-+ I m a g e T o C u s t o m B l o b %
++ I m a g e T o C u s t o m S t r e a m %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% ImageToCustomBlob() is the equivalent of WriteImage(), but writes the
-% formatted "file" to the supplied method rather than to an actual file.
+% 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 ImageToCustomBlob method is:
+% The format of the ImageToCustomStream method is:
%
-% void ImageToCustomBlob(const ImageInfo *image_info,Image *image,
-% CustomBlobInfo *custom_info,ExceptionInfo *exception)
+% void ImageToCustomStream(const ImageInfo *image_info,Image *image,
+% CustomStreamInfo *custom_stream,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
%
% o image: the image.
%
-% o custom_info: the methods to use when writing and seeking.
+% o custom_stream: the methods to use when writing and seeking.
%
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport void ImageToCustomBlob(const ImageInfo *image_info,Image *image,
- CustomBlobInfo *custom_info,ExceptionInfo *exception)
+MagickExport void ImageToCustomStream(const ImageInfo *image_info,Image *image,
+ CustomStreamInfo *custom_stream,ExceptionInfo *exception)
{
const MagickInfo
*magick_info;
image_info->filename);
assert(image != (Image *) NULL);
assert(image->signature == MagickCoreSignature);
- assert(custom_info != (CustomBlobInfo *) NULL);
- assert(custom_info->reader != (BlobHandler) NULL);
- assert(custom_info->writer != (BlobHandler) NULL);
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->reader != (BlobHandler) NULL);
+ assert(custom_stream->writer != (BlobHandler) NULL);
assert(exception != (ExceptionInfo *) NULL);
blob_info=CloneImageInfo(image_info);
blob_info->adjoin=MagickFalse;
- blob_info->custom_info=custom_info;
+ blob_info->custom_stream=custom_stream;
(void) SetImageInfo(blob_info,1,exception);
if (*blob_info->magick != '\0')
(void) CopyMagickString(image->magick,blob_info->magick,MagickPathExtent);
/*
Write file to disk in blob image format.
*/
- blob_info->custom_info=(CustomBlobInfo *) NULL;
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
sizeof(*blob));
if (blob == (unsigned char *) NULL)
{
count=(ssize_t) fread(blob,sizeof(*blob),MagickMaxBufferExtent,
blob_info->file);
- custom_info->writer(blob,count,custom_info->data);
+ custom_stream->writer(blob,count,custom_stream->data);
}
}
(void) fclose(blob_info->file);
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% ImagesToCustomBlob() is the equivalent of WriteImages(), but writes the
-% formatted "file" to the supplied method rather than to an actual file.
+% 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 ImageToCustomBlob method is:
+% The format of the ImageToCustomStream method is:
%
-% void ImagesToCustomBlob(const ImageInfo *image_info,Image *images,
-% CustomBlobInfo *custom_info,ExceptionInfo *exception)
+% void ImagesToCustomStream(const ImageInfo *image_info,Image *images,
+% CustomStreamInfo *custom_stream,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
%
% o images: the image list.
%
-% o custom_info: the methods to use when writing and seeking.
+% o custom_stream: the methods to use when writing and seeking.
%
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport void ImagesToCustomBlob(const ImageInfo *image_info,Image *images,
- CustomBlobInfo *custom_info,ExceptionInfo *exception)
+MagickExport void ImagesToCustomStream(const ImageInfo *image_info,
+ Image *images,CustomStreamInfo *custom_stream,ExceptionInfo *exception)
{
const MagickInfo
*magick_info;
image_info->filename);
assert(images != (Image *) NULL);
assert(images->signature == MagickCoreSignature);
- assert(custom_info != (CustomBlobInfo *) NULL);
- assert(custom_info->reader != (BlobHandler) NULL);
- assert(custom_info->writer != (BlobHandler) NULL);
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->reader != (BlobHandler) NULL);
+ assert(custom_stream->writer != (BlobHandler) NULL);
assert(exception != (ExceptionInfo *) NULL);
blob_info=CloneImageInfo(image_info);
- blob_info->custom_info=custom_info;
+ blob_info->custom_stream=custom_stream;
(void) SetImageInfo(blob_info,(unsigned int) GetImageListLength(images),
exception);
if (*blob_info->magick != '\0')
/*
Write file to disk in blob image format.
*/
- blob_info->custom_info=(CustomBlobInfo *) NULL;
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
sizeof(*blob));
if (blob == (unsigned char *) NULL)
{
count=(ssize_t) fread(blob,sizeof(*blob),MagickMaxBufferExtent,
blob_info->file);
- custom_info->writer(blob,count,custom_info->data);
+ custom_stream->writer(blob,count,custom_stream->data);
}
}
(void) fclose(blob_info->file);
}
case CustomStream:
{
- if ((image->blob->custom_info->seeker != (BlobSeeker) NULL) &&
- (image->blob->custom_info->teller != (BlobTeller) NULL))
+ if ((image->blob->custom_stream->seeker != (BlobSeeker) NULL) &&
+ (image->blob->custom_stream->teller != (BlobTeller) NULL))
seekable=MagickTrue;
else
seekable=MagickFalse;
AttachBlob(image->blob,image_info->blob,image_info->length);
return(MagickTrue);
}
- if ((image_info->custom_info != (CustomBlobInfo *) NULL) &&
+ if ((image_info->custom_stream != (CustomStreamInfo *) NULL) &&
(*image->filename == '\0'))
{
image->blob->type=CustomStream;
- image->blob->custom_info=image_info->custom_info;
+ image->blob->custom_stream=image_info->custom_stream;
return(MagickTrue);
}
(void) DetachBlob(image->blob);
}
case CustomStream:
{
- count=image->blob->custom_info->reader(q,length,
- image->blob->custom_info->data);
+ count=image->blob->custom_stream->reader(q,length,
+ image->blob->custom_stream->data);
break;
}
}
}
case CustomStream:
{
- if (image->blob->custom_info->seeker == (BlobSeeker) NULL)
+ if (image->blob->custom_stream->seeker == (BlobSeeker) NULL)
return(-1);
- image->blob->offset=image->blob->custom_info->seeker(offset,whence,
- image->blob->custom_info->data);
+ image->blob->offset=image->blob->custom_stream->seeker(offset,whence,
+ image->blob->custom_stream->data);
break;
}
}
% %
% %
% %
+% S e t B l o b C u s t o m S t r e a m %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetBlobCustomStream() sets the blob's custom stream handlers.
+%
+% The format of the SetBlobCustomStream method is:
+%
+% void SetBlobCustomStream(BlobInfo *blob_info,
+% ssize_t (*reader)(const unsigned char *,const size_t,const void *),
+% ssize_t (*writer)(const unsigned char *,const size_t,const void *),
+% size_t (*seeker)(const MagickOffsetType,const int,const void *),
+% MagickOffsetType (*teller)(const void *))
+%
+% A description of each parameter follows:
+%
+% o blob_info: the blob info.
+%
+% o reader: your custom stream reader.
+%
+% o writer: your custom stream writer.
+%
+% o seeker: your custom stream seeker.
+%
+% o teller: your custom stream teller.
+%
+*/
+MagickExport void SetBlobCustomStream(BlobInfo *blob_info,
+ ssize_t (*reader)(const unsigned char *,const size_t,const void *),
+ ssize_t (*writer)(const unsigned char *,const size_t,const void *),
+ size_t (*seeker)(const MagickOffsetType,const int,const void *),
+ MagickOffsetType (*teller)(const void *))
+{
+ assert(blob_info != (BlobInfo *) NULL);
+ assert(blob_info->signature == MagickCoreSignature);
+ blob_info->custom_stream->reader=reader;
+ blob_info->custom_stream->writer=writer;
+ blob_info->custom_stream->seeker=seeker;
+ blob_info->custom_stream->teller=teller;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ S e t B l o b E x e m p t %
% %
% %
}
case CustomStream:
{
- if (image->blob->custom_info->teller != (BlobTeller) NULL)
- offset=image->blob->custom_info->teller(image->blob->custom_info->data);
+ if (image->blob->custom_stream->teller != (BlobTeller) NULL)
+ offset=image->blob->custom_stream->teller(image->blob->custom_stream->data);
break;
}
}
% %
% %
% %
-% C u s t o m B l o b T o I m a g e %
+% C u s t o m S t r e a m T o I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% CustomBlobToImage() is the equivalent of ReadImage(), but reads the
+% 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 BlobToImage method is:
+% The format of the CustomStreamToImage method is:
%
-% Image *BlobToImage(const ImageInfo *image_info,const void *blob,
-% const size_t length,ExceptionInfo *exception)
+% Image *CustomStreamToImage(const ImageInfo *image_info,
+% CustomStreamInfo *custom_stream,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
-% o blob: the address of a character stream in one of the image formats
-% understood by ImageMagick.
-%
-% o length: This size_t integer reflects the length in bytes of the blob.
+% o custom_stream: the methods to use when writing and seeking.
%
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport Image *CustomBlobToImage(const ImageInfo *image_info,
- CustomBlobInfo *custom_info,ExceptionInfo *exception)
+MagickExport Image *CustomStreamToImage(const ImageInfo *image_info,
+ CustomStreamInfo *custom_stream,ExceptionInfo *exception)
{
const MagickInfo
*magick_info;
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
- assert(custom_info != (CustomBlobInfo *) NULL);
- assert(custom_info->reader != (BlobHandler) NULL);
+ assert(custom_stream != (CustomStreamInfo *) NULL);
+ assert(custom_stream->reader != (BlobHandler) NULL);
assert(exception != (ExceptionInfo *) NULL);
blob_info=CloneImageInfo(image_info);
- blob_info->custom_info=custom_info;
+ blob_info->custom_stream=custom_stream;
if (*blob_info->magick == '\0')
(void) SetImageInfo(blob_info,0,exception);
magick_info=GetMagickInfo(blob_info->magick,exception);
}
image=(Image *) NULL;
if ((GetMagickBlobSupport(magick_info) != MagickFalse) ||
- (blob_info->custom_info == (CustomBlobInfo *) NULL))
+ (blob_info->custom_stream == (CustomStreamInfo *) NULL))
{
/*
Native blob support for this image format or SetImageInfo changed the
/*
Write data to file on disk.
*/
- blob_info->custom_info=(CustomBlobInfo *) NULL;
+ blob_info->custom_stream=(CustomStreamInfo *) NULL;
blob=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
sizeof(*blob));
if (blob == (unsigned char *) NULL)
count=(ssize_t) MagickMaxBufferExtent;
while (count == (ssize_t) MagickMaxBufferExtent)
{
- count=custom_info->reader(blob,MagickMaxBufferExtent,
- custom_info->data);
+ count=custom_stream->reader(blob,MagickMaxBufferExtent,
+ custom_stream->data);
count=(ssize_t) write(file,(const char *) blob,count);
}
(void) fclose(blob_info->file);
}
case CustomStream:
{
- count=image->blob->custom_info->writer((const unsigned char *) data,
- length,image->blob->custom_info->data);
+ count=image->blob->custom_stream->writer((const unsigned char *) data,
+ length,image->blob->custom_stream->data);
break;
}
}
SetImageInfoFile(clone_info,image_info->file);
SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
clone_info->stream=image_info->stream;
- clone_info->custom_info=image_info->custom_info;
+ clone_info->custom_stream=image_info->custom_stream;
(void) CopyMagickString(clone_info->magick,image_info->magick,
MagickPathExtent);
(void) CopyMagickString(clone_info->unique,image_info->unique,
% %
% %
% %
+% S e t I m a g e A l p h a %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetImageAlpha() sets the alpha levels of the image.
+%
+% The format of the SetImageAlpha method is:
+%
+% MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
+% fully transparent.
+%
+*/
+MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
+ ExceptionInfo *exception)
+{
+ CacheView
+ *image_view;
+
+ MagickBooleanType
+ status;
+
+ ssize_t
+ y;
+
+ assert(image != (Image *) NULL);
+ if (image->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+ assert(image->signature == MagickCoreSignature);
+ image->alpha_trait=BlendPixelTrait;
+ status=MagickTrue;
+ image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(image,image,image->rows,1)
+#endif
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ register Quantum
+ *magick_restrict q;
+
+ register ssize_t
+ x;
+
+ if (status == MagickFalse)
+ continue;
+ q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+ if (q == (Quantum *) NULL)
+ {
+ status=MagickFalse;
+ continue;
+ }
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ if (GetPixelWriteMask(image,q) != 0)
+ SetPixelAlpha(image,alpha,q);
+ q+=GetPixelChannels(image);
+ }
+ if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+ status=MagickFalse;
+ }
+ image_view=DestroyCacheView(image_view);
+ return(status);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% S e t I m a g e B a c k g r o u n d C o l o r %
% %
% %
% %
% %
% %
-% S e t I m a g e I n f o F i l e %
+% S e t I m a g e I n f o C u s t o m S t r e a m %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SetImageInfoFile() sets the image info file member.
+% SetImageInfoCustomStream() sets the image info custom stream handlers.
%
-% The format of the SetImageInfoFile method is:
+% The format of the SetImageInfoCustomStream method is:
%
-% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
+% void SetImageInfoCustomStream(ImageInfo *image_info,
+% ssize_t (*reader)(const unsigned char *,const size_t,const void *),
+% ssize_t (*writer)(const unsigned char *,const size_t,const void *),
+% size_t (*seeker)(const MagickOffsetType,const int,const void *),
+% MagickOffsetType (*teller)(const void *))
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
-% o file: the file.
+% o reader: your custom stream reader.
+%
+% o writer: your custom stream writer.
+%
+% o seeker: your custom stream seeker.
+%
+% o teller: your custom stream teller.
%
*/
-MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
+MagickExport void SetImageInfoCustomStream(ImageInfo *image_info,
+ ssize_t (*reader)(const unsigned char *,const size_t,const void *),
+ ssize_t (*writer)(const unsigned char *,const size_t,const void *),
+ size_t (*seeker)(const MagickOffsetType,const int,const void *),
+ MagickOffsetType (*teller)(const void *))
{
assert(image_info != (ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
- image_info->file=file;
+ SetBlobCustomStream(image_info->blob,reader,writer,seeker,teller);
}
\f
/*
% %
% %
% %
-% S e t I m a g e A l p h a %
+% S e t I m a g e I n f o F i l e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SetImageAlpha() sets the alpha levels of the image.
+% SetImageInfoFile() sets the image info file member.
%
-% The format of the SetImageAlpha method is:
+% The format of the SetImageInfoFile method is:
%
-% MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
-% ExceptionInfo *exception)
+% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
%
% A description of each parameter follows:
%
-% o image: the image.
+% o image_info: the image info.
%
-% o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
-% fully transparent.
+% o file: the file.
%
*/
-MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
- ExceptionInfo *exception)
+MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
{
- CacheView
- *image_view;
-
- MagickBooleanType
- status;
-
- ssize_t
- y;
-
- assert(image != (Image *) NULL);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
- assert(image->signature == MagickCoreSignature);
- image->alpha_trait=BlendPixelTrait;
- status=MagickTrue;
- image_view=AcquireAuthenticCacheView(image,exception);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(status) \
- magick_threads(image,image,image->rows,1)
-#endif
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- register Quantum
- *magick_restrict q;
-
- register ssize_t
- x;
-
- if (status == MagickFalse)
- continue;
- q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
- if (q == (Quantum *) NULL)
- {
- status=MagickFalse;
- continue;
- }
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- if (GetPixelWriteMask(image,q) != 0)
- SetPixelAlpha(image,alpha,q);
- q+=GetPixelChannels(image);
- }
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- status=MagickFalse;
- }
- image_view=DestroyCacheView(image_view);
- return(status);
+ assert(image_info != (ImageInfo *) NULL);
+ assert(image_info->signature == MagickCoreSignature);
+ if (image_info->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
+ image_info->filename);
+ image_info->file=file;
}
\f
/*