% July 1992 %
% %
% %
-% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2011 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/cache.h"
#include "magick/color.h"
#include "magick/color-private.h"
+#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
%
% o length: Specifies the length of the magick string.
%
-%
*/
static MagickBooleanType IsVIFF(const unsigned char *magick,const size_t length)
{
char
comment[512];
- unsigned long
+ unsigned int
rows,
columns,
subrows;
- long
+ int
x_offset,
y_offset;
x_bits_per_pixel,
y_bits_per_pixel;
- unsigned long
+ unsigned int
location_type,
location_dimension,
number_of_images,
int
bit;
- long
- y;
-
MagickBooleanType
status;
register IndexPacket
*indexes;
- register long
+ register ssize_t
x;
register PixelPacket
*q;
- register long
+ register ssize_t
i;
register unsigned char
*p;
+ size_t
+ bytes_per_pixel,
+ lsb_first,
+ max_packets,
+ quantum;
+
ssize_t
- count;
+ count,
+ y;
unsigned char
buffer[7],
*viff_pixels;
- unsigned long
- bytes_per_pixel,
- lsb_first,
- max_packets,
- quantum;
-
ViffInfo
viff_info;
viff_info.rows=ReadBlobLSBLong(image);
viff_info.columns=ReadBlobLSBLong(image);
viff_info.subrows=ReadBlobLSBLong(image);
- viff_info.x_offset=(long) ReadBlobLSBLong(image);
- viff_info.y_offset=(long) ReadBlobLSBLong(image);
+ viff_info.x_offset=(int) ReadBlobLSBLong(image);
+ viff_info.y_offset=(int) ReadBlobLSBLong(image);
viff_info.x_bits_per_pixel=(float) ReadBlobLSBLong(image);
viff_info.y_bits_per_pixel=(float) ReadBlobLSBLong(image);
viff_info.location_type=ReadBlobLSBLong(image);
viff_info.rows=ReadBlobMSBLong(image);
viff_info.columns=ReadBlobMSBLong(image);
viff_info.subrows=ReadBlobMSBLong(image);
- viff_info.x_offset=(long) ReadBlobMSBLong(image);
- viff_info.y_offset=(long) ReadBlobMSBLong(image);
+ viff_info.x_offset=(int) ReadBlobMSBLong(image);
+ viff_info.y_offset=(int) ReadBlobMSBLong(image);
viff_info.x_bits_per_pixel=(float) ReadBlobMSBLong(image);
viff_info.y_bits_per_pixel=(float) ReadBlobMSBLong(image);
viff_info.location_type=ReadBlobMSBLong(image);
(void) ReadBlobByte(image);
image->columns=viff_info.rows;
image->rows=viff_info.columns;
- image->depth=viff_info.x_bits_per_pixel <= 8 ? 8UL : MAGICKCORE_QUANTUM_DEPTH;
+ image->depth=viff_info.x_bits_per_pixel <= 8 ? 8UL :
+ MAGICKCORE_QUANTUM_DEPTH;
/*
Verify that we can read this VIFF image.
*/
}
default: break;
}
- for (i=0; i < (long) (viff_info.map_rows*image->colors); i++)
+ for (i=0; i < (ssize_t) (viff_info.map_rows*image->colors); i++)
{
switch ((int) viff_info.map_storage_type)
{
case VFF_MAPTYP_DOUBLE: value=((double *) viff_colormap)[i]; break;
default: value=1.0*viff_colormap[i]; break;
}
- if (i < (long) image->colors)
+ if (i < (ssize_t) image->colors)
{
image->colormap[i].red=ScaleCharToQuantum((unsigned char) value);
image->colormap[i].green=
image->colormap[i].blue=ScaleCharToQuantum((unsigned char) value);
}
else
- if (i < (long) (2*image->colors))
+ if (i < (ssize_t) (2*image->colors))
image->colormap[i % image->colors].green=
ScaleCharToQuantum((unsigned char) value);
else
- if (i < (long) (3*image->colors))
+ if (i < (ssize_t) (3*image->colors))
image->colormap[i % image->colors].blue=
ScaleCharToQuantum((unsigned char) value);
}
if (viff_info.data_storage_type == VFF_TYP_BIT)
max_packets=((image->columns+7UL) >> 3UL)*image->rows;
else
- max_packets=(unsigned long) (number_pixels*viff_info.number_data_bands);
+ max_packets=(size_t) (number_pixels*viff_info.number_data_bands);
viff_pixels=(unsigned char *) AcquireQuantumMemory(max_packets,
bytes_per_pixel*sizeof(*viff_pixels));
if (viff_pixels == (unsigned char *) NULL)
}
max_value=value;
min_value=value;
- for (i=0; i < (long) max_packets; i++)
+ for (i=0; i < (ssize_t) max_packets; i++)
{
switch ((int) viff_info.data_storage_type)
{
Convert pixels to Quantum size.
*/
p=(unsigned char *) viff_pixels;
- for (i=0; i < (long) max_packets; i++)
+ for (i=0; i < (ssize_t) max_packets; i++)
{
switch ((int) viff_info.data_storage_type)
{
*/
(void) SetImageType(image,BilevelType);
(void) SetImageType(image,PaletteType);
- 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)
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++)
if (PixelIntensity(q) < ((MagickRealType) QuantumRange/2.0))
{
- quantum=(unsigned long) indexes[x+bit];
+ quantum=(size_t) GetIndexPixelComponent(indexes+x+bit);
quantum|=0x01;
- indexes[x+bit]=(IndexPacket) quantum;
+ SetIndexPixelComponent(indexes+x+bit,quantum);
}
p++;
}
if ((image->columns % 8) != 0)
{
- for (bit=0; bit < (long) (image->columns % 8); bit++)
+ for (bit=0; bit < (ssize_t) (image->columns % 8); bit++)
if (PixelIntensity(q) < ((MagickRealType) QuantumRange/2.0))
{
- quantum=(unsigned long) indexes[x+bit];
+ quantum=(size_t) GetIndexPixelComponent(indexes+x+bit);
quantum|=0x01;
- indexes[x+bit]=(IndexPacket) quantum;
+ SetIndexPixelComponent(indexes+x+bit,quantum);
}
p++;
}
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;
}
}
else
if (image->storage_class == PseudoClass)
- 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)
break;
indexes=GetAuthenticIndexQueue(image);
- for (x=0; x < (long) image->columns; x++)
- indexes[x]=(IndexPacket) (*p++);
+ for (x=0; x < (ssize_t) image->columns; x++)
+ SetIndexPixelComponent(indexes+x,*p++);
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;
}
Convert DirectColor scanline.
*/
number_pixels=(MagickSizeType) image->columns*image->rows;
- 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)
break;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- q->red=ScaleCharToQuantum(*p);
- q->green=ScaleCharToQuantum(*(p+number_pixels));
- q->blue=ScaleCharToQuantum(*(p+2*number_pixels));
+ SetRedPixelComponent(q,ScaleCharToQuantum(*p));
+ SetGreenPixelComponent(q,ScaleCharToQuantum(*(p+number_pixels)));
+ SetBluePixelComponent(q,ScaleCharToQuantum(*(p+2*number_pixels)));
if (image->colors != 0)
{
- q->red=image->colormap[(long) q->red].red;
- q->green=image->colormap[(long) q->green].green;
- q->blue=image->colormap[(long) q->blue].blue;
+ SetRedPixelComponent(q,image->colormap[(ssize_t)
+ GetRedPixelComponent(q)].red);
+ SetGreenPixelComponent(q,image->colormap[(ssize_t)
+ GetGreenPixelComponent(q)].green);
+ SetBluePixelComponent(q,image->colormap[(ssize_t)
+ GetBluePixelComponent(q)].blue);
}
- q->opacity=(Quantum) (image->matte ? QuantumRange-
- ScaleCharToQuantum(*(p+number_pixels*3)) : OpaqueOpacity);
+ SetOpacityPixelComponent(q,image->matte != MagickFalse ?
+ QuantumRange-ScaleCharToQuantum(*(p+number_pixels*3)) :
+ OpaqueOpacity);
p++;
q++;
}
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;
}
%
% The format of the RegisterVIFFImage method is:
%
-% unsigned long RegisterVIFFImage(void)
+% size_t RegisterVIFFImage(void)
%
*/
-ModuleExport unsigned long RegisterVIFFImage(void)
+ModuleExport size_t RegisterVIFFImage(void)
{
MagickInfo
*entry;
reserve[3],
comment[512];
- unsigned long
+ size_t
rows,
columns,
subrows;
- long
+ int
x_offset,
y_offset;
unsigned int
x_bits_per_pixel,
- y_bits_per_pixel;
-
- unsigned long
+ y_bits_per_pixel,
location_type,
location_dimension,
number_of_images,
const char
*value;
- long
- y;
-
MagickBooleanType
status;
register const PixelPacket
*p;
- register long
+ register ssize_t
x;
- register long
+ register ssize_t
i;
register unsigned char
*q;
+ ssize_t
+ y;
+
unsigned char
buffer[8],
*viff_pixels;
*viff_info.comment='\0';
value=GetImageProperty(image,"comment");
if (value != (const char *) NULL)
- (void) CopyMagickString(viff_info.comment,value,MagickMin(strlen(value),511)+1);
+ (void) CopyMagickString(viff_info.comment,value,MagickMin(strlen(value),
+ 511)+1);
viff_info.rows=image->columns;
viff_info.columns=image->rows;
viff_info.subrows=0;
viff_info.map_scheme=VFF_MS_ONEPERBAND;
viff_info.map_storage_type=VFF_MAPTYP_1_BYTE;
viff_info.map_rows=3;
- viff_info.map_columns=image->colors;
+ viff_info.map_columns=(unsigned int) image->colors;
}
else
if (image->colors <= 2)
buffer[7]=(unsigned char) viff_info.reserve[2];
(void) WriteBlob(image,8,buffer);
(void) WriteBlob(image,512,(unsigned char *) viff_info.comment);
- (void) WriteBlobMSBLong(image,viff_info.rows);
- (void) WriteBlobMSBLong(image,viff_info.columns);
- (void) WriteBlobMSBLong(image,viff_info.subrows);
- (void) WriteBlobMSBLong(image,(unsigned long) viff_info.x_offset);
- (void) WriteBlobMSBLong(image,(unsigned long) viff_info.y_offset);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.rows);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.columns);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.subrows);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.x_offset);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.y_offset);
viff_info.x_bits_per_pixel=1U*(63 << 24) | (128 << 16);
- (void) WriteBlobMSBLong(image,(unsigned long) viff_info.x_bits_per_pixel);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.x_bits_per_pixel);
viff_info.y_bits_per_pixel=1U*(63 << 24) | (128 << 16);
- (void) WriteBlobMSBLong(image,(unsigned long) viff_info.y_bits_per_pixel);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.y_bits_per_pixel);
(void) WriteBlobMSBLong(image,viff_info.location_type);
(void) WriteBlobMSBLong(image,viff_info.location_dimension);
- (void) WriteBlobMSBLong(image,viff_info.number_of_images);
- (void) WriteBlobMSBLong(image,viff_info.number_data_bands);
- (void) WriteBlobMSBLong(image,viff_info.data_storage_type);
- (void) WriteBlobMSBLong(image,viff_info.data_encode_scheme);
- (void) WriteBlobMSBLong(image,viff_info.map_scheme);
- (void) WriteBlobMSBLong(image,viff_info.map_storage_type);
- (void) WriteBlobMSBLong(image,viff_info.map_rows);
- (void) WriteBlobMSBLong(image,viff_info.map_columns);
- (void) WriteBlobMSBLong(image,viff_info.map_subrows);
- (void) WriteBlobMSBLong(image,viff_info.map_enable);
- (void) WriteBlobMSBLong(image,viff_info.maps_per_cycle);
- (void) WriteBlobMSBLong(image,viff_info.color_space_model);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.number_of_images);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.number_data_bands);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.data_storage_type);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.data_encode_scheme);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_scheme);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_storage_type);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_rows);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_columns);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_subrows);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_enable);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.maps_per_cycle);
+ (void) WriteBlobMSBLong(image,(unsigned int) viff_info.color_space_model);
for (i=0; i < 420; i++)
(void) WriteBlobByte(image,'\0');
/*
Convert DirectClass packet to VIFF RGB pixel.
*/
number_pixels=(MagickSizeType) image->columns*image->rows;
- 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;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- *q=ScaleQuantumToChar(p->red);
- *(q+number_pixels)=ScaleQuantumToChar(p->green);
- *(q+number_pixels*2)=ScaleQuantumToChar(p->blue);
+ *q=ScaleQuantumToChar(GetRedPixelComponent(p));
+ *(q+number_pixels)=ScaleQuantumToChar(GetGreenPixelComponent(p));
+ *(q+number_pixels*2)=ScaleQuantumToChar(GetBluePixelComponent(p));
if (image->matte != MagickFalse)
*(q+number_pixels*3)=ScaleQuantumToChar((Quantum)
- (QuantumRange-p->opacity));
+ (GetAlphaPixelComponent(p)));
p++;
q++;
}
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
if (viff_colormap == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
q=viff_colormap;
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
*q++=ScaleQuantumToChar(image->colormap[i].red);
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
*q++=ScaleQuantumToChar(image->colormap[i].green);
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
*q++=ScaleQuantumToChar(image->colormap[i].blue);
(void) WriteBlob(image,3*image->colors,viff_colormap);
viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap);
Convert PseudoClass packet to VIFF colormapped pixels.
*/
q=viff_pixels;
- 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++)
- *q++=(unsigned char) indexes[x];
+ for (x=0; x < (ssize_t) image->columns; x++)
+ *q++=(unsigned char) GetIndexPixelComponent(indexes+x);
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
else
if (image->colors <= 2)
{
- long
+ ssize_t
x,
y;
Convert PseudoClass image to a VIFF monochrome image.
*/
(void) SetImageType(image,BilevelType);
- 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);
indexes=GetVirtualIndexQueue(image);
bit=0;
byte=0;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
byte>>=1;
if (PixelIntensity(p) < ((MagickRealType) QuantumRange/2.0))
*q++=byte >> (8-bit);
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
+ y,image->rows);
if (status == MagickFalse)
break;
}
/*
Convert PseudoClass packet to VIFF grayscale pixel.
*/
- 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;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
*q++=(unsigned char) PixelIntensityToQuantum(p);
p++;
}
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
+ y,image->rows);
if (status == MagickFalse)
break;
}