% July 1992 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2012 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 %
Forward declarations.
*/
static MagickBooleanType
- WriteTGAImage(const ImageInfo *,Image *);
+ WriteTGAImage(const ImageInfo *,Image *,ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MagickBooleanType
status;
- PixelPacket
+ PixelInfo
pixel;
Quantum
unsigned char
j,
k,
+ pixels[4],
runlength;
+ unsigned int
+ alpha_bits;
+
/*
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)
{
*/
image->columns=tga_info.width;
image->rows=tga_info.height;
- image->matte=(tga_info.attributes & 0x0FU) != 0 ? MagickTrue : MagickFalse;
+ alpha_bits=(tga_info.attributes & 0x0FU);
+ image->matte=(alpha_bits > 0) || (tga_info.bits_per_pixel == 32) ?
+ MagickTrue : MagickFalse;
if ((tga_info.image_type != TGAColormap) &&
(tga_info.image_type != TGARLEColormap))
image->depth=(size_t) ((tga_info.bits_per_pixel <= 8) ? 8 :
one=1;
image->colors=one << tga_info.bits_per_pixel;
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
}
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,tga_info.id_length,(unsigned char *) comment);
comment[tga_info.id_length]='\0';
- (void) SetImageProperty(image,"comment",comment);
+ (void) SetImageProperty(image,"comment",comment,exception);
comment=DestroyString(comment);
}
(void) ResetMagickMemory(&pixel,0,sizeof(pixel));
/*
Read TGA raster colormap.
*/
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
for (i=0; i < (ssize_t) image->colors; i++)
{
if (((unsigned char) (tga_info.attributes & 0x20) >> 5) == 0)
real=image->rows-real-1;
q=QueueAuthenticPixels(image,0,(ssize_t) real,image->columns,1,exception);
- if (q == (const Quantum *) NULL)
+ if (q == (Quantum *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
index=(Quantum) ReadBlobByte(image);
if (tga_info.colormap_type != 0)
pixel=image->colormap[(ssize_t) ConstrainColormapIndex(image,
- 1UL*index)];
+ 1UL*index,exception)];
else
{
pixel.red=ScaleCharToQuantum((unsigned char) index);
range;
/*
- 5 bits each of red green and blue.
+ 5 bits each of RGB.
*/
- j=(unsigned char) ReadBlobByte(image);
- k=(unsigned char) ReadBlobByte(image);
+ if (ReadBlob(image,2,pixels) != 2)
+ ThrowReaderException(CorruptImageError,"UnableToReadImageData");
+ j=pixels[0];
+ k=pixels[1];
range=GetQuantumRange(5UL);
pixel.red=ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,range);
pixel.green=ScaleAnyToQuantum((1UL*(k & 0x03) << 3)+
(1UL*(j & 0xe0) >> 5),range);
pixel.blue=ScaleAnyToQuantum(1UL*(j & 0x1f),range);
if (image->matte != MagickFalse)
- pixel.alpha=(k & 0x80) == 0 ? (Quantum) OpaqueAlpha :
- (Quantum) TransparentAlpha;
+ pixel.alpha=(k & 0x80) == 0 ? (Quantum) OpaqueAlpha : (Quantum)
+ TransparentAlpha;
if (image->storage_class == PseudoClass)
- index=ConstrainColormapIndex(image,((size_t) k << 8)+j);
+ index=ConstrainColormapIndex(image,((size_t) k << 8)+j,exception);
break;
}
case 24:
+ {
+ /*
+ BGR pixels.
+ */
+ if (ReadBlob(image,3,pixels) != 3)
+ ThrowReaderException(CorruptImageError,"UnableToReadImageData");
+ pixel.blue=ScaleCharToQuantum(pixels[0]);
+ pixel.green=ScaleCharToQuantum(pixels[1]);
+ pixel.red=ScaleCharToQuantum(pixels[2]);
+ break;
+ }
case 32:
{
/*
- 8 bits each of blue green and red.
+ BGRA pixels.
*/
- pixel.blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
- pixel.green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
- pixel.red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
- if (tga_info.bits_per_pixel == 32)
- pixel.alpha=ScaleCharToQuantum((unsigned char)
- ReadBlobByte(image));
+ if (ReadBlob(image,4,pixels) != 4)
+ ThrowReaderException(CorruptImageError,"UnableToReadImageData");
+ pixel.blue=ScaleCharToQuantum(pixels[0]);
+ pixel.green=ScaleCharToQuantum(pixels[1]);
+ pixel.red=ScaleCharToQuantum(pixels[2]);
+ pixel.alpha=ScaleCharToQuantum(pixels[3]);
break;
}
}
%
% The format of the WriteTGAImage method is:
%
-% MagickBooleanType WriteTGAImage(const ImageInfo *image_info,Image *image)
+% MagickBooleanType WriteTGAImage(const ImageInfo *image_info,
+% Image *image,ExceptionInfo *exception)
%
% A description of each parameter follows.
%
return(y);
}
-static MagickBooleanType WriteTGAImage(const ImageInfo *image_info,Image *image)
+static MagickBooleanType WriteTGAImage(const ImageInfo *image_info,Image *image,
+ ExceptionInfo *exception)
{
#define TargaColormap 1
#define TargaRGB 2
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->columns > 65535L) || (image->rows > 65535L))
ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,RGBColorspace);
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
targa_info.id_length=0;
- value=GetImageProperty(image,"comment");
+ value=GetImageProperty(image,"comment",exception);
if (value != (const char *) NULL)
targa_info.id_length=(unsigned char) MagickMin(strlen(value),255);
targa_info.colormap_type=0;
(image_info->type != TrueColorMatteType) &&
(image_info->type != PaletteType) &&
(image->matte == MagickFalse) &&
- (IsImageGray(image,&image->exception) != MagickFalse))
+ (IsImageGray(image,exception) != MagickFalse))
targa_info.image_type=TargaMonochrome;
else
if ((image->storage_class == DirectClass) || (image->colors > 256))
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
for (y=(ssize_t) (image->rows-1); y >= 0; y--)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
break;
q=targa_pixels;