% Read/Write RAW Gray Image Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
Include declarations.
*/
#include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
#include "MagickCore/blob.h"
#include "MagickCore/blob-private.h"
#include "MagickCore/cache.h"
static Image *ReadGRAYImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
+ const unsigned char
+ *pixels;
+
Image
*canvas_image,
*image;
count,
y;
- unsigned char
- *pixels;
-
/*
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
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);
+ assert(exception->signature == MagickCoreSignature);
+ image=AcquireImage(image_info,exception);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
- if (DiscardBlobBytes(image,(size_t) image->offset) == MagickFalse)
+ if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
/*
Create virtual canvas to support cropping (i.e. image.gray[100x100+10+20]).
*/
+ (void) SetImageColorspace(image,GRAYColorspace,exception);
canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
exception);
- (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
+ (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
+ exception);
quantum_type=GrayQuantum;
quantum_info=AcquireQuantumInfo(image_info,canvas_image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- pixels=GetQuantumPixels(quantum_info);
+ pixels=(const unsigned char *) NULL;
if (image_info->number_scenes != 0)
while (image->scene < image_info->scene)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
for (y=0; y < (ssize_t) image->rows; y++)
{
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
if (count != (ssize_t) length)
break;
}
scene=0;
count=0;
length=0;
+ status=MagickTrue;
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,exception);
+ if (status == MagickFalse)
+ break;
+ if (SetImageColorspace(image,GRAYColorspace,exception) == MagickFalse)
+ break;
if (scene == 0)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
register const Quantum
- *restrict p;
+ *magick_restrict p;
register ssize_t
x;
register Quantum
- *restrict q;
+ *magick_restrict q;
if (count != (ssize_t) length)
{
+ status=MagickFalse;
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
}
q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,exception);
- if (q == (const Quantum *) NULL)
+ if (q == (Quantum *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
image->columns,1,exception);
q=QueueAuthenticPixels(image,0,y-image->extract_info.y,image->columns,
1,exception);
- if ((p == (const Quantum *) NULL) ||
- (q == (const Quantum *) NULL))
+ if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- SetPixelRed(image,GetPixelRed(canvas_image,p),q);
- SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
- SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
+ SetPixelGray(image,GetPixelGray(canvas_image,p),q);
p+=GetPixelChannels(canvas_image);
q+=GetPixelChannels(image);
}
if (status == MagickFalse)
break;
}
- count=ReadBlob(image,length,pixels);
+ pixels=(const unsigned char *) ReadBlobStream(image,length,
+ GetQuantumPixels(quantum_info),&count);
+ if (count != (ssize_t) length)
+ break;
}
SetQuantumImageType(image,quantum_type);
/*
/*
Allocate next image structure.
*/
- AcquireNextImage(image_info,image);
+ AcquireNextImage(image_info,image,exception);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
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);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
return(GetFirstImageInList(image));
}
\f
MagickInfo
*entry;
- entry=SetMagickInfo("GRAY");
+ entry=AcquireMagickInfo("GRAY","GRAY","Raw gray samples");
entry->decoder=(DecodeImageHandler *) ReadGRAYImage;
entry->encoder=(EncodeImageHandler *) WriteGRAYImage;
- entry->raw=MagickTrue;
- entry->endian_support=MagickTrue;
- entry->description=ConstantString("Raw gray samples");
- entry->module=ConstantString("GRAY");
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickCoreSignature);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
/*
Write grayscale pixels.
*/
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,RGBColorspace);
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
quantum_type=GrayQuantum;
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
- pixels=GetQuantumPixels(quantum_info);
+ pixels=(unsigned char *) GetQuantumPixels(quantum_info);
for (y=0; y < (ssize_t) image->rows; y++)
{
register const Quantum
- *restrict p;
+ *magick_restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)