% Read/Write RAW Gray Image Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2009 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 "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.h"
-#include "magick/pixel-private.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/statistic.h"
-#include "magick/string_.h"
-#include "magick/module.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
+#include "MagickCore/constitute.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/magick.h"
+#include "MagickCore/memory_.h"
+#include "MagickCore/monitor.h"
+#include "MagickCore/monitor-private.h"
+#include "MagickCore/pixel.h"
+#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/statistic.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
\f
/*
Forward declarations.
*/
static MagickBooleanType
- WriteGRAYImage(const ImageInfo *,Image *);
+ WriteGRAYImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadGRAYImage() reads an image of raw grayscale samples and returns
% it. It allocates the memory necessary for the new Image structure and
-% returns a pointer to the new image.
+% returns a pointer to the new image.
%
% The format of the ReadGRAYImage method is:
%
static Image *ReadGRAYImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
+ const unsigned char
+ *pixels;
+
Image
*canvas_image,
*image;
- long
- y;
-
MagickBooleanType
status;
QuantumType
quantum_type;
- register long
- i;
-
- ssize_t
- count;
-
size_t
length;
- unsigned char
- *pixels;
+ ssize_t
+ count,
+ y;
/*
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);
}
- for (i=0; i < image->offset; i++)
- if (ReadBlobByte(image) == EOF)
- {
- ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
- image->filename);
- break;
- }
+ 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)
{
*/
image->scene++;
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
- for (y=0; y < (long) image->rows; y++)
+ 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)
- {
- ThrowFileException(exception,CorruptImageError,
- "UnexpectedEndOfFile",image->filename);
- break;
- }
+ break;
}
- for (y=0; y < (long) image->extract_info.height; y++)
+ for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
- register const PixelPacket
- *__restrict p;
+ register const Quantum
+ *magick_restrict p;
- register long
+ register ssize_t
x;
- register PixelPacket
- *__restrict q;
+ register Quantum
+ *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 == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
- count=ReadBlob(image,length,pixels);
- if ((count != (ssize_t) length) &&
- (y < (long) (image->extract_info.height-1)))
- {
- ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
- image->filename);
- break;
- }
if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
+ ((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))
+ if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
break;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- q->red=p->red;
- q->green=p->green;
- q->blue=p->blue;
- p++;
- q++;
+ SetPixelGray(image,GetPixelGray(canvas_image,p),q);
+ p+=GetPixelChannels(canvas_image);
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
+ 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(exception,&canvas_image->exception);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
return(GetFirstImageInList(image));
}
\f
%
% The format of the RegisterGRAYImage method is:
%
-% unsigned long RegisterGRAYImage(void)
+% size_t RegisterGRAYImage(void)
%
*/
-ModuleExport unsigned long RegisterGRAYImage(void)
+ModuleExport size_t RegisterGRAYImage(void)
{
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->format_type=ExplicitFormatType;
- entry->description=ConstantString("Raw gray samples");
- entry->module=ConstantString("GRAY");
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
% The format of the WriteGRAYImage method is:
%
% MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
-% Image *image)
+% Image *image,ExceptionInfo *exception)
%
% A description of each parameter follows.
%
%
% o image: The image.
%
+% o exception: return any errors or warnings in this structure.
+%
*/
static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
- Image *image)
+ Image *image,ExceptionInfo *exception)
{
- long
- y;
-
MagickBooleanType
status;
QuantumType
quantum_type;
- ssize_t
- count;
-
size_t
length;
+ ssize_t
+ count,
+ y;
+
unsigned char
*pixels;
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);
- status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
+ assert(exception != (ExceptionInfo *) NULL);
+ assert(exception->signature == MagickCoreSignature);
+ status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
scene=0;
/*
Write grayscale pixels.
*/
- if (image->colorspace != RGBColorspace)
- (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);
- for (y=0; y < (long) image->rows; y++)
+ pixels=(unsigned char *) GetQuantumPixels(quantum_info);
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- register const PixelPacket
- *__restrict p;
+ register const Quantum
+ *magick_restrict p;
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
break;
- length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
- quantum_type,pixels,&image->exception);
+ length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
+ quantum_type,pixels,exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}