% 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/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/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 "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/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/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"
\f
/*
Typedef declarations.
Forward declarations.
*/
static MagickBooleanType
- WritePCXImage(const ImageInfo *,Image *);
+ WritePCXImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% o length: Specifies the length of the magick string.
%
-%
*/
static MagickBooleanType IsDCX(const unsigned char *magick,const size_t length)
{
%
% o length: Specifies the length of the magick string.
%
-%
*/
static MagickBooleanType IsPCX(const unsigned char *magick,const size_t length)
{
id,
mask;
- ssize_t
- y;
-
MagickBooleanType
status;
PCXInfo
pcx_info;
- register IndexPacket
- *indexes;
-
register ssize_t
x;
- register PixelPacket
+ register Quantum
*q;
register ssize_t
*p,
*r;
+ size_t
+ one,
+ pcx_packets;
+
ssize_t
- count;
+ count,
+ y;
unsigned char
packet,
*pcx_pixels,
*scanline;
- size_t
- one,
- pcx_packets;
-
/*
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)
{
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
image->depth=pcx_info.bits_per_pixel <= 8 ? 8U : MAGICKCORE_QUANTUM_DEPTH;
image->units=PixelsPerInchResolution;
- image->x_resolution=(double) pcx_info.horizontal_resolution;
- image->y_resolution=(double) pcx_info.vertical_resolution;
+ image->resolution.x=(double) pcx_info.horizontal_resolution;
+ image->resolution.y=(double) pcx_info.vertical_resolution;
image->colors=16;
pcx_colormap=(unsigned char *) AcquireQuantumMemory(256UL,
3*sizeof(*pcx_colormap));
((pcx_info.bits_per_pixel*pcx_info.planes) == 1))
image->colors=(size_t) MagickMin(one << (1UL*
(pcx_info.bits_per_pixel*pcx_info.planes)),256UL);
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if ((pcx_info.bits_per_pixel >= 8) && (pcx_info.planes != 1))
image->storage_class=DirectClass;
{
packet=(unsigned char) ReadBlobByte(image);
if (EOFBlob(image) != MagickFalse)
- break;
+ ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
*p++=packet;
pcx_packets--;
}
{
packet=(unsigned char) ReadBlobByte(image);
if (EOFBlob(image) != MagickFalse)
- break;
+ ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
if ((packet & 0xc0) != 0xc0)
{
*p++=packet;
count=(ssize_t) (packet & 0x3f);
packet=(unsigned char) ReadBlobByte(image);
if (EOFBlob(image) != MagickFalse)
- break;
+ ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
for ( ; count != 0; count--)
{
*p++=packet;
}
}
if (image->storage_class == DirectClass)
- image->matte=pcx_info.planes > 3 ? MagickTrue : MagickFalse;
+ image->alpha_trait=pcx_info.planes > 3 ? BlendPixelTrait :
+ UndefinedPixelTrait;
else
if ((pcx_info.version == 5) ||
((pcx_info.bits_per_pixel*pcx_info.planes) == 1))
image->colormap[0].red=(Quantum) 0;
image->colormap[0].green=(Quantum) 0;
image->colormap[0].blue=(Quantum) 0;
- image->colormap[1].red=(Quantum) QuantumRange;
- image->colormap[1].green=(Quantum) QuantumRange;
- image->colormap[1].blue=(Quantum) QuantumRange;
+ image->colormap[1].red=QuantumRange;
+ image->colormap[1].green=QuantumRange;
+ image->colormap[1].blue=QuantumRange;
}
else
if (image->colors > 16)
{
p=pcx_pixels+(y*pcx_info.bytes_per_line*pcx_info.planes);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
r=scanline;
if (image->storage_class == DirectClass)
for (i=0; i < pcx_info.planes; i++)
for (x=0; x < (ssize_t) image->columns; x++)
{
if (image->storage_class == PseudoClass)
- indexes[x]=(IndexPacket) (*r++);
+ SetPixelIndex(image,*r++,q);
else
{
- q->red=ScaleCharToQuantum(*r++);
- q->green=ScaleCharToQuantum(*r++);
- q->blue=ScaleCharToQuantum(*r++);
- if (image->matte != MagickFalse)
- q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*r++));
+ SetPixelRed(image,ScaleCharToQuantum(*r++),q);
+ SetPixelGreen(image,ScaleCharToQuantum(*r++),q);
+ SetPixelBlue(image,ScaleCharToQuantum(*r++),q);
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,ScaleCharToQuantum(*r++),q);
}
- q++;
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
- image->rows);
+ image->rows);
if (status == MagickFalse)
break;
}
}
if (image->storage_class == PseudoClass)
- (void) SyncImage(image);
+ (void) SyncImage(image,exception);
scanline=(unsigned char *) RelinquishMagickMemory(scanline);
if (pcx_colormap != (unsigned char *) NULL)
pcx_colormap=(unsigned char *) RelinquishMagickMemory(pcx_colormap);
/*
Allocate next image structure.
*/
- AcquireNextImage(image_info,image);
+ AcquireNextImage(image_info,image,exception);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
%
% The format of the WritePCXImage method is:
%
-% MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WritePCXImage(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 PCXWritePixels(PCXInfo *pcx_info,
const unsigned char *pixels,Image *image)
{
q=pixels;
for (i=0; i < (ssize_t) pcx_info->planes; i++)
{
- previous=(*q++);
- count=1;
- for (x=0; x < (ssize_t) (pcx_info->bytes_per_line-1); x++)
- {
- packet=(*q++);
- if ((packet == previous) && (count < 63))
- {
- count++;
- continue;
- }
- if ((count > 1) || ((previous & 0xc0) == 0xc0))
+ if (pcx_info->encoding == 0)
+ {
+ for (x=0; x < (ssize_t) pcx_info->bytes_per_line; x++)
+ (void) WriteBlobByte(image,(unsigned char) (*q++));
+ }
+ else
+ {
+ previous=(*q++);
+ count=1;
+ for (x=0; x < (ssize_t) (pcx_info->bytes_per_line-1); x++)
{
- count|=0xc0;
- (void) WriteBlobByte(image,(unsigned char) count);
+ packet=(*q++);
+ if ((packet == previous) && (count < 63))
+ {
+ count++;
+ continue;
+ }
+ if ((count > 1) || ((previous & 0xc0) == 0xc0))
+ {
+ count|=0xc0;
+ (void) WriteBlobByte(image,(unsigned char) count);
+ }
+ (void) WriteBlobByte(image,previous);
+ previous=packet;
+ count=1;
}
- (void) WriteBlobByte(image,previous);
- previous=packet;
- count=1;
- }
- if ((count > 1) || ((previous & 0xc0) == 0xc0))
- {
- count|=0xc0;
- (void) WriteBlobByte(image,(unsigned char) count);
+ if ((count > 1) || ((previous & 0xc0) == 0xc0))
+ {
+ count|=0xc0;
+ (void) WriteBlobByte(image,(unsigned char) count);
+ }
+ (void) WriteBlobByte(image,previous);
}
- (void) WriteBlobByte(image,previous);
}
return (MagickTrue);
}
-static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
+static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
{
- ssize_t
- y;
-
MagickBooleanType
status;
PCXInfo
pcx_info;
- register const IndexPacket
- *indexes;
-
- register const PixelPacket
+ register const Quantum
*p;
register ssize_t
size_t
length;
+ ssize_t
+ y;
+
unsigned char
*pcx_colormap,
*pcx_pixels;
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);
- if (image->colorspace != RGBColorspace)
- (void) TransformImageColorspace(image,RGBColorspace);
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
page_table=(MagickOffsetType *) NULL;
if ((LocaleCompare(image_info->magick,"DCX") == 0) ||
((GetNextImageInList(image) != (Image *) NULL) &&
*/
pcx_info.identifier=0x0a;
pcx_info.version=5;
- pcx_info.encoding=1;
+ pcx_info.encoding=image_info->compression == NoCompression ? 0 : 1;
pcx_info.bits_per_pixel=8;
if ((image->storage_class == PseudoClass) &&
- (IsMonochromeImage(image,&image->exception) != MagickFalse))
+ (IsImageMonochrome(image,exception) != MagickFalse))
pcx_info.bits_per_pixel=1;
pcx_info.left=0;
pcx_info.top=0;
case PixelsPerInchResolution:
default:
{
- pcx_info.horizontal_resolution=(unsigned short) image->x_resolution;
- pcx_info.vertical_resolution=(unsigned short) image->y_resolution;
+ pcx_info.horizontal_resolution=(unsigned short) image->resolution.x;
+ pcx_info.vertical_resolution=(unsigned short) image->resolution.y;
break;
}
case PixelsPerCentimeterResolution:
{
pcx_info.horizontal_resolution=(unsigned short)
- (2.54*image->x_resolution+0.5);
+ (2.54*image->resolution.x+0.5);
pcx_info.vertical_resolution=(unsigned short)
- (2.54*image->y_resolution+0.5);
+ (2.54*image->resolution.y+0.5);
break;
}
}
if ((image->storage_class == DirectClass) || (image->colors > 256))
{
pcx_info.planes=3;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
pcx_info.planes++;
}
pcx_info.bytes_per_line=(unsigned short) (((size_t) image->columns*
for (i=0; i < 58; i++)
(void) WriteBlobByte(image,'\0');
length=(size_t) pcx_info.bytes_per_line;
- pcx_pixels=(unsigned char *) AcquireQuantumMemory(length,
- pcx_info.planes*sizeof(*pcx_pixels));
+ pcx_pixels=(unsigned char *) AcquireQuantumMemory(length,pcx_info.planes*
+ sizeof(*pcx_pixels));
if (pcx_pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
q=pcx_pixels;
if ((image->storage_class == DirectClass) || (image->colors > 256))
{
- const PixelPacket
+ const Quantum
*pixels;
/*
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
- pixels=GetVirtualPixels(image,0,y,image->columns,1,
- &image->exception);
- if (pixels == (const PixelPacket *) NULL)
+ pixels=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (pixels == (const Quantum *) NULL)
break;
q=pcx_pixels;
for (i=0; i < pcx_info.planes; i++)
{
for (x=0; x < (ssize_t) pcx_info.bytes_per_line; x++)
{
- *q++=ScaleQuantumToChar(GetRedPixelComponent(p));
- p++;
+ *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+ p+=GetPixelChannels(image);
}
break;
}
{
for (x=0; x < (ssize_t) pcx_info.bytes_per_line; x++)
{
- *q++=ScaleQuantumToChar(GetGreenPixelComponent(p));
- p++;
+ *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+ p+=GetPixelChannels(image);
}
break;
}
{
for (x=0; x < (ssize_t) pcx_info.bytes_per_line; x++)
{
- *q++=ScaleQuantumToChar(GetBluePixelComponent(p));
- p++;
+ *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+ p+=GetPixelChannels(image);
}
break;
}
{
for (x=(ssize_t) pcx_info.bytes_per_line; x != 0; x--)
{
- *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
- p++;
+ *q++=ScaleQuantumToChar((Quantum) (GetPixelAlpha(image,p)));
+ p+=GetPixelChannels(image);
}
break;
}
if (pcx_info.bits_per_pixel > 1)
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=pcx_pixels;
for (x=0; x < (ssize_t) image->columns; x++)
- *q++=(unsigned char) indexes[x];
+ {
+ *q++=(unsigned char) GetPixelIndex(image,p);
+ p+=GetPixelChannels(image);
+ }
if (PCXWritePixels(&pcx_info,pcx_pixels,image) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
}
else
{
- IndexPacket
+ Quantum
polarity;
register unsigned char
/*
Convert PseudoClass image to a PCX monochrome image.
*/
- polarity=(IndexPacket) (PixelIntensityToQuantum(
- &image->colormap[0]) < ((Quantum) QuantumRange/2) ? 1 : 0);
+ polarity=(Quantum) (GetPixelInfoIntensity(
+ &image->colormap[0]) < (QuantumRange/2) ? 1 : 0);
if (image->colors == 2)
- polarity=(IndexPacket) (
- PixelIntensityToQuantum(&image->colormap[0]) <
- PixelIntensityToQuantum(&image->colormap[1]) ? 1 : 0);
+ polarity=(Quantum) (GetPixelInfoIntensity(&image->colormap[0]) <
+ GetPixelInfoIntensity(&image->colormap[1]) ? 1 : 0);
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);
bit=0;
byte=0;
q=pcx_pixels;
for (x=0; x < (ssize_t) image->columns; x++)
{
byte<<=1;
- if (indexes[x] == polarity)
+ if (GetPixelIndex(image,p) == polarity)
byte|=0x01;
bit++;
if (bit == 8)
bit=0;
byte=0;
}
- p++;
+ p+=GetPixelChannels(image);
}
if (bit != 0)
*q++=byte << (8-bit);
break;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
- image->rows);
+ status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
+ y,image->rows);
if (status == MagickFalse)
break;
}
ThrowWriterException(CorruptImageError,"ImproperImageHeader");
(void) WriteBlobLSBLong(image,0x3ADE68B1L);
for (i=0; i <= (ssize_t) scene; i++)
- (void) WriteBlobLSBLong(image,(size_t) page_table[i]);
+ (void) WriteBlobLSBLong(image,(unsigned int) page_table[i]);
page_table=(MagickOffsetType *) RelinquishMagickMemory(page_table);
}
if (status == MagickFalse)
*message;
message=GetExceptionMessage(errno);
- (void) ThrowMagickException(&image->exception,GetMagickModule(),
- FileOpenError,"UnableToWriteFile","`%s': %s",image->filename,message);
+ (void) ThrowMagickException(exception,GetMagickModule(),FileOpenError,
+ "UnableToWriteFile","`%s': %s",image->filename,message);
message=DestroyString(message);
}
(void) CloseBlob(image);