% Read/Write X Windows System Bitmap Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2017 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 %
%
*/
-static int XBMInteger(Image *image,short int *hex_digits)
-{
+static unsigned int XBMInteger(Image *image,short int *hex_digits)
+{
int
- c,
- flag,
+ c;
+
+ unsigned int
value;
-
- value=0;
- flag=0;
- for ( ; ; )
- {
+
+ /*
+ Skip any leading whitespace.
+ */
+ do
+ {
c=ReadBlobByte(image);
if (c == EOF)
- {
- value=(-1);
- break;
- }
+ return(0);
+ } while ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'));
+ /*
+ Evaluate number.
+ */
+ value=0;
+ do
+ {
+ if (value > (unsigned int) (INT_MAX/10))
+ break;
+ value*=16;
c&=0xff;
- if (isxdigit(c) != MagickFalse)
- {
- value=(int) ((size_t) value << 4)+hex_digits[c];
- flag++;
- continue;
- }
- if ((hex_digits[c]) < 0 && (flag != 0))
+ if (value > (unsigned int) (INT_MAX-hex_digits[c]))
break;
- }
+ value+=hex_digits[c];
+ c=ReadBlobByte(image);
+ if (c == EOF)
+ return(0);
+ } while (hex_digits[c] >= 0);
return(value);
}
static Image *ReadXBMImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
- buffer[MaxTextExtent],
- name[MaxTextExtent];
+ buffer[MagickPathExtent],
+ name[MagickPathExtent];
Image
*image;
short int
hex_digits[256];
- size_t
- bit,
- byte,
- bytes_per_line,
- length,
- padding,
- value,
- version;
-
ssize_t
y;
unsigned char
*data;
- unsigned long
+ unsigned int
+ bit,
+ byte,
+ bytes_per_line,
height,
+ length,
+ padding,
+ value,
+ version,
width;
/*
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
width=0;
height=0;
while (ReadBlobString(image,buffer) != (char *) NULL)
- if (sscanf(buffer,"#define %s %lu",name,&width) == 2)
+ if (sscanf(buffer,"#define %32s %u",name,&width) == 2)
if ((strlen(name) >= 6) &&
(LocaleCompare(name+strlen(name)-6,"_width") == 0))
break;
while (ReadBlobString(image,buffer) != (char *) NULL)
- if (sscanf(buffer,"#define %s %lu",name,&height) == 2)
+ if (sscanf(buffer,"#define %32s %u",name,&height) == 2)
if ((strlen(name) >= 7) &&
(LocaleCompare(name+strlen(name)-7,"_height") == 0))
break;
version=11;
while (ReadBlobString(image,buffer) != (char *) NULL)
{
- if (sscanf(buffer,"static short %s = {",name) == 1)
+ if (sscanf(buffer,"static short %32s = {",name) == 1)
version=10;
else
- if (sscanf(buffer,"static unsigned char %s = {",name) == 1)
+ if (sscanf(buffer,"static unsigned char %32s = {",name) == 1)
version=11;
else
- if (sscanf(buffer,"static char %s = {",name) == 1)
+ if (sscanf(buffer,"static char %32s = {",name) == 1)
version=11;
else
continue;
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
/*
Initialize hex values.
*/
if (((image->columns % 16) != 0) && ((image->columns % 16) < 9) &&
(version == 10))
padding=1;
- bytes_per_line=(image->columns+7)/8+padding;
- length=(size_t) image->rows;
+ bytes_per_line=(unsigned int) (image->columns+7)/8+padding;
+ length=(unsigned int) image->rows;
data=(unsigned char *) AcquireQuantumMemory(length,bytes_per_line*
sizeof(*data));
if (data == (unsigned char *) NULL)
if (version == 10)
for (i=0; i < (ssize_t) (bytes_per_line*image->rows); (i+=2))
{
- value=(size_t) XBMInteger(image,hex_digits);
+ value=XBMInteger(image,hex_digits);
*p++=(unsigned char) value;
if ((padding == 0) || (((i+2) % bytes_per_line) != 0))
*p++=(unsigned char) (value >> 8);
else
for (i=0; i < (ssize_t) (bytes_per_line*image->rows); i++)
{
- value=(size_t) XBMInteger(image,hex_digits);
+ value=XBMInteger(image,hex_digits);
*p++=(unsigned char) value;
}
/*
MagickInfo
*entry;
- entry=SetMagickInfo("XBM");
+ entry=AcquireMagickInfo("XBM","XBM",
+ "X Windows system bitmap (black and white)");
entry->decoder=(DecodeImageHandler *) ReadXBMImage;
entry->encoder=(EncodeImageHandler *) WriteXBMImage;
entry->magick=(IsImageFormatHandler *) IsXBM;
- entry->adjoin=MagickFalse;
- entry->description=ConstantString(
- "X Windows system bitmap (black and white)");
- entry->module=ConstantString("XBM");
+ entry->flags^=CoderAdjoinFlag;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ExceptionInfo *exception)
{
char
- basename[MaxTextExtent],
- buffer[MaxTextExtent];
+ basename[MagickPathExtent],
+ buffer[MagickPathExtent];
MagickBooleanType
status;
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
- if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,sRGBColorspace,exception);
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
/*
Write X bitmap header.
*/
GetPathComponent(image->filename,BasePath,basename);
- (void) FormatLocaleString(buffer,MaxTextExtent,"#define %s_width %.20g\n",
+ (void) FormatLocaleString(buffer,MagickPathExtent,"#define %s_width %.20g\n",
basename,(double) image->columns);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
- (void) FormatLocaleString(buffer,MaxTextExtent,"#define %s_height %.20g\n",
+ (void) FormatLocaleString(buffer,MagickPathExtent,"#define %s_height %.20g\n",
basename,(double) image->rows);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
- (void) FormatLocaleString(buffer,MaxTextExtent,
+ (void) FormatLocaleString(buffer,MagickPathExtent,
"static char %s_bits[] = {\n",basename);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
- (void) CopyMagickString(buffer," ",MaxTextExtent);
+ (void) CopyMagickString(buffer," ",MagickPathExtent);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
/*
Convert MIFF to X bitmap pixels.
count=0;
x=0;
y=0;
- (void) CopyMagickString(buffer," ",MaxTextExtent);
+ (void) CopyMagickString(buffer," ",MagickPathExtent);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
for (y=0; y < (ssize_t) image->rows; y++)
{
for (x=0; x < (ssize_t) image->columns; x++)
{
byte>>=1;
- if (GetPixelIntensity(image,p) < (QuantumRange/2))
+ if (GetPixelLuma(image,p) < (QuantumRange/2))
byte|=0x80;
bit++;
if (bit == 8)
/*
Write a bitmap byte to the image file.
*/
- (void) FormatLocaleString(buffer,MaxTextExtent,"0x%02X, ",
+ (void) FormatLocaleString(buffer,MagickPathExtent,"0x%02X, ",
(unsigned int) (byte & 0xff));
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
count++;
if (count == 12)
{
- (void) CopyMagickString(buffer,"\n ",MaxTextExtent);
+ (void) CopyMagickString(buffer,"\n ",MagickPathExtent);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
count=0;
};
Write a bitmap byte to the image file.
*/
byte>>=(8-bit);
- (void) FormatLocaleString(buffer,MaxTextExtent,"0x%02X, ",
+ (void) FormatLocaleString(buffer,MagickPathExtent,"0x%02X, ",
(unsigned int) (byte & 0xff));
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
count++;
if (count == 12)
{
- (void) CopyMagickString(buffer,"\n ",MaxTextExtent);
+ (void) CopyMagickString(buffer,"\n ",MagickPathExtent);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
count=0;
};
if (status == MagickFalse)
break;
}
- (void) CopyMagickString(buffer,"};\n",MaxTextExtent);
+ (void) CopyMagickString(buffer,"};\n",MagickPathExtent);
(void) WriteBlob(image,strlen(buffer),(unsigned char *) buffer);
(void) CloseBlob(image);
return(MagickTrue);