% July 1992 %
% %
% %
-% Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2012 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 %
20071202 TS * rewrote RLE decoder - old version could cause buffer overflows
* failure of RLE decoding now thows error RLEDecoderError
* fixed bug in RLE decoding - now all rows are decoded, not just
- the first one
- * fixed bug in reader - record offsets now handled correctly
- * fixed bug in reader - only bits 0..2 indicate compression type
+ the first one
+ * fixed bug in reader - record offsets now handled correctly
+ * fixed bug in reader - only bits 0..2 indicate compression type
* in writer: now using image color count instead of depth
*/
\f
/*
Include declarations.
*/
-#include "magick/studio.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/cache.h"
-#include "magick/colormap-private.h"
-#include "magick/color-private.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/property.h"
-#include "magick/quantum-private.h"
-#include "magick/quantum-private.h"
-#include "magick/static.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/colormap-private.h"
+#include "MagickCore/color-private.h"
+#include "MagickCore/colormap.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-accessor.h"
+#include "MagickCore/property.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
\f
/*
Typedef declarations.
attributes,
version;
- unsigned long
+ size_t
create_time,
modify_time,
archive_time,
type[4], /* database type identifier "vIMG" */
id[4]; /* database creator identifier "View" */
- unsigned long
+ size_t
seed,
next_record;
version,
type;
- unsigned long
+ size_t
reserved_1,
note;
x_last,
y_last;
- unsigned long
+ size_t
reserved_2;
short int
Forward declarations.
*/
static MagickBooleanType
- WritePDBImage(const ImageInfo *,Image *);
+ WritePDBImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#define RLE_MODE_COPY 0
#define RLE_MODE_RUN 1
- int data = 0, count = 0;
- unsigned char *p;
- int mode = RLE_MODE_NONE;
-
- for (p = pixels; p < pixels + length; p++) {
- if (0 == count) {
- data = ReadBlobByte( image );
- if (-1 == data) return MagickFalse;
- if (data > 128) {
- mode = RLE_MODE_RUN;
- count = data - 128 + 1;
- data = ReadBlobByte( image );
- if (-1 == data) return MagickFalse;
- } else {
- mode = RLE_MODE_COPY;
- count = data + 1;
- }
- }
-
- if (RLE_MODE_COPY == mode) {
- data = ReadBlobByte( image );
- if (-1 == data) return MagickFalse;
- }
- *p = (unsigned char)data;
- --count;
- }
- return MagickTrue;
+ int data = 0, count = 0;
+ unsigned char *p;
+ int mode = RLE_MODE_NONE;
+
+ for (p = pixels; p < pixels + length; p++) {
+ if (0 == count) {
+ data = ReadBlobByte( image );
+ if (-1 == data) return MagickFalse;
+ if (data > 128) {
+ mode = RLE_MODE_RUN;
+ count = data - 128 + 1;
+ data = ReadBlobByte( image );
+ if (-1 == data) return MagickFalse;
+ } else {
+ mode = RLE_MODE_COPY;
+ count = data + 1;
+ }
+ }
+
+ if (RLE_MODE_COPY == mode) {
+ data = ReadBlobByte( image );
+ if (-1 == data) return MagickFalse;
+ }
+ *p = (unsigned char)data;
+ --count;
+ }
+ return MagickTrue;
}
\f
/*
Image
*image;
- IndexPacket
- index;
-
- long
- img_offset, /* TS */
- comment_offset = 0,
- y;
-
MagickBooleanType
status;
PDBInfo
pdb_info;
- register IndexPacket
- *indexes;
+ Quantum
+ index;
- register long
+ register ssize_t
x;
- register PixelPacket
+ register Quantum
*q;
register unsigned char
*p;
+ size_t
+ bits_per_pixel,
+ num_pad_bytes, /* TS */
+ one,
+ packets;
+
ssize_t
- count;
+ count,
+ img_offset, /* TS */
+ comment_offset = 0,
+ y;
unsigned char
*pixels;
- unsigned long
- num_pad_bytes, /* TS */
- bits_per_pixel,
- packets;
-
/*
Open image file.
*/
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
- image=AcquireImage(image_info);
+ image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
/*
Read record header.
*/
- img_offset=(long) ReadBlobMSBLong(image); /* TS */
+ img_offset=(int) ReadBlobMSBLong(image); /* TS */
attributes=(unsigned char) ReadBlobByte(image);
+ (void) attributes;
count=ReadBlob(image,3,(unsigned char *) tag);
if (count != 3 || memcmp(tag,"\x6f\x80\x00",3) != 0)
ThrowReaderException(CorruptImageError,"CorruptImage");
-
if (pdb_info.number_records > 1)
{
- comment_offset=(long) ReadBlobMSBLong(image);
+ comment_offset=(int) ReadBlobMSBLong(image);
attributes=(unsigned char) ReadBlobByte(image);
count=ReadBlob(image,3,(unsigned char *) tag);
if (count != 3 || memcmp(tag,"\x6f\x80\x01",3) != 0)
ThrowReaderException(CorruptImageError,"CorruptImage");
}
-
- num_pad_bytes = (unsigned long) (img_offset - TellBlob( image ));
+ num_pad_bytes = (size_t) (img_offset - TellBlob( image ));
while (num_pad_bytes--) ReadBlobByte( image );
/*
Read image header.
/*
Initialize image structure.
*/
- image->columns=(unsigned long) pdb_image.width;
- image->rows=(unsigned long) pdb_image.height;
+ image->columns=(size_t) pdb_image.width;
+ image->rows=(size_t) pdb_image.height;
image->depth=8;
image->storage_class=PseudoClass;
bits_per_pixel=pdb_image.type == 0 ? 2UL : pdb_image.type == 2 ? 4UL : 1UL;
- if (AcquireImageColormap(image,1 << bits_per_pixel) == MagickFalse)
+ one=1;
+ if (AcquireImageColormap(image,one << bits_per_pixel,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
{
image->compression=RLECompression;
if (!DecodeImage(image, pixels, packets * image -> rows))
- ThrowReaderException( CorruptImageError, "RLEDecoderError" ); /* TS */
+ ThrowReaderException( CorruptImageError, "RLEDecoderError" ); /* TS */
break;
}
default:
ThrowReaderException(CorruptImageError,
- "UnrecognizedImageCompressionType" );
+ "UnrecognizedImageCompressionType" );
}
p=pixels;
switch (bits_per_pixel)
/*
Read 1-bit PDB image.
*/
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
- for (x=0; x < ((long) image->columns-7); x+=8)
+ for (x=0; x < ((ssize_t) image->columns-7); x+=8)
{
for (bit=0; bit < 8; bit++)
{
- index=(IndexPacket) (*p & (0x80 >> bit) ? 0x00 : 0x01);
- indexes[x+bit]=index;
- *q++=image->colormap[(long) index];
+ index=(Quantum) (*p & (0x80 >> bit) ? 0x00 : 0x01);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
}
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
+ (void) SyncImage(image,exception);
break;
}
case 2:
/*
Read 2-bit PDB image.
*/
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
- for (x=0; x < (long) image->columns; x+=4)
+ for (x=0; x < (ssize_t) image->columns; x+=4)
{
- index=ConstrainColormapIndex(image,3UL-((*p >> 6) & 0x03));
- indexes[x]=index;
- *q++=image->colormap[(long) index];
- index=ConstrainColormapIndex(image,3UL-((*p >> 4) & 0x03));
- indexes[x+1]=index;
- *q++=image->colormap[(long) index];
- index=ConstrainColormapIndex(image,3UL-((*p >> 2) & 0x03));
- indexes[x+2]=index;
- *q++=image->colormap[(long) index];
- index=ConstrainColormapIndex(image,3UL-((*p) & 0x03));
- indexes[x+3]=index;
- *q++=image->colormap[(long) index];
+ index=ConstrainColormapIndex(image,3UL-((*p >> 6) & 0x03),exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
+ index=ConstrainColormapIndex(image,3UL-((*p >> 4) & 0x03),exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
+ index=ConstrainColormapIndex(image,3UL-((*p >> 2) & 0x03),exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
+ index=ConstrainColormapIndex(image,3UL-((*p) & 0x03),exception);
+ SetPixelIndex(image,index,q);
p++;
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
+ (void) SyncImage(image,exception);
break;
}
case 4:
/*
Read 4-bit PDB image.
*/
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
- for (x=0; x < (long) image->columns; x+=2)
+ for (x=0; x < (ssize_t) image->columns; x+=2)
{
- index=ConstrainColormapIndex(image,15UL-((*p >> 4) & 0x0f));
- indexes[x]=index;
- *q++=image->colormap[(long) index];
- index=ConstrainColormapIndex(image,15UL-((*p) & 0x0f));
- indexes[x+1]=index;
- *q++=image->colormap[(long) index];
+ index=ConstrainColormapIndex(image,15UL-((*p >> 4) & 0x0f),exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
+ index=ConstrainColormapIndex(image,15UL-((*p) & 0x0f),exception);
+ SetPixelIndex(image,index,q);
p++;
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
+ (void) SyncImage(image,exception);
break;
}
default:
register char
*p;
- unsigned long
+ size_t
length;
- num_pad_bytes = (unsigned long) (comment_offset - TellBlob( image ));
+ num_pad_bytes = (size_t) (comment_offset - TellBlob( image ));
while (num_pad_bytes--) ReadBlobByte( image );
/*
*p='\0';
if (comment == (char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- (void) SetImageProperty(image,"comment",comment);
+ (void) SetImageProperty(image,"comment",comment,exception);
comment=DestroyString(comment);
}
(void) CloseBlob(image);
%
% The format of the RegisterPDBImage method is:
%
-% unsigned long RegisterPDBImage(void)
+% size_t RegisterPDBImage(void)
%
*/
-ModuleExport unsigned long RegisterPDBImage(void)
+ModuleExport size_t RegisterPDBImage(void)
{
MagickInfo
*entry;
%
% The format of the WritePDBImage method is:
%
-% MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WritePDBImage(const ImageInfo *image_info,
+% 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 unsigned char *EncodeRLE(unsigned char *destination,
- unsigned char *source,unsigned long literal,unsigned long repeat)
+ unsigned char *source,size_t literal,size_t repeat)
{
if (literal > 0)
*destination++=(unsigned char) (literal-1);
return(destination);
}
-static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
+static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
{
const char
*comment;
int
bits;
- long
- y;
-
MagickBooleanType
status;
QuantumInfo
*quantum_info;
- register const PixelPacket
+ register const Quantum
*p;
- register long
+ register ssize_t
x;
register unsigned char
*q;
size_t
- packet_size;
+ bits_per_pixel,
+ literal,
+ packets,
+ packet_size,
+ repeat;
+
+ ssize_t
+ y;
unsigned char
*buffer,
*runlength,
*scanline;
- unsigned long
- bits_per_pixel,
- literal,
- packets,
- repeat;
-
/*
Open output image file.
*/
assert(image->signature == MagickSignature);
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 == MagickSignature);
+ status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
- if (image->colorspace != RGBColorspace)
- (void) TransformImageColorspace(image,RGBColorspace);
+ if (IsRGBColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,RGBColorspace,exception);
- if (image -> colors <= 2 || GetImageType( image, &image -> exception ) == BilevelType) { /* TS */
+ if (image -> colors <= 2 || GetImageType( image, exception ) == BilevelType) { /* TS */
bits_per_pixel = 1;
} else if (image -> colors <= 4) {
bits_per_pixel = 2;
(void) CopyMagickMemory(pdb_info.id,"View",4);
pdb_info.seed=0;
pdb_info.next_record=0;
- comment=GetImageProperty(image,"comment");
+ comment=GetImageProperty(image,"comment",exception);
pdb_info.number_records=(comment == (const char *) NULL ? 1 : 2);
(void) WriteBlob(image,32,(unsigned char *) pdb_info.name);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_info.attributes);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_info.version);
- (void) WriteBlobMSBLong(image,pdb_info.create_time);
- (void) WriteBlobMSBLong(image,pdb_info.modify_time);
- (void) WriteBlobMSBLong(image,pdb_info.archive_time);
- (void) WriteBlobMSBLong(image,pdb_info.modify_number);
- (void) WriteBlobMSBLong(image,pdb_info.application_info);
- (void) WriteBlobMSBLong(image,pdb_info.sort_info);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.create_time);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_time);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.archive_time);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_number);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.application_info);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.sort_info);
(void) WriteBlob(image,4,(unsigned char *) pdb_info.type);
(void) WriteBlob(image,4,(unsigned char *) pdb_info.id);
- (void) WriteBlobMSBLong(image,(unsigned long) pdb_info.seed);
- (void) WriteBlobMSBLong(image,(unsigned long) pdb_info.next_record);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.seed);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.next_record);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_info.number_records);
(void) CopyMagickString(pdb_image.name,pdb_info.name,32);
pdb_image.version=1; /* RLE Compressed */
sizeof(*scanline));
if (scanline == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
- if (image->colorspace != RGBColorspace)
- (void) TransformImageColorspace(image,RGBColorspace);
+ if (IsRGBColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,RGBColorspace,exception);
/*
Convert to GRAY raster scanline.
*/
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
- bits=8/(long) bits_per_pixel-1; /* start at most significant bits */
+ bits=8/(int) bits_per_pixel-1; /* start at most significant bits */
literal=0;
repeat=0;
q=runlength;
buffer[0]=0x00;
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- 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;
- (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
- GrayQuantum,scanline,&image->exception);
+ (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
+ GrayQuantum,scanline,exception);
for (x=0; x < pdb_image.width; x++)
{
- if (x < (long) image->columns)
+ if (x < (ssize_t) image->columns)
buffer[literal+repeat]|=(0xff-scanline[x*packet_size]) >>
(8-bits_per_pixel) << bits*bits_per_pixel;
bits--;
literal-=0x80;
}
}
- bits=8/(long) bits_per_pixel-1;
+ bits=8/(int) bits_per_pixel-1;
buffer[literal+repeat]=0x00;
}
}
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
/*
Write the Image record header.
*/
- (void) WriteBlobMSBLong(image,(unsigned long)
+ (void) WriteBlobMSBLong(image,(unsigned int)
(TellBlob(image)+8*pdb_info.number_records));
(void) WriteBlobByte(image,0x40);
(void) WriteBlobByte(image,0x6f);
/*
Write the comment record header.
*/
- (void) WriteBlobMSBLong(image,(unsigned long) (TellBlob(image)+8+58+q-
+ (void) WriteBlobMSBLong(image,(unsigned int) (TellBlob(image)+8+58+q-
runlength));
(void) WriteBlobByte(image,0x40);
(void) WriteBlobByte(image,0x6f);
(void) WriteBlob(image,32,(unsigned char *) pdb_image.name);
(void) WriteBlobByte(image,(unsigned char) pdb_image.version);
(void) WriteBlobByte(image,(unsigned char) pdb_image.type);
- (void) WriteBlobMSBLong(image,pdb_image.reserved_1);
- (void) WriteBlobMSBLong(image,pdb_image.note);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_1);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.note);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.x_last);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.y_last);
- (void) WriteBlobMSBLong(image,pdb_image.reserved_2);
+ (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_2);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.x_anchor);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.y_anchor);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.width);