% Read/Write Apple Macintosh QuickDraw/PICT Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 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 %
ThrowReaderException(CorruptImageError,"ImproperImageHeader"); \
}
-#define ReadRectangle(image,rectangle) \
-{ \
- rectangle.top=(short) ReadBlobMSBShort(image); \
- rectangle.left=(short) ReadBlobMSBShort(image); \
- rectangle.bottom=(short) ReadBlobMSBShort(image); \
- rectangle.right=(short) ReadBlobMSBShort(image); \
- if ((rectangle.left > rectangle.right) || \
- (rectangle.top > rectangle.bottom)) \
- ThrowReaderException(CorruptImageError,"ImproperImageHeader"); \
-}
-
typedef struct _PICTCode
{
const char
return(y);
}
+static MagickBooleanType ReadRectangle(Image *image,PICTRectangle *rectangle)
+{
+ rectangle->top=(short) ReadBlobMSBShort(image);
+ rectangle->left=(short) ReadBlobMSBShort(image);
+ rectangle->bottom=(short) ReadBlobMSBShort(image);
+ rectangle->right=(short) ReadBlobMSBShort(image);
+ if ((rectangle->left > rectangle->right) ||
+ (rectangle->top > rectangle->bottom))
+ return(MagickFalse);
+ return(MagickTrue);
+}
+
static Image *ReadPICTImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
image=AcquireImage(image_info,exception);
- image->depth=8;
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
for (i=0; i < 508; i++)
(void) ReadBlobByte(image);
(void) ReadBlobMSBShort(image); /* skip picture size */
- ReadRectangle(image,frame);
+ if (ReadRectangle(image,&frame) == MagickFalse)
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
while ((c=ReadBlobByte(image)) == 0) ;
if (c != 0x11)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
Create black canvas.
*/
flags=0;
+ image->depth=8;
image->columns=1UL*(frame.right-frame.left);
image->rows=1UL*(frame.bottom-frame.top);
image->resolution.x=DefaultResolution;
code=ReadBlobByte(image);
if (version == 2)
code=(int) ReadBlobMSBShort(image);
+ if (code < 0)
+ break;
if (code > 0xa1)
{
if (image->debug != MagickFalse)
(void) ReadBlobByte(image);
break;
}
- ReadRectangle(image,frame);
+ if (ReadRectangle(image,&frame) == MagickFalse)
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if (((frame.left & 0x8000) != 0) || ((frame.top & 0x8000) != 0))
break;
image->columns=1UL*(frame.right-frame.left);
if (pattern != 1)
ThrowReaderException(CorruptImageError,"UnknownPatternType");
length=ReadBlobMSBShort(image);
- ReadRectangle(image,frame);
+ if (ReadRectangle(image,&frame) == MagickFalse)
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
ReadPixmap(pixmap);
image->depth=1UL*pixmap.component_size;
image->resolution.x=1.0*pixmap.horizontal_resolution;
(void) ReadBlobMSBShort(image);
(void) ReadBlobMSBShort(image);
}
- ReadRectangle(image,frame);
+ if (ReadRectangle(image,&frame) == MagickFalse)
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/*
Initialize tile image.
*/
}
}
}
- ReadRectangle(image,source);
- ReadRectangle(image,destination);
+ if (ReadRectangle(image,&source) == MagickFalse)
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+ if (ReadRectangle(image,&destination) == MagickFalse)
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) ReadBlobMSBShort(image);
if ((code == 0x91) || (code == 0x99) || (code == 0x9b))
{
/*
Skip to next op code.
*/
+ if (code < 0)
+ break;
if (codes[code].length == -1)
(void) ReadBlobMSBShort(image);
else
file=fdopen(unique_file,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
{
+ if (file != (FILE *) NULL)
+ (void) fclose(file);
(void) CopyMagickString(image->filename,read_info->filename,
MaxTextExtent);
ThrowFileException(exception,FileOpenError,
length=ReadBlobMSBLong(image);
for (i=0; i < 6; i++)
(void) ReadBlobMSBLong(image);
- ReadRectangle(image,frame);
+ if (ReadRectangle(image,&frame) == MagickFalse)
+ {
+ (void) fclose(file);
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+ }
for (i=0; i < 122; i++)
(void) ReadBlobByte(image);
for (i=0; i < (ssize_t) (length-154); i++)
(void) fputc(c,file);
}
(void) fclose(file);
+ (void) close(unique_file);
tile_image=ReadImage(read_info,exception);
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
(void) SetImageExtent(image,
MagickMax(image->columns,tile_image->columns),
MagickMax(image->rows,tile_image->rows),exception);
- if (IssRGBCompatibleColorspace(tile_image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,tile_image->colorspace,
- exception);
+ (void) TransformImageColorspace(image,tile_image->colorspace,exception);
(void) CompositeImage(image,tile_image,CopyCompositeOp,MagickTrue,
frame.left,frame.right,exception);
image->compression=tile_image->compression;
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
- if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,sRGBColorspace,exception);
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
/*
Initialize image info.
*/
storage_class=image->storage_class;
if (image_info->compression == JPEGCompression)
storage_class=DirectClass;
- if ((storage_class == DirectClass) || (image->alpha_trait == BlendPixelTrait))
+ if (storage_class == DirectClass)
{
- pixmap.component_count=image->alpha_trait ? 4 : 3;
+ pixmap.component_count=image->alpha_trait == BlendPixelTrait ? 4 : 3;
pixmap.pixel_type=16;
pixmap.bits_per_pixel=32;
pixmap.pack_type=0x04;
Allocate memory.
*/
bytes_per_line=image->columns;
- if ((storage_class == DirectClass) || (image->alpha_trait == BlendPixelTrait))
- bytes_per_line*=image->alpha_trait ? 4 : 3;
+ if (storage_class == DirectClass)
+ bytes_per_line*=image->alpha_trait == BlendPixelTrait ? 4 : 3;
buffer=(unsigned char *) AcquireQuantumMemory(PictInfoSize,sizeof(*buffer));
packed_scanline=(unsigned char *) AcquireQuantumMemory((size_t)
(row_bytes+MaxCount),sizeof(*packed_scanline));
Write picture data.
*/
count=0;
- if ((storage_class == PseudoClass) && (image->alpha_trait != BlendPixelTrait))
+ if (storage_class == PseudoClass)
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,exception);