This source file includes following definitions.
- ReadINLINEImage
- RegisterINLINEImage
- UnregisterINLINEImage
- WriteINLINEImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/client.h"
#include "magick/display.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
#include "magick/xwindow.h"
#include "magick/xwindow-private.h"
static MagickBooleanType
WriteINLINEImage(const ImageInfo *,Image *);
static Image *ReadINLINEImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register size_t
i;
size_t
quantum;
ssize_t
count;
unsigned char
*inline_image;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
if (LocaleCompare(image_info->magick,"DATA") == 0)
{
char
*filename;
Image
*data_image;
filename=AcquireString("data:");
(void) ConcatenateMagickString(filename,image_info->filename,
MaxTextExtent);
data_image=ReadInlineImage(image_info,filename,exception);
filename=DestroyString(filename);
return(data_image);
}
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
quantum=MagickMin((size_t) GetBlobSize(image),MagickMaxBufferExtent);
if (quantum == 0)
quantum=MagickMaxBufferExtent;
inline_image=(unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*inline_image));
count=0;
for (i=0; inline_image != (unsigned char *) NULL; i+=count)
{
count=(ssize_t) ReadBlob(image,quantum,inline_image+i);
if (count <= 0)
{
count=0;
if (errno != EINTR)
break;
}
if (~((size_t) i) < (quantum+1))
{
inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
break;
}
inline_image=(unsigned char *) ResizeQuantumMemory(inline_image,i+count+
quantum+1,sizeof(*inline_image));
}
if (inline_image == (unsigned char *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return((Image *) NULL);
}
inline_image[i+count]='\0';
image=DestroyImageList(image);
image=ReadInlineImage(image_info,(char *) inline_image,exception);
inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
return(image);
}
ModuleExport size_t RegisterINLINEImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("DATA");
entry->decoder=(DecodeImageHandler *) ReadINLINEImage;
entry->encoder=(EncodeImageHandler *) WriteINLINEImage;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Base64-encoded inline images");
entry->module=ConstantString("INLINE");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("INLINE");
entry->decoder=(DecodeImageHandler *) ReadINLINEImage;
entry->encoder=(EncodeImageHandler *) WriteINLINEImage;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Base64-encoded inline images");
entry->module=ConstantString("INLINE");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterINLINEImage(void)
{
(void) UnregisterMagickInfo("INLINE");
(void) UnregisterMagickInfo("DATA");
}
static MagickBooleanType WriteINLINEImage(const ImageInfo *image_info,
Image *image)
{
char
*base64,
message[MaxTextExtent];
const MagickInfo
*magick_info;
ExceptionInfo
*exception;
Image
*write_image;
ImageInfo
*write_info;
MagickBooleanType
status;
size_t
blob_length,
encode_length;
unsigned char
*blob;
assert(image_info != (const 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);
exception=(&image->exception);
write_info=CloneImageInfo(image_info);
(void) SetImageInfo(write_info,1,exception);
if (LocaleCompare(write_info->magick,"INLINE") == 0)
(void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
magick_info=GetMagickInfo(write_info->magick,exception);
if ((magick_info == (const MagickInfo *) NULL) ||
(GetMagickMimeType(magick_info) == (const char *) NULL))
ThrowWriterException(CorruptImageError,"ImageTypeNotSupported");
(void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
blob_length=2048;
write_image=CloneImage(image,0,0,MagickTrue,exception);
if (write_image == (Image *) NULL)
{
write_info=DestroyImageInfo(write_info);
return(MagickTrue);
}
blob=(unsigned char *) ImageToBlob(write_info,write_image,&blob_length,
exception);
write_image=DestroyImage(write_image);
write_info=DestroyImageInfo(write_info);
if (blob == (unsigned char *) NULL)
return(MagickFalse);
encode_length=0;
base64=Base64Encode(blob,blob_length,&encode_length);
blob=(unsigned char *) RelinquishMagickMemory(blob);
if (base64 == (char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
{
base64=DestroyString(base64);
return(status);
}
(void) FormatLocaleString(message,MaxTextExtent,"data:%s;base64,",
GetMagickMimeType(magick_info));
(void) WriteBlobString(image,message);
(void) WriteBlobString(image,base64);
base64=DestroyString(base64);
return(MagickTrue);
}