This source file includes following definitions.
- ReadHRZImage
- RegisterHRZImage
- UnregisterHRZImage
- WriteHRZImage
#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/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
static MagickBooleanType
WriteHRZImage(const ImageInfo *,Image *);
static Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register ssize_t
x;
register PixelPacket
*q;
register unsigned char
*p;
ssize_t
count,
y;
size_t
length;
unsigned char
*pixels;
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->columns=256;
image->rows=240;
image->depth=8;
status=SetImageExtent(image,image->columns,image->rows);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
return(DestroyImageList(image));
}
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,3*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
length=(size_t) (3*image->columns);
for (y=0; y < (ssize_t) image->rows; y++)
{
count=ReadBlob(image,length,pixels);
if ((size_t) count != length)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(4**p++));
SetPixelGreen(q,ScaleCharToQuantum(4**p++));
SetPixelBlue(q,ScaleCharToQuantum(4**p++));
SetPixelOpacity(q,OpaqueOpacity);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
ModuleExport size_t RegisterHRZImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HRZ");
entry->decoder=(DecodeImageHandler *) ReadHRZImage;
entry->encoder=(EncodeImageHandler *) WriteHRZImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Slow Scan TeleVision");
entry->module=ConstantString("HRZ");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterHRZImage(void)
{
(void) UnregisterMagickInfo("HRZ");
}
static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
{
Image
*hrz_image;
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
x,
y;
register unsigned char
*q;
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);
hrz_image=ResizeImage(image,256,240,image->filter,image->blur,
&image->exception);
if (hrz_image == (Image *) NULL)
return(MagickFalse);
(void) TransformImageColorspace(hrz_image,sRGBColorspace);
pixels=(unsigned char *) AcquireQuantumMemory((size_t) hrz_image->columns,
3*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
{
hrz_image=DestroyImage(hrz_image);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
for (y=0; y < (ssize_t) hrz_image->rows; y++)
{
p=GetVirtualPixels(hrz_image,0,y,hrz_image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
q=pixels;
for (x=0; x < (ssize_t) hrz_image->columns; x++)
{
*q++=ScaleQuantumToChar(GetPixelRed(p)/4);
*q++=ScaleQuantumToChar(GetPixelGreen(p)/4);
*q++=ScaleQuantumToChar(GetPixelBlue(p)/4);
p++;
}
count=WriteBlob(image,(size_t) (q-pixels),pixels);
if (count != (ssize_t) (q-pixels))
break;
status=SetImageProgress(image,SaveImageTag,y,hrz_image->rows);
if (status == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
hrz_image=DestroyImage(hrz_image);
(void) CloseBlob(image);
return(MagickTrue);
}