This source file includes following definitions.
- IsEPT
- ReadEPTImage
- RegisterEPTImage
- UnregisterEPTImage
- WriteEPTImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/color.h"
#include "magick/constitute.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/delegate.h"
#include "magick/geometry.h"
#include "magick/histogram.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/quantize.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/transform.h"
#include "magick/utility.h"
typedef struct _EPTInfo
{
size_t
magick;
MagickOffsetType
postscript_offset,
tiff_offset;
size_t
postscript_length,
tiff_length;
unsigned char
*postscript,
*tiff;
} EPTInfo;
static MagickBooleanType
WriteEPTImage(const ImageInfo *,Image *);
static MagickBooleanType IsEPT(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"\305\320\323\306",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
static Image *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
EPTInfo
ept_info;
Image
*image;
ImageInfo
*read_info;
MagickBooleanType
status;
MagickOffsetType
offset;
ssize_t
count;
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);
}
ept_info.magick=ReadBlobLSBLong(image);
if (ept_info.magick != 0xc6d3d0c5ul)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
ept_info.postscript_offset=(MagickOffsetType) ReadBlobLSBLong(image);
ept_info.postscript_length=ReadBlobLSBLong(image);
(void) ReadBlobLSBLong(image);
(void) ReadBlobLSBLong(image);
ept_info.tiff_offset=(MagickOffsetType) ReadBlobLSBLong(image);
ept_info.tiff_length=ReadBlobLSBLong(image);
(void) ReadBlobLSBShort(image);
ept_info.postscript=(unsigned char *) AcquireQuantumMemory(
ept_info.postscript_length+1,sizeof(*ept_info.postscript));
if (ept_info.postscript == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) ResetMagickMemory(ept_info.postscript,0,(ept_info.postscript_length+1)*
sizeof(*ept_info.postscript));
ept_info.tiff=(unsigned char *) AcquireQuantumMemory(ept_info.tiff_length+1,
sizeof(*ept_info.tiff));
if (ept_info.tiff == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) ResetMagickMemory(ept_info.tiff,0,(ept_info.tiff_length+1)*
sizeof(*ept_info.tiff));
offset=SeekBlob(image,ept_info.tiff_offset,SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
count=ReadBlob(image,ept_info.tiff_length,ept_info.tiff);
if (count != (ssize_t) (ept_info.tiff_length))
(void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning,
"InsufficientImageDataInFile","`%s'",image->filename);
offset=SeekBlob(image,ept_info.postscript_offset,SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
count=ReadBlob(image,ept_info.postscript_length,ept_info.postscript);
if (count != (ssize_t) (ept_info.postscript_length))
(void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning,
"InsufficientImageDataInFile","`%s'",image->filename);
(void) CloseBlob(image);
image=DestroyImage(image);
read_info=CloneImageInfo(image_info);
(void) CopyMagickString(read_info->magick,"EPS",MaxTextExtent);
image=BlobToImage(read_info,ept_info.postscript,ept_info.postscript_length,
exception);
if (image == (Image *) NULL)
{
(void) CopyMagickString(read_info->magick,"TIFF",MaxTextExtent);
image=BlobToImage(read_info,ept_info.tiff,ept_info.tiff_length,exception);
}
read_info=DestroyImageInfo(read_info);
if (image != (Image *) NULL)
{
(void) CopyMagickString(image->filename,image_info->filename,
MaxTextExtent);
(void) CopyMagickString(image->magick,"EPT",MaxTextExtent);
}
ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
ept_info.postscript);
return(image);
}
ModuleExport size_t RegisterEPTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("EPT");
entry->decoder=(DecodeImageHandler *) ReadEPTImage;
entry->encoder=(EncodeImageHandler *) WriteEPTImage;
entry->magick=(IsImageFormatHandler *) IsEPT;
entry->seekable_stream=MagickTrue;
entry->adjoin=MagickFalse;
entry->blob_support=MagickFalse;
entry->description=ConstantString(
"Encapsulated PostScript with TIFF preview");
entry->module=ConstantString("EPT");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("EPT2");
entry->decoder=(DecodeImageHandler *) ReadEPTImage;
entry->encoder=(EncodeImageHandler *) WriteEPTImage;
entry->magick=(IsImageFormatHandler *) IsEPT;
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->blob_support=MagickFalse;
entry->description=ConstantString(
"Encapsulated PostScript Level II with TIFF preview");
entry->module=ConstantString("EPT");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("EPT3");
entry->decoder=(DecodeImageHandler *) ReadEPTImage;
entry->encoder=(EncodeImageHandler *) WriteEPTImage;
entry->magick=(IsImageFormatHandler *) IsEPT;
entry->seekable_stream=MagickTrue;
entry->blob_support=MagickFalse;
entry->description=ConstantString(
"Encapsulated PostScript Level III with TIFF preview");
entry->module=ConstantString("EPT");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterEPTImage(void)
{
(void) UnregisterMagickInfo("EPT");
}
static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image)
{
char
filename[MaxTextExtent];
EPTInfo
ept_info;
Image
*write_image;
ImageInfo
*write_info;
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);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
write_image=CloneImage(image,0,0,MagickTrue,&image->exception);
if (write_image == (Image *) NULL)
return(MagickFalse);
write_info=CloneImageInfo(image_info);
*write_info->magick='\0';
(void) CopyMagickString(write_info->magick,"EPS",MaxTextExtent);
if (LocaleCompare(image_info->magick,"EPT2") == 0)
(void) CopyMagickString(write_info->magick,"EPS2",MaxTextExtent);
if (LocaleCompare(image_info->magick,"EPT3") == 0)
(void) CopyMagickString(write_info->magick,"EPS3",MaxTextExtent);
(void) ResetMagickMemory(&ept_info,0,sizeof(ept_info));
ept_info.magick=0xc6d3d0c5ul;
ept_info.postscript=(unsigned char *) ImageToBlob(write_info,write_image,
&ept_info.postscript_length,&image->exception);
write_image=DestroyImage(write_image);
write_info=DestroyImageInfo(write_info);
if (ept_info.postscript == (void *) NULL)
return(MagickFalse);
write_image=CloneImage(image,0,0,MagickTrue,&image->exception);
if (write_image == (Image *) NULL)
return(MagickFalse);
write_info=CloneImageInfo(image_info);
(void) CopyMagickString(write_info->magick,"TIFF",MaxTextExtent);
(void) FormatLocaleString(filename,MaxTextExtent,"tiff:%s",
write_info->filename);
(void) CopyMagickString(write_info->filename,filename,MaxTextExtent);
(void) TransformImage(&write_image,(char *) NULL,"512x512>");
if ((write_image->storage_class == DirectClass) ||
(write_image->colors > 256))
{
QuantizeInfo
quantize_info;
GetQuantizeInfo(&quantize_info);
quantize_info.dither=IsPaletteImage(write_image,&image->exception) ==
MagickFalse ? MagickTrue : MagickFalse;
(void) QuantizeImage(&quantize_info,write_image);
}
write_info->compression=NoCompression;
ept_info.tiff=(unsigned char *) ImageToBlob(write_info,write_image,
&ept_info.tiff_length,&image->exception);
write_image=DestroyImage(write_image);
write_info=DestroyImageInfo(write_info);
if (ept_info.tiff == (void *) NULL)
{
ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
ept_info.postscript);
return(MagickFalse);
}
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.magick);
(void) WriteBlobLSBLong(image,30);
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length);
(void) WriteBlobLSBLong(image,0);
(void) WriteBlobLSBLong(image,0);
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length+30);
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.tiff_length);
(void) WriteBlobLSBShort(image,0xffff);
(void) WriteBlob(image,ept_info.postscript_length,ept_info.postscript);
(void) WriteBlob(image,ept_info.tiff_length,ept_info.tiff);
ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
ept_info.postscript);
ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
(void) CloseBlob(image);
return(MagickTrue);
}