% July 1992 %
% %
% %
-% 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/color.h"
-#include "magick/color-private.h"
-#include "magick/colormap.h"
-#include "magick/colormap-private.h"
-#include "magick/colorspace.h"
-#include "magick/draw.h"
-#include "magick/exception.h"
-#include "magick/exception-private.h"
-#include "magick/geometry.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/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/attribute.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/color.h"
+#include "MagickCore/color-private.h"
+#include "MagickCore/colormap.h"
+#include "MagickCore/colormap-private.h"
+#include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
+#include "MagickCore/draw.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/geometry.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/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
+#include "MagickCore/transform.h"
\f
/*
Typedef declarations.
Forward declarations.
*/
static MagickBooleanType
- WriteDIBImage(const ImageInfo *,Image *);
+ WriteDIBImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Image
*image;
- IndexPacket
- index;
-
- ssize_t
- bit,
- y;
-
MagickBooleanType
status;
- register IndexPacket
- *indexes;
+ Quantum
+ index;
register ssize_t
x;
- register PixelPacket
+ register Quantum
*q;
register ssize_t
*p;
size_t
+ bytes_per_line,
length;
ssize_t
- count;
+ bit,
+ count,
+ y;
+
unsigned char
*pixels;
- size_t
- bytes_per_line;
-
/*
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)
{
dib_info.green_mask=ReadBlobLSBLong(image);
dib_info.blue_mask=ReadBlobLSBLong(image);
}
- image->matte=dib_info.bits_per_pixel == 32 ? MagickTrue : MagickFalse;
+ image->alpha_trait=dib_info.bits_per_pixel == 32 ? BlendPixelTrait :
+ UndefinedPixelTrait;
image->columns=(size_t) MagickAbsoluteValue(dib_info.width);
image->rows=(size_t) MagickAbsoluteValue(dib_info.height);
image->depth=8;
if ((dib_info.number_colors != 0) || (dib_info.bits_per_pixel < 16))
{
+ size_t
+ one;
+
image->storage_class=PseudoClass;
image->colors=dib_info.number_colors;
+ one=1;
if (image->colors == 0)
- image->colors=1L << dib_info.bits_per_pixel;
+ image->colors=one << dib_info.bits_per_pixel;
}
if (image_info->size)
{
/*
Read DIB raster colormap.
*/
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
length=(size_t) image->colors;
dib_colormap=(unsigned char *) AcquireQuantumMemory(length,
Initialize image structure.
*/
image->units=PixelsPerCentimeterResolution;
- image->x_resolution=(double) dib_info.x_pixels/100.0;
- image->y_resolution=(double) dib_info.y_pixels/100.0;
+ image->resolution.x=(double) dib_info.x_pixels/100.0;
+ image->resolution.y=(double) dib_info.y_pixels/100.0;
/*
Convert DIB raster image to pixel packets.
*/
{
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 < ((ssize_t) image->columns-7); x+=8)
{
for (bit=0; bit < 8; bit++)
{
- index=(IndexPacket) ((*p) & (0x80 >> bit) ? 0x01 : 0x00);
- indexes[x+bit]=index;
- *q++=image->colormap[(ssize_t) index];
+ index=(Quantum) ((*p) & (0x80 >> bit) ? 0x01 : 0x00);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
}
p++;
}
{
for (bit=0; bit < (ssize_t) (image->columns % 8); bit++)
{
- index=(IndexPacket) ((*p) & (0x80 >> bit) ? 0x01 : 0x00);
- indexes[x+bit]=index;
- *q++=image->colormap[(ssize_t) index];
+ index=(Quantum) ((*p) & (0x80 >> bit) ? 0x01 : 0x00);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
}
p++;
}
break;
}
}
+ (void) SyncImage(image,exception);
break;
}
case 4:
{
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 < ((ssize_t) image->columns-1); x+=2)
{
- index=ConstrainColormapIndex(image,(*p >> 4) & 0xf);
- indexes[x]=index;
- *q++=image->colormap[(ssize_t) index];
- index=ConstrainColormapIndex(image,*p & 0xf);
- indexes[x+1]=index;
- *q++=image->colormap[(ssize_t) index];
+ index=ConstrainColormapIndex(image,(*p >> 4) & 0xf,exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
+ index=ConstrainColormapIndex(image,*p & 0xf,exception);
+ SetPixelIndex(image,index,q);
p++;
+ q+=GetPixelChannels(image);
}
if ((image->columns % 2) != 0)
{
- index=ConstrainColormapIndex(image,(*p >> 4) & 0xf);
- indexes[x]=index;
- *q++=image->colormap[(ssize_t) index];
+ index=ConstrainColormapIndex(image,(*p >> 4) & 0xf,exception);
+ SetPixelIndex(image,index,q);
+ q+=GetPixelChannels(image);
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
}
+ (void) SyncImage(image,exception);
break;
}
case 8:
{
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 < (ssize_t) image->columns; x++)
{
- index=ConstrainColormapIndex(image,*p);
- indexes[x]=index;
- *q=image->colormap[(ssize_t) index];
+ index=ConstrainColormapIndex(image,*p,exception);
+ SetPixelIndex(image,index,q);
p++;
- q++;
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
break;
}
}
+ (void) SyncImage(image,exception);
break;
}
case 16:
{
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 < (ssize_t) image->columns; x++)
{
word|=(*p++ << 8);
if (dib_info.red_mask == 0)
{
- q->red=ScaleCharToQuantum(ScaleColor5to8((unsigned char)
- ((word >> 10) & 0x1f)));
- q->green=ScaleCharToQuantum(ScaleColor5to8((unsigned char)
- ((word >> 5) & 0x1f)));
- q->blue=ScaleCharToQuantum(ScaleColor5to8((unsigned char)
- (word & 0x1f)));
+ SetPixelRed(image,ScaleCharToQuantum(ScaleColor5to8(
+ (unsigned char) ((word >> 10) & 0x1f))),q);
+ SetPixelGreen(image,ScaleCharToQuantum(ScaleColor5to8(
+ (unsigned char) ((word >> 5) & 0x1f))),q);
+ SetPixelBlue(image,ScaleCharToQuantum(ScaleColor5to8(
+ (unsigned char) (word & 0x1f))),q);
}
else
{
- q->red=ScaleCharToQuantum(ScaleColor5to8((unsigned char)
- ((word >> 11) & 0x1f)));
- q->green=ScaleCharToQuantum(ScaleColor6to8((unsigned char)
- ((word >> 5) & 0x3f)));
- q->blue=ScaleCharToQuantum(ScaleColor5to8((unsigned char)
- (word & 0x1f)));
+ SetPixelRed(image,ScaleCharToQuantum(ScaleColor5to8(
+ (unsigned char) ((word >> 11) & 0x1f))),q);
+ SetPixelGreen(image,ScaleCharToQuantum(ScaleColor6to8(
+ (unsigned char) ((word >> 5) & 0x3f))),q);
+ SetPixelBlue(image,ScaleCharToQuantum(ScaleColor5to8(
+ (unsigned char) (word & 0x1f))),q);
}
- q++;
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
{
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 < (ssize_t) image->columns; x++)
{
- q->blue=ScaleCharToQuantum(*p++);
- q->green=ScaleCharToQuantum(*p++);
- q->red=ScaleCharToQuantum(*p++);
- if (image->matte != MagickFalse)
- q->opacity=ScaleCharToQuantum(*p++);
- q++;
+ SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+ SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+ SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
%
% The format of the WriteDIBImage method is:
%
-% MagickBooleanType WriteDIBImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WriteDIBImage(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 WriteDIBImage(const ImageInfo *image_info,Image *image)
+static MagickBooleanType WriteDIBImage(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
{
DIBInfo
dib_info;
- ssize_t
- y;
-
MagickBooleanType
status;
- register const IndexPacket
- *indexes;
-
- register const PixelPacket
+ register const Quantum
*p;
register ssize_t
register unsigned char
*q;
+ size_t
+ bytes_per_line;
+
+ ssize_t
+ y;
+
unsigned char
*dib_data,
*pixels;
- size_t
- bytes_per_line;
-
/*
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);
/*
Initialize DIB raster file header.
*/
- if (image->colorspace != RGBColorspace)
- (void) TransformImageColorspace(image,RGBColorspace);
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
if (image->storage_class == DirectClass)
{
/*
Full color DIB raster.
*/
dib_info.number_colors=0;
- dib_info.bits_per_pixel=(unsigned short) (image->matte ? 32 : 24);
+ dib_info.bits_per_pixel=(unsigned short) (image->alpha_trait ? 32 : 24);
}
else
{
dib_info.bits_per_pixel=8;
if (image_info->depth > 8)
dib_info.bits_per_pixel=16;
- if (IsMonochromeImage(image,&image->exception) != MagickFalse)
+ if (IsImageMonochrome(image,exception) != MagickFalse)
dib_info.bits_per_pixel=1;
dib_info.number_colors=(dib_info.bits_per_pixel == 16) ? 0 :
(1UL << dib_info.bits_per_pixel);
case UndefinedResolution:
case PixelsPerInchResolution:
{
- dib_info.x_pixels=(size_t) (100.0*image->x_resolution/2.54);
- dib_info.y_pixels=(size_t) (100.0*image->y_resolution/2.54);
+ dib_info.x_pixels=(size_t) (100.0*image->resolution.x/2.54);
+ dib_info.y_pixels=(size_t) (100.0*image->resolution.y/2.54);
break;
}
case PixelsPerCentimeterResolution:
{
- dib_info.x_pixels=(size_t) (100.0*image->x_resolution);
- dib_info.y_pixels=(size_t) (100.0*image->y_resolution);
+ dib_info.x_pixels=(size_t) (100.0*image->resolution.x);
+ dib_info.y_pixels=(size_t) (100.0*image->resolution.y);
break;
}
}
*/
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;
bit=0;
byte=0;
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++;
+ p+=GetPixelChannels(image);
}
if (bit != 0)
{
for (x=(ssize_t) (image->columns+7)/8; x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
- image->rows);
+ image->rows);
if (status == MagickFalse)
break;
}
*/
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 < (ssize_t) image->columns; x++)
- *q++=(unsigned char) indexes[x];
+ {
+ *q++=(unsigned char) GetPixelIndex(image,p);
+ p+=GetPixelChannels(image);
+ }
for ( ; x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
- image->rows);
+ image->rows);
if (status == MagickFalse)
break;
}
*/
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 < (ssize_t) image->columns; x++)
{
word=(unsigned short) ((ScaleColor8to5((unsigned char)
- ScaleQuantumToChar(GetRedPixelComponent(p))) << 11) | (ScaleColor8to6((unsigned char)
- ScaleQuantumToChar(GetGreenPixelComponent(p))) << 5) | (ScaleColor8to5(
- (unsigned char) ScaleQuantumToChar((unsigned char) GetBluePixelComponent(p)) << 0)));
+ ScaleQuantumToChar(GetPixelRed(image,p))) << 11) | (ScaleColor8to6(
+ (unsigned char) ScaleQuantumToChar(GetPixelGreen(image,p))) << 5) |
+ (ScaleColor8to5((unsigned char) ScaleQuantumToChar((unsigned char)
+ GetPixelBlue(image,p)) << 0)));
*q++=(unsigned char)(word & 0xff);
*q++=(unsigned char)(word >> 8);
- p++;
+ p+=GetPixelChannels(image);
}
- for (x=2L*image->columns; x < (ssize_t) bytes_per_line; x++)
+ for (x=(ssize_t) (2*image->columns); x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
- image->rows);
+ image->rows);
if (status == MagickFalse)
break;
}
*/
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 < (ssize_t) image->columns; x++)
{
- *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
- *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
- *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
- if (image->matte != MagickFalse)
- *q++=ScaleQuantumToChar(GetOpacityPixelComponent(p));
- p++;
+ *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+ *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+ *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+ if (image->alpha_trait == BlendPixelTrait)
+ *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
+ p+=GetPixelChannels(image);
}
if (dib_info.bits_per_pixel == 24)
- for (x=3L*image->columns; x < (ssize_t) bytes_per_line; x++)
+ for (x=(ssize_t) (3*image->columns); x < (ssize_t) bytes_per_line; x++)
*q++=0x00;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
- image->rows);
+ image->rows);
if (status == MagickFalse)
break;
}
/*
Write DIB header.
*/
- (void) WriteBlobLSBLong(image,dib_info.size);
- (void) WriteBlobLSBLong(image,(size_t) dib_info.width);
+ (void) WriteBlobLSBLong(image,(unsigned int) dib_info.size);
+ (void) WriteBlobLSBLong(image,dib_info.width);
(void) WriteBlobLSBLong(image,(unsigned short) dib_info.height);
(void) WriteBlobLSBShort(image,(unsigned short) dib_info.planes);
(void) WriteBlobLSBShort(image,dib_info.bits_per_pixel);
- (void) WriteBlobLSBLong(image,dib_info.compression);
- (void) WriteBlobLSBLong(image,dib_info.image_size);
- (void) WriteBlobLSBLong(image,dib_info.x_pixels);
- (void) WriteBlobLSBLong(image,dib_info.y_pixels);
- (void) WriteBlobLSBLong(image,dib_info.number_colors);
- (void) WriteBlobLSBLong(image,dib_info.colors_important);
+ (void) WriteBlobLSBLong(image,(unsigned int) dib_info.compression);
+ (void) WriteBlobLSBLong(image,(unsigned int) dib_info.image_size);
+ (void) WriteBlobLSBLong(image,(unsigned int) dib_info.x_pixels);
+ (void) WriteBlobLSBLong(image,(unsigned int) dib_info.y_pixels);
+ (void) WriteBlobLSBLong(image,(unsigned int) dib_info.number_colors);
+ (void) WriteBlobLSBLong(image,(unsigned int) dib_info.colors_important);
if (image->storage_class == PseudoClass)
{
if (dib_info.bits_per_pixel <= 8)