This source file includes following definitions.
- IsIPL
- SetHeaderFromIPL
- ReadIPLImage
- RegisterIPLImage
- UnregisterIPLImage
- WriteIPLImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.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/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
typedef struct _IPLInfo
{
unsigned int
tag,
size,
time,
z,
width,
height,
colors,
depth,
byteType;
} IPLInfo;
static MagickBooleanType
WriteIPLImage(const ImageInfo *,Image *);
static MagickBooleanType IsIPL(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"data",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
static void SetHeaderFromIPL(Image *image, IPLInfo *ipl){
image->columns = ipl->width;
image->rows = ipl->height;
image->depth = ipl->depth;
image->x_resolution = 1;
image->y_resolution = 1;
}
static Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image *image;
MagickBooleanType status;
register PixelPacket *q;
unsigned char magick[12], *pixels;
ssize_t count;
ssize_t y;
size_t t_count=0;
size_t length;
IPLInfo
ipl_info;
QuantumFormatType
quantum_format;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
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);
}
count=ReadBlob(image,4,magick);
(void) count;
if((LocaleNCompare((char *) magick,"iiii",4) == 0))
image->endian=LSBEndian;
else{
if((LocaleNCompare((char *) magick,"mmmm",4) == 0))
image->endian=MSBEndian;
else{
ThrowReaderException(CorruptImageError, "ImproperImageHeader");
}
}
count=ReadBlob(image, 8, magick);
count=ReadBlob(image,4,magick);
if((LocaleNCompare((char *) magick,"data",4) != 0))
ThrowReaderException(CorruptImageError, "ImproperImageHeader");
ipl_info.size=ReadBlobLong(image);
ipl_info.width=ReadBlobLong(image);
ipl_info.height=ReadBlobLong(image);
if((ipl_info.width == 0UL) || (ipl_info.height == 0UL))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
ipl_info.colors=ReadBlobLong(image);
if(ipl_info.colors == 3){ SetImageColorspace(image,sRGBColorspace);}
else { image->colorspace = GRAYColorspace; }
ipl_info.z=ReadBlobLong(image);
ipl_info.time=ReadBlobLong(image);
ipl_info.byteType=ReadBlobLong(image);
switch (ipl_info.byteType) {
case 0:
ipl_info.depth=8;
quantum_format = UnsignedQuantumFormat;
break;
case 1:
ipl_info.depth=16;
quantum_format = SignedQuantumFormat;
break;
case 2:
ipl_info.depth=16;
quantum_format = UnsignedQuantumFormat;
break;
case 3:
ipl_info.depth=32;
quantum_format = SignedQuantumFormat;
break;
case 4: ipl_info.depth=32;
quantum_format = FloatingPointQuantumFormat;
break;
case 5:
ipl_info.depth=8;
quantum_format = UnsignedQuantumFormat;
break;
case 6:
ipl_info.depth=16;
quantum_format = UnsignedQuantumFormat;
break;
case 10:
ipl_info.depth=64;
quantum_format = FloatingPointQuantumFormat;
break;
default:
ipl_info.depth=16;
quantum_format = UnsignedQuantumFormat;
break;
}
SetHeaderFromIPL(image, &ipl_info);
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
length=image->columns;
quantum_type=GetQuantumType(image,exception);
do
{
SetHeaderFromIPL(image, &ipl_info);
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
status=SetImageExtent(image,image->columns,image->rows);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
return(DestroyImageList(image));
}
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
status=SetQuantumFormat(image,quantum_info,quantum_format);
if (status == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
if(image->columns != ipl_info.width){
}
if(ipl_info.colors == 1){
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
}
else{
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RedQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GreenQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
BlueQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
}
SetQuantumImageType(image,quantum_type);
t_count++;
quantum_info = DestroyQuantumInfo(quantum_info);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
if(t_count < ipl_info.z * ipl_info.time){
AcquireNextImage(image_info, image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while (t_count < ipl_info.z*ipl_info.time);
CloseBlob(image);
return(GetFirstImageInList(image));
}
ModuleExport size_t RegisterIPLImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("IPL");
entry->decoder=(DecodeImageHandler *) ReadIPLImage;
entry->encoder=(EncodeImageHandler *) WriteIPLImage;
entry->magick=(IsImageFormatHandler *) IsIPL;
entry->adjoin=MagickTrue;
entry->description=ConstantString("IPL Image Sequence");
entry->module=ConstantString("IPL");
entry->endian_support=MagickTrue;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterIPLImage(void)
{
(void) UnregisterMagickInfo("IPL");
}
static MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image)
{
ExceptionInfo
*exception;
IPLInfo
ipl_info;
MagickBooleanType
status;
MagickOffsetType
scene;
register const PixelPacket
*p;
QuantumInfo
*quantum_info;
ssize_t
y;
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);
scene=0;
quantum_info=AcquireQuantumInfo(image_info, image);
if ((quantum_info->format == UndefinedQuantumFormat) &&
(IsHighDynamicRangeImage(image,&image->exception) != MagickFalse))
SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
switch(quantum_info->depth){
case 8:
ipl_info.byteType = 0;
break;
case 16:
if(quantum_info->format == SignedQuantumFormat){
ipl_info.byteType = 2;
}
else{
ipl_info.byteType = 1;
}
break;
case 32:
if(quantum_info->format == FloatingPointQuantumFormat){
ipl_info.byteType = 3;
}
else{
ipl_info.byteType = 4;
}
break;
case 64:
ipl_info.byteType = 10;
break;
default:
ipl_info.byteType = 2;
break;
}
ipl_info.z = (unsigned int) GetImageListLength(image);
ipl_info.time = 1;
ipl_info.width = (unsigned int) image->columns;
ipl_info.height = (unsigned int) image->rows;
(void) TransformImageColorspace(image,sRGBColorspace);
if(IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) { ipl_info.colors = 3; }
else{ ipl_info.colors = 1; }
ipl_info.size = (unsigned int) (28 +
((image->depth)/8)*ipl_info.height*ipl_info.width*ipl_info.colors*ipl_info.z);
if(image_info->endian == MSBEndian)
(void) WriteBlob(image, 4, (const unsigned char *) "mmmm");
else{
image->endian = LSBEndian;
(void) WriteBlob(image, 4, (const unsigned char *) "iiii");
}
(void) WriteBlobLong(image, 4);
(void) WriteBlob(image, 4, (const unsigned char *) "100f");
(void) WriteBlob(image, 4, (const unsigned char *) "data");
(void) WriteBlobLong(image, ipl_info.size);
(void) WriteBlobLong(image, ipl_info.width);
(void) WriteBlobLong(image, ipl_info.height);
(void) WriteBlobLong(image, ipl_info.colors);
if(image_info->adjoin == MagickFalse)
(void) WriteBlobLong(image, 1);
else
(void) WriteBlobLong(image, ipl_info.z);
(void) WriteBlobLong(image, ipl_info.time);
(void) WriteBlobLong(image, ipl_info.byteType);
exception=(&image->exception);
do
{
pixels=GetQuantumPixels(quantum_info);
if(ipl_info.colors == 1){
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
GrayQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
}
}
if(ipl_info.colors == 3){
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
RedQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
}
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
GreenQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
}
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
BlueQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
}
quantum_info=DestroyQuantumInfo(quantum_info);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
}while (image_info->adjoin != MagickFalse);
(void) WriteBlob(image, 4, (const unsigned char *) "fini");
(void) WriteBlobLong(image, 0);
CloseBlob(image);
return(MagickTrue);
}