This source file includes following definitions.
- IsVICAR
- ReadVICARImage
- RegisterVICARImage
- UnregisterVICARImage
- WriteVICARImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.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/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/string-private.h"
static MagickBooleanType
WriteVICARImage(const ImageInfo *,Image *);
static MagickBooleanType IsVICAR(const unsigned char *magick,
const size_t length)
{
if (length < 14)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"LBLSIZE",7) == 0)
return(MagickTrue);
if (LocaleNCompare((const char *) magick,"NJPL1I",6) == 0)
return(MagickTrue);
if (LocaleNCompare((const char *) magick,"PDS_VERSION_ID",14) == 0)
return(MagickTrue);
return(MagickFalse);
}
static Image *ReadVICARImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
char
keyword[MaxTextExtent],
value[MaxTextExtent];
const unsigned char
*pixels;
Image
*image;
int
c;
MagickBooleanType
status,
value_expected;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
register PixelPacket
*q;
size_t
length;
ssize_t
count,
y;
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);
}
c=ReadBlobByte(image);
count=1;
if (c == EOF)
{
image=DestroyImage(image);
return((Image *) NULL);
}
length=0;
image->columns=0;
image->rows=0;
while (isgraph(c) && ((image->columns == 0) || (image->rows == 0)))
{
if (isalnum(c) == MagickFalse)
{
c=ReadBlobByte(image);
count++;
}
else
{
register char
*p;
p=keyword;
do
{
if ((size_t) (p-keyword) < (MaxTextExtent-1))
*p++=c;
c=ReadBlobByte(image);
count++;
} while (isalnum(c) || (c == '_'));
*p='\0';
value_expected=MagickFalse;
while ((isspace((int) ((unsigned char) c)) != 0) || (c == '='))
{
if (c == '=')
value_expected=MagickTrue;
c=ReadBlobByte(image);
count++;
}
if (value_expected == MagickFalse)
continue;
p=value;
while (isalnum(c))
{
if ((size_t) (p-value) < (MaxTextExtent-1))
*p++=c;
c=ReadBlobByte(image);
count++;
}
*p='\0';
if (LocaleCompare(keyword,"Label_RECORDS") == 0)
length=(ssize_t) StringToLong(value);
if (LocaleCompare(keyword,"LBLSIZE") == 0)
length=(ssize_t) StringToLong(value);
if (LocaleCompare(keyword,"RECORD_BYTES") == 0)
image->columns=StringToUnsignedLong(value);
if (LocaleCompare(keyword,"NS") == 0)
image->columns=StringToUnsignedLong(value);
if (LocaleCompare(keyword,"LINES") == 0)
image->rows=StringToUnsignedLong(value);
if (LocaleCompare(keyword,"NL") == 0)
image->rows=StringToUnsignedLong(value);
}
while (isspace((int) ((unsigned char) c)) != 0)
{
c=ReadBlobByte(image);
count++;
}
}
while (count < (ssize_t) length)
{
c=ReadBlobByte(image);
if (c == EOF)
break;
count++;
}
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
image->depth=8;
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));
}
(void) SetImageColorspace(image,GRAYColorspace);
quantum_type=GrayQuantum;
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
length=GetQuantumExtent(image,quantum_info,quantum_type);
pixels=(const unsigned char *) NULL;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
pixels=(const unsigned char *) ReadBlobStream(image,length,
GetQuantumPixels(quantum_info),&count);
if (count != (ssize_t) length)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
SetQuantumImageType(image,quantum_type);
quantum_info=DestroyQuantumInfo(quantum_info);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
ModuleExport size_t RegisterVICARImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("VICAR");
entry->decoder=(DecodeImageHandler *) ReadVICARImage;
entry->encoder=(EncodeImageHandler *) WriteVICARImage;
entry->magick=(IsImageFormatHandler *) IsVICAR;
entry->adjoin=MagickFalse;
entry->description=ConstantString("VICAR rasterfile format");
entry->module=ConstantString("VICAR");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterVICARImage(void)
{
(void) UnregisterMagickInfo("VICAR");
}
static MagickBooleanType WriteVICARImage(const ImageInfo *image_info,
Image *image)
{
char
header[MaxTextExtent];
int
y;
MagickBooleanType
status;
QuantumInfo
*quantum_info;
register const PixelPacket
*p;
size_t
length;
ssize_t
count;
unsigned char
*pixels;
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);
(void) TransformImageColorspace(image,sRGBColorspace);
(void) ResetMagickMemory(header,' ',MaxTextExtent);
(void) FormatLocaleString(header,MaxTextExtent,
"LBLSIZE=%.20g FORMAT='BYTE' TYPE='IMAGE' BUFSIZE=20000 DIM=2 EOL=0 "
"RECSIZE=%.20g ORG='BSQ' NL=%.20g NS=%.20g NB=1 N1=0 N2=0 N3=0 N4=0 NBB=0 "
"NLB=0 TASK='ImageMagick'",(double) MaxTextExtent,(double) image->columns,
(double) image->rows,(double) image->columns);
(void) WriteBlob(image,MaxTextExtent,(unsigned char *) header);
image->depth=8;
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
GrayQuantum,pixels,&image->exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
quantum_info=DestroyQuantumInfo(quantum_info);
(void) CloseBlob(image);
return(MagickTrue);
}