This source file includes following definitions.
- IsMVG
- ReadMVGImage
- RegisterMVGImage
- UnregisterMVGImage
- WriteMVGImage
#include "magick/studio.h"
#include "magick/artifact.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/draw.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/module.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
static MagickBooleanType
WriteMVGImage(const ImageInfo *,Image *);
static MagickBooleanType IsMVG(const unsigned char *magick,const size_t length)
{
if (length < 20)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"push graphic-context",20) == 0)
return(MagickTrue);
return(MagickFalse);
}
static Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define BoundingBox "viewbox"
DrawInfo
*draw_info;
Image
*image;
MagickBooleanType
status;
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);
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
if ((image->columns == 0) || (image->rows == 0))
{
char
primitive[MaxTextExtent];
register char
*p;
SegmentInfo
bounds;
while (ReadBlobString(image,primitive) != (char *) NULL)
{
for (p=primitive; (*p == ' ') || (*p == '\t'); p++) ;
if (LocaleNCompare(BoundingBox,p,strlen(BoundingBox)) != 0)
continue;
(void) sscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1,
&bounds.x2,&bounds.y2);
image->columns=(size_t) floor((bounds.x2-bounds.x1)+0.5);
image->rows=(size_t) floor((bounds.y2-bounds.y1)+0.5);
break;
}
}
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
draw_info->affine.sx=image->x_resolution == 0.0 ? 1.0 : image->x_resolution/
DefaultResolution;
draw_info->affine.sy=image->y_resolution == 0.0 ? 1.0 : image->y_resolution/
DefaultResolution;
image->columns=(size_t) (draw_info->affine.sx*image->columns);
image->rows=(size_t) (draw_info->affine.sy*image->rows);
status=SetImageExtent(image,image->columns,image->rows);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
return(DestroyImageList(image));
}
if (SetImageBackgroundColor(image) == MagickFalse)
{
InheritException(exception,&image->exception);
image=DestroyImageList(image);
return((Image *) NULL);
}
if (GetBlobStreamData(image) == (unsigned char *) NULL)
draw_info->primitive=FileToString(image->filename,~0UL,exception);
else
{
draw_info->primitive=(char *) AcquireMagickMemory(GetBlobSize(image)+1);
if (draw_info->primitive != (char *) NULL)
{
CopyMagickMemory(draw_info->primitive,GetBlobStreamData(image),
GetBlobSize(image));
draw_info->primitive[GetBlobSize(image)]='\0';
}
}
(void) DrawImage(image,draw_info);
draw_info=DestroyDrawInfo(draw_info);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
ModuleExport size_t RegisterMVGImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MVG");
entry->decoder=(DecodeImageHandler *) ReadMVGImage;
entry->encoder=(EncodeImageHandler *) WriteMVGImage;
entry->magick=(IsImageFormatHandler *) IsMVG;
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->description=ConstantString("Magick Vector Graphics");
entry->module=ConstantString("MVG");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterMVGImage(void)
{
(void) UnregisterMagickInfo("MVG");
}
static MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image)
{
const char
*value;
MagickBooleanType
status;
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);
value=GetImageArtifact(image,"MVG");
if (value == (const char *) NULL)
ThrowWriterException(OptionError,"NoImageVectorGraphics");
status=OpenBlob(image_info,image,WriteBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
(void) WriteBlob(image,strlen(value),(const unsigned char *) value);
(void) CloseBlob(image);
return(MagickTrue);
}