This source file includes following definitions.
- IsFAX
- ReadFAXImage
- RegisterFAXImage
- UnregisterFAXImage
- WriteFAXImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/compress.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
static MagickBooleanType
WriteFAXImage(const ImageInfo *,Image *);
static MagickBooleanType IsFAX(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (LocaleNCompare((char *) magick,"DFAX",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
static Image *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
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);
}
image->storage_class=PseudoClass;
if (image->columns == 0)
image->columns=2592;
if (image->rows == 0)
image->rows=3508;
image->depth=8;
if (AcquireImageColormap(image,2) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
image->colormap[0].red=QuantumRange;
image->colormap[0].green=QuantumRange;
image->colormap[0].blue=QuantumRange;
image->colormap[1].red=(Quantum) 0;
image->colormap[1].green=(Quantum) 0;
image->colormap[1].blue=(Quantum) 0;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
status=SetImageExtent(image,image->columns,image->rows);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
return(DestroyImageList(image));
}
status=HuffmanDecodeImage(image);
if (status == MagickFalse)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
ModuleExport size_t RegisterFAXImage(void)
{
MagickInfo
*entry;
static const char
*Note=
{
"FAX machines use non-square pixels which are 1.5 times wider than\n"
"they are tall but computer displays use square pixels, therefore\n"
"FAX images may appear to be narrow unless they are explicitly\n"
"resized using a geometry of \"150x100%\".\n"
};
entry=SetMagickInfo("FAX");
entry->decoder=(DecodeImageHandler *) ReadFAXImage;
entry->encoder=(EncodeImageHandler *) WriteFAXImage;
entry->magick=(IsImageFormatHandler *) IsFAX;
entry->description=ConstantString("Group 3 FAX");
entry->note=ConstantString(Note);
entry->module=ConstantString("FAX");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("G3");
entry->decoder=(DecodeImageHandler *) ReadFAXImage;
entry->encoder=(EncodeImageHandler *) WriteFAXImage;
entry->magick=(IsImageFormatHandler *) IsFAX;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Group 3 FAX");
entry->module=ConstantString("FAX");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterFAXImage(void)
{
(void) UnregisterMagickInfo("FAX");
(void) UnregisterMagickInfo("G3");
}
static MagickBooleanType WriteFAXImage(const ImageInfo *image_info,Image *image)
{
ImageInfo
*write_info;
MagickBooleanType
status;
MagickOffsetType
scene;
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_info=CloneImageInfo(image_info);
(void) CopyMagickString(write_info->magick,"FAX",MaxTextExtent);
scene=0;
do
{
(void) TransformImageColorspace(image,sRGBColorspace);
status=HuffmanEncodeImage(write_info,image,image);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (write_info->adjoin != MagickFalse);
write_info=DestroyImageInfo(write_info);
(void) CloseBlob(image);
return(status);
}