This source file includes following definitions.
- ReadRAWImage
- RegisterRAWImage
- UnregisterRAWImage
- WriteRAWImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.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/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#include "magick/module.h"
static MagickBooleanType
WriteRAWImage(const ImageInfo *,Image *);
static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
const unsigned char
*pixels;
Image
*canvas_image,
*image;
MagickBooleanType
status;
MagickOffsetType
scene;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
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);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
if (DiscardBlobBytes(image,image->offset) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
exception);
(void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
quantum_type=GrayQuantum;
quantum_info=AcquireQuantumInfo(image_info,canvas_image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
pixels=(const unsigned char *) NULL;
if (image_info->number_scenes != 0)
while (image->scene < image_info->scene)
{
image->scene++;
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
for (y=0; y < (ssize_t) image->rows; y++)
{
pixels=(const unsigned char *) ReadBlobStream(image,length,
GetQuantumPixels(quantum_info),&count);
if (count != (ssize_t) length)
break;
}
}
scene=0;
count=0;
length=0;
do
{
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));
}
if (scene == 0)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
pixels=(const unsigned char *) ReadBlobStream(image,length,
GetQuantumPixels(quantum_info),&count);
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
register const PixelPacket
*magick_restrict p;
register PixelPacket
*magick_restrict q;
register ssize_t
x;
if (count != (ssize_t) length)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
if (((y-image->extract_info.y) >= 0) &&
((y-image->extract_info.y) < (ssize_t) image->rows))
{
p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
image->columns,1,exception);
q=QueueAuthenticPixels(image,0,y-image->extract_info.y,image->columns,
1,exception);
if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,GetPixelRed(p));
SetPixelGreen(q,GetPixelGreen(p));
SetPixelBlue(q,GetPixelBlue(p));
p++;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
pixels=(const unsigned char *) ReadBlobStream(image,length,
GetQuantumPixels(quantum_info),&count);
}
SetQuantumImageType(image,quantum_type);
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
if (count == (ssize_t) length)
{
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;
}
scene++;
} while (count == (ssize_t) length);
quantum_info=DestroyQuantumInfo(quantum_info);
InheritException(&image->exception,&canvas_image->exception);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
ModuleExport size_t RegisterRAWImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("R");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw red samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("C");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw cyan samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("G");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw green samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("M");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw magenta samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("B");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw blue samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("Y");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw yellow samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("A");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw alpha samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("O");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw opacity samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("K");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Raw black samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterRAWImage(void)
{
(void) UnregisterMagickInfo("R");
(void) UnregisterMagickInfo("C");
(void) UnregisterMagickInfo("G");
(void) UnregisterMagickInfo("M");
(void) UnregisterMagickInfo("B");
(void) UnregisterMagickInfo("Y");
(void) UnregisterMagickInfo("A");
(void) UnregisterMagickInfo("O");
(void) UnregisterMagickInfo("K");
}
static MagickBooleanType WriteRAWImage(const ImageInfo *image_info,Image *image)
{
MagickOffsetType
scene;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
MagickBooleanType
status;
register const PixelPacket
*p;
size_t
length;
ssize_t
count,
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);
switch (*image->magick)
{
case 'A':
case 'a':
{
quantum_type=AlphaQuantum;
break;
}
case 'B':
case 'b':
{
quantum_type=BlueQuantum;
break;
}
case 'C':
case 'c':
{
quantum_type=CyanQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
case 'g':
case 'G':
{
quantum_type=GreenQuantum;
break;
}
case 'I':
case 'i':
{
quantum_type=IndexQuantum;
break;
}
case 'K':
case 'k':
{
quantum_type=BlackQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
case 'M':
case 'm':
{
quantum_type=MagentaQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
case 'o':
case 'O':
{
quantum_type=OpacityQuantum;
break;
}
case 'R':
case 'r':
{
quantum_type=RedQuantum;
break;
}
case 'Y':
case 'y':
{
quantum_type=YellowQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
default:
{
quantum_type=GrayQuantum;
break;
}
}
scene=0;
do
{
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,
quantum_type,pixels,&image->exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
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) CloseBlob(image);
return(MagickTrue);
}