% July 1992 %
% %
% %
-% Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2010 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 %
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
+#include "magick/colormap.h"
+#include "magick/colormap-private.h"
#include "magick/colorspace.h"
#include "magick/composite.h"
#include "magick/constitute.h"
const char
*name;
- long
+ ssize_t
length;
const char
version,
pack_type;
- unsigned long
+ size_t
pack_size,
horizontal_resolution,
vertical_resolution;
component_count,
component_size;
- unsigned long
+ size_t
plane_bytes,
table,
reserved;
/* 0x0b */ { "OvSize", 4, "oval size (point)" },
/* 0x0c */ { "Origin", 4, "dh, dv (word)" },
/* 0x0d */ { "TxSize", 2, "text size (word)" },
- /* 0x0e */ { "FgColor", 4, "foreground color (longword)" },
- /* 0x0f */ { "BkColor", 4, "background color (longword)" },
+ /* 0x0e */ { "FgColor", 4, "foreground color (ssize_tword)" },
+ /* 0x0f */ { "BkColor", 4, "background color (ssize_tword)" },
/* 0x10 */ { "TxRatio", 8, "numerator (point), denominator (point)" },
/* 0x11 */ { "Version", 1, "version (byte)" },
/* 0x12 */ { "BkPixPat", 0, "color background pattern" },
% The format of the DecodeImage method is:
%
% unsigned char *DecodeImage(Image *blob,Image *image,
-% unsigned long bytes_per_line,const int bits_per_pixel,
+% size_t bytes_per_line,const int bits_per_pixel,
% unsigned size_t extent)
%
% A description of each parameter follows:
static unsigned char *ExpandBuffer(unsigned char *pixels,
MagickSizeType *bytes_per_line,const unsigned int bits_per_pixel)
{
- register long
+ register ssize_t
i;
register unsigned char
return(pixels);
case 4:
{
- for (i=0; i < (long) *bytes_per_line; i++)
+ for (i=0; i < (ssize_t) *bytes_per_line; i++)
{
*q++=(*p >> 4) & 0xff;
*q++=(*p & 15);
}
case 2:
{
- for (i=0; i < (long) *bytes_per_line; i++)
+ for (i=0; i < (ssize_t) *bytes_per_line; i++)
{
*q++=(*p >> 6) & 0x03;
*q++=(*p >> 4) & 0x03;
}
case 1:
{
- for (i=0; i < (long) *bytes_per_line; i++)
+ for (i=0; i < (ssize_t) *bytes_per_line; i++)
{
*q++=(*p >> 7) & 0x01;
*q++=(*p >> 6) & 0x01;
}
static unsigned char *DecodeImage(Image *blob,Image *image,
- unsigned long bytes_per_line,const unsigned int bits_per_pixel,size_t *extent)
+ size_t bytes_per_line,const unsigned int bits_per_pixel,size_t *extent)
{
- long
+ ssize_t
j,
y;
MagickSizeType
number_pixels;
- register long
+ register ssize_t
i;
register unsigned char
*pixels,
*scanline;
- unsigned long
+ size_t
bytes_per_pixel,
scanline_length,
width;
/*
Pixels are already uncompressed.
*/
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=pixels+y*width;
number_pixels=bytes_per_line;
/*
Uncompress RLE pixels into uncompressed pixel buffer.
*/
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=pixels+y*width;
if (bytes_per_line > 200)
break;
}
count=ReadBlob(blob,scanline_length,scanline);
- for (j=0; j < (long) scanline_length; )
+ for (j=0; j < (ssize_t) scanline_length; )
if ((scanline[j] & 0x80) == 0)
{
length=(size_t) ((scanline[j] & 0xff)+1);
if ((q-pixels+number_pixels) <= *extent)
(void) CopyMagickMemory(q,p,(size_t) number_pixels);
q+=number_pixels;
- j+=(long) (length*bytes_per_pixel+1);
+ j+=(ssize_t) (length*bytes_per_pixel+1);
}
else
{
length=(size_t) (((scanline[j] ^ 0xff) & 0xff)+2);
number_pixels=bytes_per_pixel;
p=ExpandBuffer(scanline+j+1,&number_pixels,bits_per_pixel);
- for (i=0; i < (long) length; i++)
+ for (i=0; i < (ssize_t) length; i++)
{
if ((q-pixels+number_pixels) <= *extent)
(void) CopyMagickMemory(q,p,(size_t) number_pixels);
q+=number_pixels;
}
- j+=bytes_per_pixel+1;
+ j+=(ssize_t) bytes_per_pixel+1;
}
}
scanline=(unsigned char *) RelinquishMagickMemory(scanline);
% The format of the EncodeImage method is:
%
% size_t EncodeImage(Image *image,const unsigned char *scanline,
-% const unsigned long bytes_per_line,unsigned char *pixels)
+% const size_t bytes_per_line,unsigned char *pixels)
%
% A description of each parameter follows:
%
% o pixels: A pointer to an array of characters where the packed
% characters are stored.
%
-%
*/
static size_t EncodeImage(Image *image,const unsigned char *scanline,
- const unsigned long bytes_per_line,unsigned char *pixels)
+ const size_t bytes_per_line,unsigned char *pixels)
{
#define MaxCount 128
#define MaxPackbitsRunlength 128
- long
+ ssize_t
count,
repeat_count,
runlength;
register const unsigned char
*p;
- register long
+ register ssize_t
i;
register unsigned char
p=scanline+(bytes_per_line-1);
q=pixels;
index=(*p);
- for (i=(long) bytes_per_line-1; i >= 0; i--)
+ for (i=(ssize_t) bytes_per_line-1; i >= 0; i--)
{
if (index == *p)
runlength++;
%
% o length: Specifies the length of the magick string.
%
-%
*/
static MagickBooleanType IsPICT(const unsigned char *magick,const size_t length)
{
%
*/
-static inline unsigned long MagickMax(const unsigned long x,
- const unsigned long y)
+static inline size_t MagickMax(const size_t x,
+ const size_t y)
{
if (x > y)
return(x);
c,
code;
- long
+ ssize_t
flags,
j,
version,
register IndexPacket
*indexes;
- register long
+ register ssize_t
x;
register PixelPacket
*q;
- register long
+ register ssize_t
i;
size_t
length=ReadBlobMSBShort(image);
if (length != 0x000a)
{
- for (i=0; i < (long) (length-2); i++)
+ for (i=0; i < (ssize_t) (length-2); i++)
(void) ReadBlobByte(image);
break;
}
case 0x13:
case 0x14:
{
- long
+ ssize_t
pattern;
- unsigned long
+ size_t
height,
width;
(void) ReadBlobMSBLong(image);
flags=1L*ReadBlobMSBShort(image);
length=ReadBlobMSBShort(image);
- for (i=0; i <= (long) length; i++)
+ for (i=0; i <= (ssize_t) length; i++)
(void) ReadBlobMSBLong(image);
width=1UL*(frame.bottom-frame.top);
height=1UL*(frame.right-frame.left);
length=width;
if (length < 8)
{
- for (i=0; i < (long) (length*height); i++)
+ for (i=0; i < (ssize_t) (length*height); i++)
(void) ReadBlobByte(image);
}
else
for (j=0; j < (int) height; j++)
if (length > 200)
- for (j=0; j < (long) ReadBlobMSBShort(image); j++)
+ for (j=0; j < (ssize_t) ReadBlobMSBShort(image); j++)
(void) ReadBlobByte(image);
else
- for (j=0; j < (long) ReadBlobByte(image); j++)
+ for (j=0; j < (ssize_t) ReadBlobByte(image); j++)
(void) ReadBlobByte(image);
break;
}
Skip polygon or region.
*/
length=ReadBlobMSBShort(image);
- for (i=0; i < (long) (length-2); i++)
+ for (i=0; i < (ssize_t) (length-2); i++)
(void) ReadBlobByte(image);
break;
}
case 0x9a:
case 0x9b:
{
- long
+ ssize_t
bytes_per_line;
PICTRectangle
}
if ((bytes_per_line & 0x8000) != 0)
{
- for (i=0; i < (long) tile_image->colors; i++)
+ for (i=0; i < (ssize_t) tile_image->colors; i++)
{
j=ReadBlobMSBShort(image) % tile_image->colors;
if ((flags & 0x8000) != 0)
}
else
{
- for (i=0; i < (long) tile_image->colors; i++)
+ for (i=0; i < (ssize_t) tile_image->colors; i++)
{
tile_image->colormap[i].red=(Quantum) (QuantumRange-
tile_image->colormap[i].red);
Skip region.
*/
length=ReadBlobMSBShort(image);
- for (i=0; i < (long) (length-2); i++)
+ for (i=0; i < (ssize_t) (length-2); i++)
(void) ReadBlobByte(image);
}
if ((code != 0x9a) && (code != 0x9b) &&
Convert PICT tile image to pixel packets.
*/
p=pixels;
- for (y=0; y < (long) tile_image->rows; y++)
+ for (y=0; y < (ssize_t) tile_image->rows; y++)
{
if (p > (pixels+extent+image->columns))
ThrowReaderException(CorruptImageError,"NotEnoughPixelData");
- q=QueueAuthenticPixels(tile_image,0,y,tile_image->columns,1,exception);
+ q=QueueAuthenticPixels(tile_image,0,y,tile_image->columns,1,
+ exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(tile_image);
- for (x=0; x < (long) tile_image->columns; x++)
+ for (x=0; x < (ssize_t) tile_image->columns; x++)
{
if (tile_image->storage_class == PseudoClass)
{
index=ConstrainColormapIndex(tile_image,*p);
indexes[x]=index;
- q->red=tile_image->colormap[(long) index].red;
- q->green=tile_image->colormap[(long) index].green;
- q->blue=tile_image->colormap[(long) index].blue;
+ q->red=tile_image->colormap[(ssize_t) index].red;
+ q->green=tile_image->colormap[(ssize_t) index].green;
+ q->blue=tile_image->colormap[(ssize_t) index].blue;
}
else
{
unsigned char
*info;
- unsigned long
+ size_t
type;
/*
if (codes[code].length == -1)
(void) ReadBlobMSBShort(image);
else
- for (i=0; i < (long) codes[code].length; i++)
+ for (i=0; i < (ssize_t) codes[code].length; i++)
(void) ReadBlobByte(image);
}
}
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(read_info->filename);
if (unique_file != -1)
- file=OpenMagickStream(read_info->filename,"wb");
+ file=fdopen(unique_file,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
{
(void) CopyMagickString(image->filename,read_info->filename,
ReadRectangle(image,frame);
for (i=0; i < 122; i++)
(void) ReadBlobByte(image);
- for (i=0; i < (long) (length-154); i++)
+ for (i=0; i < (ssize_t) (length-154); i++)
{
c=ReadBlobByte(image);
(void) fputc(c,file);
read_info=DestroyImageInfo(read_info);
if (tile_image == (Image *) NULL)
continue;
- (void) FormatMagickString(geometry,MaxTextExtent,"%lux%lu",
+ (void) FormatMagickString(geometry,MaxTextExtent,"%.20gx%.20g",
+ (double) MagickMax(image->columns,tile_image->columns),
+ (double) MagickMax(image->rows,tile_image->rows));
+ (void) SetImageExtent(image,
MagickMax(image->columns,tile_image->columns),
MagickMax(image->rows,tile_image->rows));
- (void) TransformImage(&image,(char *) NULL,geometry);
if (image->colorspace != RGBColorspace)
(void) TransformImageColorspace(image,tile_image->colorspace);
(void) CompositeImage(image,CopyCompositeOp,tile_image,frame.left,
Skip reserved.
*/
length=ReadBlobMSBShort(image);
- for (i=0; i < (long) length; i++)
+ for (i=0; i < (ssize_t) length; i++)
(void) ReadBlobByte(image);
continue;
}
Skip reserved.
*/
length=(size_t) ((code >> 7) & 0xff);
- for (i=0; i < (long) length; i++)
+ for (i=0; i < (ssize_t) length; i++)
(void) ReadBlobByte(image);
continue;
}
%
% The format of the RegisterPICTImage method is:
%
-% unsigned long RegisterPICTImage(void)
+% size_t RegisterPICTImage(void)
%
*/
-ModuleExport unsigned long RegisterPICTImage(void)
+ModuleExport size_t RegisterPICTImage(void)
{
MagickInfo
*entry;
%
% The format of the WritePICTImage method is:
%
-% MagickBooleanType WritePICTImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WritePICTImage(const ImageInfo *image_info,
+% Image *image)
%
% A description of each parameter follows.
%
%
% o image: The image.
%
-%
*/
static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
Image *image)
x_resolution,
y_resolution;
- long
+ ssize_t
y;
MagickBooleanType
register const PixelPacket
*p;
- register long
+ register ssize_t
i,
x;
*packed_scanline,
*scanline;
- unsigned long
+ size_t
bytes_per_line,
storage_class;
{
(void) WriteBlobMSBShort(image,0xa1);
(void) WriteBlobMSBShort(image,0x1f2);
- (void) WriteBlobMSBShort(image,(unsigned short) (GetStringInfoLength(profile)+4));
+ (void) WriteBlobMSBShort(image,(unsigned short)
+ (GetStringInfoLength(profile)+4));
(void) WriteBlobString(image,"8BIM");
- (void) WriteBlob(image,GetStringInfoLength(profile),GetStringInfoDatum(profile));
+ (void) WriteBlob(image,GetStringInfoLength(profile),
+ GetStringInfoDatum(profile));
}
profile=GetImageProfile(image,"icc");
if (profile != (StringInfo *) NULL)
{
(void) WriteBlobMSBShort(image,0xa1);
(void) WriteBlobMSBShort(image,0xe0);
- (void) WriteBlobMSBShort(image,(unsigned short) (GetStringInfoLength(profile)+4));
+ (void) WriteBlobMSBShort(image,(unsigned short)
+ (GetStringInfoLength(profile)+4));
(void) WriteBlobMSBLong(image,0x00000000UL);
- (void) WriteBlob(image,GetStringInfoLength(profile),GetStringInfoDatum(profile));
+ (void) WriteBlob(image,GetStringInfoLength(profile),
+ GetStringInfoDatum(profile));
(void) WriteBlobMSBShort(image,0xa1);
(void) WriteBlobMSBShort(image,0xe0);
(void) WriteBlobMSBShort(image,4);
return(MagickFalse);
jpeg_image=DestroyImage(jpeg_image);
(void) WriteBlobMSBShort(image,PictJPEGOp);
- (void) WriteBlobMSBLong(image,(unsigned long) length+154);
+ (void) WriteBlobMSBLong(image,(unsigned int) length+154);
(void) WriteBlobMSBShort(image,0x0000);
(void) WriteBlobMSBLong(image,0x00010000UL);
(void) WriteBlobMSBLong(image,0x00000000UL);
else
{
(void) WriteBlobMSBShort(image,PictPixmapOp);
- (void) WriteBlobMSBLong(image,(unsigned long) base_address);
+ (void) WriteBlobMSBLong(image,(size_t) base_address);
}
(void) WriteBlobMSBShort(image,(unsigned short) (row_bytes | 0x8000));
(void) WriteBlobMSBShort(image,(unsigned short) bounds.top);
*/
(void) WriteBlobMSBShort(image,(unsigned short) pixmap.version);
(void) WriteBlobMSBShort(image,(unsigned short) pixmap.pack_type);
- (void) WriteBlobMSBLong(image,pixmap.pack_size);
+ (void) WriteBlobMSBLong(image,(unsigned int) pixmap.pack_size);
(void) WriteBlobMSBShort(image,(unsigned short) (x_resolution+0.5));
(void) WriteBlobMSBShort(image,0x0000);
(void) WriteBlobMSBShort(image,(unsigned short) (y_resolution+0.5));
*/
(void) WriteBlobMSBShort(image,(unsigned short) pixmap.component_count);
(void) WriteBlobMSBShort(image,(unsigned short) pixmap.component_size);
- (void) WriteBlobMSBLong(image,(unsigned long) pixmap.plane_bytes);
- (void) WriteBlobMSBLong(image,(unsigned long) pixmap.table);
- (void) WriteBlobMSBLong(image,(unsigned long) pixmap.reserved);
+ (void) WriteBlobMSBLong(image,(unsigned int) pixmap.plane_bytes);
+ (void) WriteBlobMSBLong(image,(unsigned int) pixmap.table);
+ (void) WriteBlobMSBLong(image,(unsigned int) pixmap.reserved);
if (storage_class == PseudoClass)
{
/*
(void) WriteBlobMSBLong(image,0x00000000L); /* color seed */
(void) WriteBlobMSBShort(image,0L); /* color flags */
(void) WriteBlobMSBShort(image,(unsigned short) (image->colors-1));
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
(void) WriteBlobMSBShort(image,(unsigned short) i);
(void) WriteBlobMSBShort(image,ScaleQuantumToShort(
*/
count=0;
if ((storage_class == PseudoClass) && (image->matte == MagickFalse))
- 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)
break;
indexes=GetVirtualIndexQueue(image);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
scanline[x]=(unsigned char) indexes[x];
- count+=EncodeImage(image,scanline,(unsigned long) (row_bytes & 0x7FFF),
+ count+=EncodeImage(image,scanline,(size_t) (row_bytes & 0x7FFF),
packed_scanline);
- if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
- (QuantumTick(y,image->rows) != MagickFalse))
+ if (image->previous == (Image *) NULL)
{
- status=image->progress_monitor(SaveImageTag,y,image->rows,
- image->client_data);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
if (image_info->compression == JPEGCompression)
{
(void) ResetMagickMemory(scanline,0,row_bytes);
- for (y=0; y < (long) image->rows; y++)
- count+=EncodeImage(image,scanline,(unsigned long)
+ for (y=0; y < (ssize_t) image->rows; y++)
+ count+=EncodeImage(image,scanline,(size_t)
(row_bytes & 0x7FFF),packed_scanline);
}
else
green=scanline+image->columns;
blue=scanline+2*image->columns;
opacity=scanline+3*image->columns;
- 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)
green=scanline+2*image->columns;
blue=scanline+3*image->columns;
}
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- *red++=ScaleQuantumToChar(p->red);
- *green++=ScaleQuantumToChar(p->green);
- *blue++=ScaleQuantumToChar(p->blue);
+ *red++=ScaleQuantumToChar(GetRedPixelComponent(p));
+ *green++=ScaleQuantumToChar(GetGreenPixelComponent(p));
+ *blue++=ScaleQuantumToChar(GetBluePixelComponent(p));
if (image->matte != MagickFalse)
*opacity++=ScaleQuantumToChar((Quantum)
- (QuantumRange-p->opacity));
+ (GetAlphaPixelComponent(p)));
p++;
}
count+=EncodeImage(image,scanline,bytes_per_line & 0x7FFF,
packed_scanline);
- if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
- (QuantumTick(y,image->rows) != MagickFalse))
+ if (image->previous == (Image *) NULL)
{
- status=image->progress_monitor(SaveImageTag,y,image->rows,
- image->client_data);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}