% December 2001 %
% %
% %
-% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2013 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 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/exception.h"
-#include "magick/exception-private.h"
-#include "magick/image.h"
-#include "magick/image-private.h"
-#include "magick/list.h"
-#include "magick/log.h"
-#include "magick/magick.h"
-#include "magick/memory_.h"
-#include "magick/monitor.h"
-#include "magick/monitor-private.h"
-#include "magick/profile.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/module.h"
-#include "magick/transform.h"
+#include "MagickCore/studio.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/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/log.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/profile.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
+#include "MagickCore/transform.h"
\f
/*
Macro definitions (from Windows wingdi.h).
#define BI_JPEG 4
#undef BI_PNG
#define BI_PNG 5
-#if !defined(__WINDOWS__) || defined(__MINGW32__)
+#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__) || defined(__MINGW64__)
+#undef BI_RGB
#define BI_RGB 0
+#undef BI_RLE8
#define BI_RLE8 1
+#undef BI_RLE4
#define BI_RLE4 2
+#undef BI_BITFIELDS
#define BI_BITFIELDS 3
+#undef LCS_CALIBRATED_RBG
#define LCS_CALIBRATED_RBG 0
+#undef LCS_sRGB
#define LCS_sRGB 1
+#undef LCS_WINDOWS_COLOR_SPACE
#define LCS_WINDOWS_COLOR_SPACE 2
+#undef PROFILE_LINKED
#define PROFILE_LINKED 3
+#undef PROFILE_EMBEDDED
#define PROFILE_EMBEDDED 4
+#undef LCS_GM_BUSINESS
#define LCS_GM_BUSINESS 1 /* Saturation */
+#undef LCS_GM_GRAPHICS
#define LCS_GM_GRAPHICS 2 /* Relative */
+#undef LCS_GM_IMAGES
#define LCS_GM_IMAGES 4 /* Perceptual */
+#undef LCS_GM_ABS_COLORIMETRIC
#define LCS_GM_ABS_COLORIMETRIC 8 /* Absolute */
#endif
\f
offset_bits,
size;
- long
+ int
width,
height;
Forward declarations.
*/
static MagickBooleanType
- WriteBMPImage(const ImageInfo *,Image *);
+ WriteBMPImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The format of the DecodeImage method is:
%
% MagickBooleanType DecodeImage(Image *image,
-% const unsigned long compression,unsigned char *pixels)
+% const size_t compression,unsigned char *pixels)
%
% A description of each parameter follows:
%
%
*/
-static inline long MagickAbsoluteValue(const long x)
+static inline ssize_t MagickAbsoluteValue(const ssize_t x)
{
if (x < 0)
return(-x);
return(y);
}
-static inline long MagickMin(const long x,const long y)
+static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
{
if (x < y)
return(x);
return(y);
}
-static MagickBooleanType DecodeImage(Image *image,
- const unsigned long compression,unsigned char *pixels)
+static MagickBooleanType DecodeImage(Image *image,const size_t compression,
+ unsigned char *pixels)
{
- int
- count;
-
- long
- y;
-
- register long
+ register ssize_t
i,
x;
*p,
*q;
+ ssize_t
+ count,
+ y;
+
unsigned char
byte;
x=0;
p=pixels;
q=pixels+(size_t) image->columns*image->rows;
- for (y=0; y < (long) image->rows; )
+ for (y=0; y < (ssize_t) image->rows; )
{
if ((p < pixels) || (p >= q))
break;
- count=ReadBlobByte(image);
- if (count == EOF)
+ count=(ssize_t) ReadBlobByte(image);
+ if ((int) count == EOF)
break;
if (count != 0)
{
/*
Encoded mode.
*/
- count=MagickMin(count,(int) (q-p));
+ count=MagickMin(count,(ssize_t) (q-p));
byte=(unsigned char) ReadBlobByte(image);
if (compression == BI_RLE8)
{
/*
Escape mode.
*/
- count=ReadBlobByte(image);
+ count=(ssize_t) ReadBlobByte(image);
if (count == 0x01)
return(MagickTrue);
switch (count)
/*
Absolute mode.
*/
- count=MagickMin(count,(int) (q-p));
+ count=MagickMin(count,(ssize_t) (q-p));
if (compression == BI_RLE8)
for (i=0; i < count; i++)
*p++=(unsigned char) ReadBlobByte(image);
}
}
}
- if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
+ if (SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,image->rows) == MagickFalse)
break;
}
(void) ReadBlobByte(image); /* end of line */
% The format of the EncodeImage method is:
%
% static MagickBooleanType EncodeImage(Image *image,
-% const unsigned long bytes_per_line,const unsigned char *pixels,
+% const size_t bytes_per_line,const unsigned char *pixels,
% unsigned char *compressed_pixels)
%
% A description of each parameter follows:
% pixel data.
%
*/
-static size_t EncodeImage(Image *image,const unsigned long bytes_per_line,
+static size_t EncodeImage(Image *image,const size_t bytes_per_line,
const unsigned char *pixels,unsigned char *compressed_pixels)
{
- long
- y;
-
MagickBooleanType
status;
register const unsigned char
*p;
- register long
+ register ssize_t
i,
x;
register unsigned char
*q;
+ ssize_t
+ y;
+
/*
Runlength encode pixels.
*/
p=pixels;
q=compressed_pixels;
i=0;
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
- for (x=0; x < (long) bytes_per_line; x+=i)
+ for (x=0; x < (ssize_t) bytes_per_line; x+=i)
{
/*
Determine runlength.
*/
- for (i=1; ((x+i) < (long) bytes_per_line); i++)
+ for (i=1; ((x+i) < (ssize_t) bytes_per_line); i++)
if ((i == 255) || (*(p+i) != *p))
break;
*q++=(unsigned char) i;
*/
*q++=(unsigned char) 0x00;
*q++=(unsigned char) 0x00;
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
Image
*image;
- IndexPacket
- index;
-
- long
- y;
-
MagickBooleanType
+ mapped,
status;
MagickOffsetType
offset,
start_position;
- register IndexPacket
- *indexes;
-
- register long
- x;
+ Quantum
+ index;
- register PixelPacket
+ register Quantum
*q;
- register long
- i;
+ register ssize_t
+ i,
+ x;
register unsigned char
*p;
- ssize_t
- count;
-
size_t
- length;
-
- unsigned char
- magick[12],
- *pixels;
-
- unsigned long
bit,
blue,
bytes_per_line,
green,
+ length,
opacity,
red;
+ ssize_t
+ count,
+ y;
+
+ unsigned char
+ magick[12],
+ *pixels;
+
/*
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)
{
count=ReadBlob(image,2,magick);
do
{
- LongPixelPacket
- shift;
+ PixelInfo
+ quantum_bits;
PixelPacket
- quantum_bits;
+ shift;
- unsigned long
+ size_t
profile_data,
profile_size;
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Format: OS/2 Bitmap");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Geometry: %ldx%ld",bmp_info.width,bmp_info.height);
+ " Geometry: %.20gx%.20g",(double) bmp_info.width,(double)
+ bmp_info.height);
}
}
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Format: MS Windows bitmap");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Geometry: %ldx%ld",bmp_info.width,bmp_info.height);
+ " Geometry: %.20gx%.20g",(double) bmp_info.width,(double)
+ bmp_info.height);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Bits per pixel: %d",bmp_info.bits_per_pixel);
+ " Bits per pixel: %.20g",(double) bmp_info.bits_per_pixel);
switch ((int) bmp_info.compression)
{
case BI_RGB:
bmp_info.blue_mask=ReadBlobLSBLong(image);
if (bmp_info.size > 40)
{
+
double
sum;
Read color management information.
*/
bmp_info.alpha_mask=ReadBlobLSBLong(image);
- bmp_info.colorspace=(long) ReadBlobLSBLong(image);
+ bmp_info.colorspace=(int) ReadBlobLSBLong(image);
/*
Decode 2^30 fixed point formatted CIE primaries.
*/
- bmp_info.red_primary.x=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.red_primary.y=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.red_primary.z=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.green_primary.x=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.green_primary.y=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.green_primary.z=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.blue_primary.x=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.blue_primary.y=(double) ReadBlobLSBLong(image)/0x3ffffff;
- bmp_info.blue_primary.z=(double) ReadBlobLSBLong(image)/0x3ffffff;
- sum=bmp_info.red_primary.x+bmp_info.red_primary.x+
+# define BMP_DENOM ((double) 0x40000000)
+ bmp_info.red_primary.x=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.red_primary.y=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.red_primary.z=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.green_primary.x=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.green_primary.y=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.green_primary.z=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.blue_primary.x=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.blue_primary.y=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+ bmp_info.blue_primary.z=(double) ReadBlobLSBLong(image)/BMP_DENOM;
+
+ sum=bmp_info.red_primary.x+bmp_info.red_primary.y+
bmp_info.red_primary.z;
- image->chromaticity.red_primary.x/=sum;
- image->chromaticity.red_primary.y/=sum;
- sum=bmp_info.green_primary.x+bmp_info.green_primary.x+
+ bmp_info.red_primary.x/=sum;
+ bmp_info.red_primary.y/=sum;
+ image->chromaticity.red_primary.x=bmp_info.red_primary.x;
+ image->chromaticity.red_primary.y=bmp_info.red_primary.y;
+
+ sum=bmp_info.green_primary.x+bmp_info.green_primary.y+
bmp_info.green_primary.z;
- image->chromaticity.green_primary.x/=sum;
- image->chromaticity.green_primary.y/=sum;
- sum=bmp_info.blue_primary.x+bmp_info.blue_primary.x+
+ bmp_info.green_primary.x/=sum;
+ bmp_info.green_primary.y/=sum;
+ image->chromaticity.green_primary.x=bmp_info.green_primary.x;
+ image->chromaticity.green_primary.y=bmp_info.green_primary.y;
+
+ sum=bmp_info.blue_primary.x+bmp_info.blue_primary.y+
bmp_info.blue_primary.z;
- image->chromaticity.blue_primary.x/=sum;
- image->chromaticity.blue_primary.y/=sum;
+ bmp_info.blue_primary.x/=sum;
+ bmp_info.blue_primary.y/=sum;
+ image->chromaticity.blue_primary.x=bmp_info.blue_primary.x;
+ image->chromaticity.blue_primary.y=bmp_info.blue_primary.y;
+
/*
Decode 16^16 fixed point formatted gamma_scales.
*/
- bmp_info.gamma_scale.x=(double) ReadBlobLSBLong(image)/0xffff;
- bmp_info.gamma_scale.y=(double) ReadBlobLSBLong(image)/0xffff;
- bmp_info.gamma_scale.z=(double) ReadBlobLSBLong(image)/0xffff;
+ bmp_info.gamma_scale.x=(double) ReadBlobLSBLong(image)/0x10000;
+ bmp_info.gamma_scale.y=(double) ReadBlobLSBLong(image)/0x10000;
+ bmp_info.gamma_scale.z=(double) ReadBlobLSBLong(image)/0x10000;
/*
Compute a single gamma from the BMP 3-channel gamma.
*/
image->gamma=(bmp_info.gamma_scale.x+bmp_info.gamma_scale.y+
bmp_info.gamma_scale.z)/3.0;
}
+
if (bmp_info.size > 108)
{
- unsigned long
+ size_t
intent;
/*
}
profile_data=ReadBlobLSBLong(image);
profile_size=ReadBlobLSBLong(image);
+ (void) profile_data;
+ (void) profile_size;
(void) ReadBlobLSBLong(image); /* Reserved byte */
}
}
- if ((bmp_info.compression != BI_RGB) &&
- ((MagickSizeType) bmp_info.file_size != GetBlobSize(image)))
+ if ((MagickSizeType) bmp_info.file_size > GetBlobSize(image))
(void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
"LengthAndFilesizeDoNotMatch","`%s'",image->filename);
+ else
+ if ((MagickSizeType) bmp_info.file_size < GetBlobSize(image))
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ CorruptImageWarning,"LengthAndFilesizeDoNotMatch","`%s'",
+ image->filename);
if (bmp_info.width <= 0)
ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
if (bmp_info.height == 0)
(bmp_info.bits_per_pixel != 8) && (bmp_info.bits_per_pixel != 16) &&
(bmp_info.bits_per_pixel != 24) && (bmp_info.bits_per_pixel != 32))
ThrowReaderException(CorruptImageError,"UnrecognizedBitsPerPixel");
- if (bmp_info.number_colors > (1U << bmp_info.bits_per_pixel))
+ if (bmp_info.bits_per_pixel < 16 &&
+ bmp_info.number_colors > (1U << bmp_info.bits_per_pixel))
{
- if (bmp_info.bits_per_pixel < 24)
- ThrowReaderException(CorruptImageError,"UnrecognizedNumberOfColors");
- bmp_info.number_colors=0;
+ ThrowReaderException(CorruptImageError,
+ "UnrecognizedNumberOfColors");
}
- if (bmp_info.compression > 3)
- ThrowReaderException(CorruptImageError,"UnrecognizedImageCompression");
if ((bmp_info.compression == 1) && (bmp_info.bits_per_pixel != 8))
ThrowReaderException(CorruptImageError,"UnrecognizedBitsPerPixel");
if ((bmp_info.compression == 2) && (bmp_info.bits_per_pixel != 4))
default:
ThrowReaderException(CorruptImageError,"UnrecognizedImageCompression");
}
- image->columns=(unsigned long) MagickAbsoluteValue(bmp_info.width);
- image->rows=(unsigned long) MagickAbsoluteValue(bmp_info.height);
+ image->columns=(size_t) MagickAbsoluteValue((ssize_t) bmp_info.width);
+ image->rows=(size_t) MagickAbsoluteValue((ssize_t) bmp_info.height);
image->depth=bmp_info.bits_per_pixel <= 8 ? bmp_info.bits_per_pixel : 8;
- image->matte=bmp_info.alpha_mask != 0 ? MagickTrue : MagickFalse;
- if ((bmp_info.number_colors != 0) || (bmp_info.bits_per_pixel < 16))
+ image->alpha_trait=(bmp_info.alpha_mask != 0) &&
+ (bmp_info.compression == BI_BITFIELDS) ? BlendPixelTrait :
+ UndefinedPixelTrait;
+ if (bmp_info.bits_per_pixel < 16)
{
+ size_t
+ one;
+
image->storage_class=PseudoClass;
image->colors=bmp_info.number_colors;
+ one=1;
if (image->colors == 0)
- image->colors=1L << bmp_info.bits_per_pixel;
+ image->colors=one << bmp_info.bits_per_pixel;
}
if (image->storage_class == PseudoClass)
{
*/
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Reading colormap of %ld colors",image->colors);
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ " Reading colormap of %.20g colors",(double) image->colors);
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
bmp_colormap=(unsigned char *) AcquireQuantumMemory((size_t)
image->colors,4*sizeof(*bmp_colormap));
if (count != (ssize_t) (packet_size*image->colors))
ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
p=bmp_colormap;
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) image->colors; i++)
{
- image->colormap[i].blue=ScaleCharToQuantum(*p++);
- image->colormap[i].green=ScaleCharToQuantum(*p++);
- image->colormap[i].red=ScaleCharToQuantum(*p++);
+ image->colormap[i].blue=(MagickRealType) ScaleCharToQuantum(*p++);
+ image->colormap[i].green=(MagickRealType) ScaleCharToQuantum(*p++);
+ image->colormap[i].red=(MagickRealType) ScaleCharToQuantum(*p++);
if (packet_size == 4)
p++;
}
bmp_colormap=(unsigned char *) RelinquishMagickMemory(bmp_colormap);
}
+ image->resolution.x=(double) bmp_info.x_pixels/100.0;
+ image->resolution.y=(double) bmp_info.y_pixels/100.0;
+ image->units=PixelsPerCentimeterResolution;
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
bmp_info.bits_per_pixel<<=1;
bytes_per_line=4*((image->columns*bmp_info.bits_per_pixel+31)/32);
length=(size_t) bytes_per_line*image->rows;
- pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->rows,
- MagickMax(bytes_per_line,image->columns+256UL)*sizeof(*pixels));
- if (pixels == (unsigned char *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ mapped=MagickFalse;
if ((bmp_info.compression == BI_RGB) ||
(bmp_info.compression == BI_BITFIELDS))
{
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Reading pixels (%ld bytes)",(long) length);
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
+ " Reading pixels (%.20g bytes)",(double) length);
+ if (GetBlobStreamData(image) != (unsigned char *) NULL)
+ {
+ mapped=MagickTrue;
+ pixels=GetBlobStreamData(image)+TellBlob(image);
+ if (DiscardBlobBytes(image,length) == MagickFalse)
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
+ }
+ else
+ {
+ pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->rows,
+ MagickMax(bytes_per_line,image->columns)*sizeof(*pixels));
+ if (pixels == (unsigned char *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ count=ReadBlob(image,length,pixels);
+ if (count != (ssize_t) length)
+ {
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
+ }
+ }
}
else
{
/*
Convert run-length encoded raster pixels.
*/
+ pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->rows,
+ MagickMax(bytes_per_line,image->columns+256UL)*sizeof(*pixels));
+ if (pixels == (unsigned char *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
status=DecodeImage(image,bmp_info.compression,pixels);
if (status == MagickFalse)
- ThrowReaderException(CorruptImageError,
- "UnableToRunlengthDecodeImage");
+ {
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ ThrowReaderException(CorruptImageError,
+ "UnableToRunlengthDecodeImage");
+ }
}
- /*
- Initialize image structure.
- */
- image->x_resolution=(double) bmp_info.x_pixels/100.0;
- image->y_resolution=(double) bmp_info.y_pixels/100.0;
- image->units=PixelsPerCentimeterResolution;
/*
Convert BMP raster image to pixel packets.
*/
if (bmp_info.compression == BI_RGB)
{
- bmp_info.alpha_mask=0;
+ bmp_info.alpha_mask=image->alpha_trait == BlendPixelTrait ?
+ 0xff000000U : 0U;
bmp_info.red_mask=0x00ff0000U;
bmp_info.green_mask=0x0000ff00U;
bmp_info.blue_mask=0x000000ffU;
}
if ((bmp_info.bits_per_pixel == 16) || (bmp_info.bits_per_pixel == 32))
{
- register unsigned long
+ register size_t
sample;
/*
while (((bmp_info.blue_mask << shift.blue) & 0x80000000UL) == 0)
shift.blue++;
if (bmp_info.alpha_mask != 0)
- while (((bmp_info.alpha_mask << shift.opacity) & 0x80000000UL) == 0)
- shift.opacity++;
+ while (((bmp_info.alpha_mask << shift.alpha) & 0x80000000UL) == 0)
+ shift.alpha++;
sample=shift.red;
while (((bmp_info.red_mask << sample) & 0x80000000UL) != 0)
sample++;
- quantum_bits.red=(Quantum) (sample-shift.red);
+ quantum_bits.red=(MagickRealType) (sample-shift.red);
sample=shift.green;
while (((bmp_info.green_mask << sample) & 0x80000000UL) != 0)
sample++;
- quantum_bits.green=(Quantum) (sample-shift.green);
+ quantum_bits.green=(MagickRealType) (sample-shift.green);
sample=shift.blue;
while (((bmp_info.blue_mask << sample) & 0x80000000UL) != 0)
sample++;
- quantum_bits.blue=(Quantum) (sample-shift.blue);
- sample=shift.opacity;
+ quantum_bits.blue=(MagickRealType) (sample-shift.blue);
+ sample=shift.alpha;
while (((bmp_info.alpha_mask << sample) & 0x80000000UL) != 0)
sample++;
- quantum_bits.opacity=(Quantum) (sample-shift.opacity);
+ quantum_bits.alpha=(MagickRealType) (sample-shift.alpha);
}
switch (bmp_info.bits_per_pixel)
{
/*
Convert bitmap scanline.
*/
- for (y=(long) image->rows-1; y >= 0; y--)
+ for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=pixels+(image->rows-y-1)*bytes_per_line;
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)) != 0 ? 0x01 : 0x00);
- indexes[x+bit]=index;
- *q++=image->colormap[(long) index];
+ index=(Quantum) (((*p) & (0x80 >> bit)) != 0 ? 0x01 : 0x00);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
}
p++;
}
{
for (bit=0; bit < (image->columns % 8); bit++)
{
- index=(IndexPacket) (((*p) & (0x80 >> bit)) != 0 ? 0x01 : 0x00);
- indexes[x+bit]=index;
- *q++=image->colormap[(long) index];
+ index=(Quantum) (((*p) & (0x80 >> bit)) != 0 ? 0x01 : 0x00);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
}
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;
}
}
+ (void) SyncImage(image,exception);
break;
}
case 4:
/*
Convert PseudoColor scanline.
*/
- for (y=(long) image->rows-1; y >= 0; y--)
+ for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=pixels+(image->rows-y-1)*bytes_per_line;
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-1); x+=2)
+ for (x=0; x < ((ssize_t) image->columns-1); x+=2)
{
- index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f);
- indexes[x]=index;
- *q++=image->colormap[(long) index];
- index=ConstrainColormapIndex(image,*p & 0x0f);
- indexes[x+1]=index;
- *q++=image->colormap[(long) index];
+ index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f,exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
+ index=ConstrainColormapIndex(image,*p & 0x0f,exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
p++;
}
if ((image->columns % 2) != 0)
{
- index=ConstrainColormapIndex(image,(*p >> 4) & 0xf);
- indexes[x]=index;
- *q++=image->colormap[(long) index];
+ index=ConstrainColormapIndex(image,(*p >> 4) & 0xf,exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
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;
}
}
+ (void) SyncImage(image,exception);
break;
}
case 8:
if ((bmp_info.compression == BI_RLE8) ||
(bmp_info.compression == BI_RLE4))
bytes_per_line=image->columns;
- for (y=(long) image->rows-1; y >= 0; y--)
+ for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=pixels+(image->rows-y-1)*bytes_per_line;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
- for (x = (long)image->columns; x != 0; --x)
+ for (x=(ssize_t) image->columns; x != 0; --x)
{
- index=ConstrainColormapIndex(image,*p);
- *indexes++=index;
- *q=image->colormap[(long) index];
- p++;
- q++;
+ index=ConstrainColormapIndex(image,*p++,exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
offset=(MagickOffsetType) (image->rows-y-1);
if (image->previous == (Image *) NULL)
{
- 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 16:
{
- unsigned long
+ size_t
pixel;
/*
*/
if (bmp_info.compression != BI_RGB &&
bmp_info.compression != BI_BITFIELDS)
- ThrowReaderException(CorruptImageError,
- "UnrecognizedImageCompression");
+ {
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ ThrowReaderException(CorruptImageError,
+ "UnrecognizedImageCompression");
+ }
bytes_per_line=2*(image->columns+image->columns % 2);
image->storage_class=DirectClass;
- for (y=(long) image->rows-1; y >= 0; y--)
+ for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=pixels+(image->rows-y-1)*bytes_per_line;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- pixel=(unsigned long) (*p++);
+ pixel=(size_t) (*p++);
pixel|=(*p++) << 8;
red=((pixel & bmp_info.red_mask) << shift.red) >> 16;
if (quantum_bits.red == 5)
blue|=((blue & 0xe000) >> 5);
if (quantum_bits.blue <= 8)
blue|=((blue & 0xff00) >> 8);
- opacity=((pixel & bmp_info.alpha_mask) << shift.opacity) >> 16;
- if (quantum_bits.opacity <= 8)
+ opacity=((pixel & bmp_info.alpha_mask) << shift.alpha) >> 16;
+ if (quantum_bits.alpha <= 8)
opacity|=((opacity & 0xff00) >> 8);
- q->red=ScaleShortToQuantum((unsigned short) red);
- q->green=ScaleShortToQuantum((unsigned short) green);
- q->blue=ScaleShortToQuantum((unsigned short) blue);
- SetOpacityPixelComponent(q,OpaqueOpacity);
- if (image->matte != MagickFalse)
- q->opacity=ScaleShortToQuantum((unsigned short) opacity);
- q++;
+ SetPixelRed(image,ScaleShortToQuantum((unsigned short) red),q);
+ SetPixelGreen(image,ScaleShortToQuantum((unsigned short) green),q);
+ SetPixelBlue(image,ScaleShortToQuantum((unsigned short) blue),q);
+ SetPixelAlpha(image,OpaqueAlpha,q);
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,
+ ScaleShortToQuantum((unsigned short) opacity),q);
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
offset=(MagickOffsetType) (image->rows-y-1);
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.
*/
bytes_per_line=4*((image->columns*24+31)/32);
- for (y=(long) image->rows-1; y >= 0; y--)
+ for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=pixels+(image->rows-y-1)*bytes_per_line;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- q->blue=ScaleCharToQuantum(*p++);
- q->green=ScaleCharToQuantum(*p++);
- q->red=ScaleCharToQuantum(*p++);
- q++;
+ SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+ SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+ SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+ SetPixelAlpha(image,OpaqueAlpha,q);
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
offset=(MagickOffsetType) (image->rows-y-1);
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
*/
if ((bmp_info.compression != BI_RGB) &&
(bmp_info.compression != BI_BITFIELDS))
- ThrowReaderException(CorruptImageError,
- "UnrecognizedImageCompression");
+ {
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ ThrowReaderException(CorruptImageError,
+ "UnrecognizedImageCompression");
+ }
bytes_per_line=4*(image->columns);
- for (y=(long) image->rows-1; y >= 0; y--)
+ for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
- unsigned long
+ size_t
pixel;
p=pixels+(image->rows-y-1)*bytes_per_line;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- pixel=(unsigned long) (*p++);
+ pixel=(size_t) (*p++);
pixel|=(*p++ << 8);
pixel|=(*p++ << 16);
pixel|=(*p++ << 24);
blue=((pixel & bmp_info.blue_mask) << shift.blue) >> 16;
if (quantum_bits.blue == 8)
blue|=(blue >> 8);
- opacity=((pixel & bmp_info.alpha_mask) << shift.opacity) >> 16;
- if (quantum_bits.opacity == 8)
+ opacity=((pixel & bmp_info.alpha_mask) << shift.alpha) >> 16;
+ if (quantum_bits.alpha == 8)
opacity|=(opacity >> 8);
- q->red=ScaleShortToQuantum((unsigned short) red);
- q->green=ScaleShortToQuantum((unsigned short) green);
- q->blue=ScaleShortToQuantum((unsigned short) blue);
- SetOpacityPixelComponent(q,OpaqueOpacity);
- if (image->matte != MagickFalse)
- q->opacity=ScaleShortToQuantum((unsigned short) opacity);
- q++;
+ SetPixelRed(image,ScaleShortToQuantum((unsigned short) red),q);
+ SetPixelGreen(image,ScaleShortToQuantum((unsigned short) green),q);
+ SetPixelBlue(image,ScaleShortToQuantum((unsigned short) blue),q);
+ SetPixelAlpha(image,OpaqueAlpha,q);
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,
+ ScaleShortToQuantum((unsigned short) opacity),q);
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
offset=(MagickOffsetType) (image->rows-y-1);
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
break;
}
default:
+ {
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+ }
}
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
Correct image orientation.
*/
flipped_image=FlipImage(image,exception);
- if (flipped_image == (Image *) NULL)
+ if (flipped_image != (Image *) NULL)
{
- image=DestroyImageList(image);
- return((Image *) NULL);
+ DuplicateBlob(flipped_image,image);
+ image=DestroyImage(image);
+ image=flipped_image;
}
- DuplicateBlob(flipped_image,image);
- image=DestroyImage(image);
- image=flipped_image;
}
/*
Proceed to next image.
/*
Acquire next image structure.
*/
- AcquireNextImage(image_info,image);
+ AcquireNextImage(image_info,image,exception);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
%
% The format of the RegisterBMPImage method is:
%
-% unsigned long RegisterBMPImage(void)
+% size_t RegisterBMPImage(void)
%
*/
-ModuleExport unsigned long RegisterBMPImage(void)
+ModuleExport size_t RegisterBMPImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("BMP2");
entry->encoder=(EncodeImageHandler *) WriteBMPImage;
entry->magick=(IsImageFormatHandler *) IsBMP;
- entry->description=ConstantString("Microsoft Windows bitmap image v2");
+ entry->description=ConstantString("Microsoft Windows bitmap image (V2)");
entry->module=ConstantString("BMP");
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry=SetMagickInfo("BMP3");
entry->encoder=(EncodeImageHandler *) WriteBMPImage;
entry->magick=(IsImageFormatHandler *) IsBMP;
- entry->description=ConstantString("Microsoft Windows bitmap image v3");
+ entry->description=ConstantString("Microsoft Windows bitmap image (V3)");
entry->module=ConstantString("BMP");
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
%
% The format of the WriteBMPImage method is:
%
-% MagickBooleanType WriteBMPImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WriteBMPImage(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 MagickBooleanType WriteBMPImage(const ImageInfo *image_info,Image *image)
+static MagickBooleanType WriteBMPImage(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
{
BMPInfo
bmp_info;
const StringInfo
*profile;
- long
- y;
-
MagickBooleanType
have_color_info,
status;
MagickOffsetType
scene;
- register const IndexPacket
- *indexes;
-
- register const PixelPacket
+ register const Quantum
*p;
- register long
+ register ssize_t
i,
x;
register unsigned char
*q;
+ size_t
+ bytes_per_line,
+ type;
+
+ ssize_t
+ y;
+
unsigned char
*bmp_data,
*pixels;
- unsigned long
- bytes_per_line,
- type;
-
/*
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);
type=4;
/*
Initialize BMP raster file header.
*/
- if (image->colorspace != RGBColorspace)
- (void) TransformImageColorspace(image,RGBColorspace);
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
(void) ResetMagickMemory(&bmp_info,0,sizeof(bmp_info));
bmp_info.file_size=14+12;
if (type > 2)
bmp_info.offset_bits=bmp_info.file_size;
bmp_info.compression=BI_RGB;
if ((image->storage_class == PseudoClass) && (image->colors > 256))
- (void) SetImageStorageClass(image,DirectClass);
+ (void) SetImageStorageClass(image,DirectClass,exception);
if (image->storage_class != DirectClass)
{
/*
if (image_info->compression == RLECompression)
bmp_info.bits_per_pixel=8;
bmp_info.number_colors=1U << bmp_info.bits_per_pixel;
- if (image->matte != MagickFalse)
- (void) SetImageStorageClass(image,DirectClass);
+ if (image->alpha_trait == BlendPixelTrait)
+ (void) SetImageStorageClass(image,DirectClass,exception);
else
- if ((unsigned long) bmp_info.number_colors < image->colors)
- (void) SetImageStorageClass(image,DirectClass);
+ if ((size_t) bmp_info.number_colors < image->colors)
+ (void) SetImageStorageClass(image,DirectClass,exception);
else
{
bmp_info.file_size+=3*(1UL << bmp_info.bits_per_pixel);
*/
bmp_info.number_colors=0;
bmp_info.bits_per_pixel=(unsigned short)
- ((type > 3) && (image->matte != MagickFalse) ? 32 : 24);
+ ((type > 3) && (image->alpha_trait == BlendPixelTrait) ? 32 : 24);
bmp_info.compression=(unsigned int) ((type > 3) &&
- (image->matte != MagickFalse) ? BI_BITFIELDS : BI_RGB);
+ (image->alpha_trait == BlendPixelTrait) ? BI_BITFIELDS : BI_RGB);
}
bytes_per_line=4*((image->columns*bmp_info.bits_per_pixel+31)/32);
bmp_info.ba_offset=0;
if (type == 2)
bmp_info.size=12;
else
- if ((type == 3) || ((image->matte == MagickFalse) &&
+ if ((type == 3) || ((image->alpha_trait != BlendPixelTrait) &&
(have_color_info == MagickFalse)))
{
type=3;
bmp_info.file_size+=extra_size;
bmp_info.offset_bits+=extra_size;
}
- bmp_info.width=(long) image->columns;
- bmp_info.height=(long) image->rows;
+ bmp_info.width=(int) image->columns;
+ bmp_info.height=(int) image->rows;
bmp_info.planes=1;
bmp_info.image_size=(unsigned int) (bytes_per_line*image->rows);
bmp_info.file_size+=bmp_info.image_size;
case UndefinedResolution:
case PixelsPerInchResolution:
{
- bmp_info.x_pixels=(unsigned int) (100.0*image->x_resolution/2.54);
- bmp_info.y_pixels=(unsigned int) (100.0*image->y_resolution/2.54);
+ bmp_info.x_pixels=(unsigned int) (100.0*image->resolution.x/2.54);
+ bmp_info.y_pixels=(unsigned int) (100.0*image->resolution.y/2.54);
break;
}
case PixelsPerCentimeterResolution:
{
- bmp_info.x_pixels=(unsigned int) (100.0*image->x_resolution);
- bmp_info.y_pixels=(unsigned int) (100.0*image->y_resolution);
+ bmp_info.x_pixels=(unsigned int) (100.0*image->resolution.x);
+ bmp_info.y_pixels=(unsigned int) (100.0*image->resolution.y);
break;
}
}
{
case 1:
{
- unsigned long
+ size_t
bit,
byte;
/*
Convert PseudoClass image to a BMP monochrome image.
*/
- 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)
+ ssize_t
+ offset;
+
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
break;
- indexes=GetVirtualIndexQueue(image);
q=pixels+(image->rows-y-1)*bytes_per_line;
bit=0;
byte=0;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
byte<<=1;
- byte|=indexes[x] != 0 ? 0x01 : 0x00;
+ byte|=GetPixelIndex(image,p) != 0 ? 0x01 : 0x00;
bit++;
if (bit == 8)
{
bit=0;
byte=0;
}
+ p+=GetPixelChannels(image);
}
if (bit != 0)
{
*q++=(unsigned char) (byte << (8-bit));
x++;
}
- for (x=(long) (image->columns+7)/8; x < (long) bytes_per_line; x++)
+ offset=(ssize_t) (image->columns+7)/8;
+ for (x=offset; x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,y,image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
}
case 4:
{
- unsigned long
- nibble,
- byte;
+ ssize_t
+ offset;
+
+ size_t
+ byte,
+ nibble;
/*
Convert PseudoClass image to a BMP monochrome image.
*/
- 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;
- indexes=GetVirtualIndexQueue(image);
q=pixels+(image->rows-y-1)*bytes_per_line;
nibble=0;
byte=0;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
byte<<=4;
- byte|=((unsigned long) indexes[x] & 0x0f);
+ byte|=((size_t) GetPixelIndex(image,p) & 0x0f);
nibble++;
if (nibble == 2)
{
nibble=0;
byte=0;
}
- }
- if (nibble != 0)
- {
- *q++=(unsigned char) (byte << 4);
- x++;
- }
- for (x=(long) (image->columns+1)/2; x < (long) bytes_per_line; x++)
+ p+=GetPixelChannels(image);
+ }
+ if (nibble != 0)
+ {
+ *q++=(unsigned char) (byte << 4);
+ x++;
+ }
+ offset=(ssize_t) (image->columns+1)/2;
+ for (x=offset; x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
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 BMP 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)
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
break;
- indexes=GetVirtualIndexQueue(image);
q=pixels+(image->rows-y-1)*bytes_per_line;
- for (x=0; x < (long) image->columns; x++)
- *q++=(unsigned char) indexes[x];
- for ( ; x < (long) bytes_per_line; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ *q++=(unsigned char) GetPixelIndex(image,p);
+ p+=GetPixelChannels(image);
+ }
+ for ( ; x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
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 DirectClass packet to BMP BGR888.
*/
- 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;
q=pixels+(image->rows-y-1)*bytes_per_line;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
- *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
- *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
- p++;
+ *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+ *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+ *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+ p+=GetPixelChannels(image);
}
- for (x=3L*(long) image->columns; x < (long) bytes_per_line; x++)
+ for (x=3L*(ssize_t) image->columns; x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
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 DirectClass packet to ARGB8888 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)
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
break;
q=pixels+(image->rows-y-1)*bytes_per_line;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
- *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
- *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
- *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
- *q++=ScaleQuantumToChar(GetOpacityPixelComponent(p));
- p++;
+ *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+ *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+ *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+ *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
+ p+=GetPixelChannels(image);
}
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 (image->debug != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Writing BMP version %ld datastream",type);
+ " Writing BMP version %.20g datastream",(double) type);
if (image->storage_class == DirectClass)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Storage class=DirectClass");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Storage class=PseudoClass");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Image depth=%lu",image->depth);
- if (image->matte != MagickFalse)
+ " Image depth=%.20g",(double) image->depth);
+ if (image->alpha_trait == BlendPixelTrait)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Matte=True");
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Matte=MagickFalse");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " BMP bits_per_pixel=%d",bmp_info.bits_per_pixel);
+ " BMP bits_per_pixel=%.20g",(double) bmp_info.bits_per_pixel);
switch ((int) bmp_info.compression)
{
case BI_RGB:
(void) WriteBlobLSBLong(image,bmp_info.number_colors);
(void) WriteBlobLSBLong(image,bmp_info.colors_important);
}
- if ((type > 3) && ((image->matte != MagickFalse) ||
+ if ((type > 3) && ((image->alpha_trait == BlendPixelTrait) ||
(have_color_info != MagickFalse)))
{
/*
(void) WriteBlobLSBLong(image,0x0000ff00U); /* Green mask */
(void) WriteBlobLSBLong(image,0x000000ffU); /* Blue mask */
(void) WriteBlobLSBLong(image,0xff000000U); /* Alpha mask */
- (void) WriteBlobLSBLong(image,0x00000001U); /* CSType==Calib. RGB */
+ (void) WriteBlobLSBLong(image,0x73524742U); /* sRGB */
(void) WriteBlobLSBLong(image,(unsigned int)
- image->chromaticity.red_primary.x*0x3ffffff);
+ (image->chromaticity.red_primary.x*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- image->chromaticity.red_primary.y*0x3ffffff);
+ (image->chromaticity.red_primary.y*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- (1.000f-(image->chromaticity.red_primary.x+
- image->chromaticity.red_primary.y)*0x3ffffff));
+ ((1.000f-(image->chromaticity.red_primary.x+
+ image->chromaticity.red_primary.y))*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- image->chromaticity.green_primary.x*0x3ffffff);
+ (image->chromaticity.green_primary.x*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- image->chromaticity.green_primary.y*0x3ffffff);
+ (image->chromaticity.green_primary.y*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- (1.000f-(image->chromaticity.green_primary.x+
- image->chromaticity.green_primary.y)*0x3ffffff));
+ ((1.000f-(image->chromaticity.green_primary.x+
+ image->chromaticity.green_primary.y))*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- image->chromaticity.blue_primary.x*0x3ffffff);
+ (image->chromaticity.blue_primary.x*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- image->chromaticity.blue_primary.y*0x3ffffff);
+ (image->chromaticity.blue_primary.y*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- (1.000f-(image->chromaticity.blue_primary.x+
- image->chromaticity.blue_primary.y)*0x3ffffff));
+ ((1.000f-(image->chromaticity.blue_primary.x+
+ image->chromaticity.blue_primary.y))*0x40000000));
(void) WriteBlobLSBLong(image,(unsigned int)
- bmp_info.gamma_scale.x*0xffff);
+ (bmp_info.gamma_scale.x*0x10000));
(void) WriteBlobLSBLong(image,(unsigned int)
- bmp_info.gamma_scale.y*0xffff);
+ (bmp_info.gamma_scale.y*0x10000));
(void) WriteBlobLSBLong(image,(unsigned int)
- bmp_info.gamma_scale.z*0xffff);
+ (bmp_info.gamma_scale.z*0x10000));
if ((image->rendering_intent != UndefinedIntent) ||
(profile != (StringInfo *) NULL))
{
- long
+ ssize_t
intent;
switch ((int) image->rendering_intent)
*/
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Colormap: %ld entries",image->colors);
+ " Colormap: %.20g entries",(double) image->colors);
bmp_colormap=(unsigned char *) AcquireQuantumMemory((size_t) (1UL <<
bmp_info.bits_per_pixel),4*sizeof(*bmp_colormap));
if (bmp_colormap == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
q=bmp_colormap;
- for (i=0; i < (long) MagickMin((long) image->colors,(long) bmp_info.number_colors); i++)
+ for (i=0; i < (ssize_t) MagickMin((ssize_t) image->colors,(ssize_t) bmp_info.number_colors); i++)
{
- *q++=ScaleQuantumToChar(image->colormap[i].blue);
- *q++=ScaleQuantumToChar(image->colormap[i].green);
- *q++=ScaleQuantumToChar(image->colormap[i].red);
+ *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].blue));
+ *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].green));
+ *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].red));
if (type > 2)
*q++=(unsigned char) 0x0;
}
- for ( ; i < (long) (1UL << bmp_info.bits_per_pixel); i++)
+ for ( ; i < (ssize_t) (1UL << bmp_info.bits_per_pixel); i++)
{
*q++=(unsigned char) 0x00;
*q++=(unsigned char) 0x00;