% July 1992 %
% %
% %
-% Copyright 1999-2011 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 %
unsigned char
j,
k,
+ pixels[4],
runlength;
+ unsigned int
+ alpha_bits;
+
/*
Open image file.
*/
*/
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->alpha_trait=(alpha_bits > 0) || (tga_info.bits_per_pixel == 32) ?
+ BlendPixelTrait : UndefinedPixelTrait;
if ((tga_info.image_type != TGAColormap) &&
(tga_info.image_type != TGARLEColormap))
image->depth=(size_t) ((tga_info.bits_per_pixel <= 8) ? 8 :
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;
+ if (image->alpha_trait == BlendPixelTrait)
+ pixel.alpha=(k & 0x80) == 0 ? (Quantum) OpaqueAlpha : (Quantum)
+ TransparentAlpha;
if (image->storage_class == PseudoClass)
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;
}
}
SetPixelRed(image,pixel.red,q);
SetPixelGreen(image,pixel.green,q);
SetPixelBlue(image,pixel.blue,q);
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
SetPixelAlpha(image,pixel.alpha,q);
q+=GetPixelChannels(image);
}
*/
if ((image->columns > 65535L) || (image->rows > 65535L))
ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
- if (IsRGBColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,RGBColorspace,exception);
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
targa_info.id_length=0;
value=GetImageProperty(image,"comment",exception);
if (value != (const char *) NULL)
if ((image_info->type != TrueColorType) &&
(image_info->type != TrueColorMatteType) &&
(image_info->type != PaletteType) &&
- (image->matte == MagickFalse) &&
+ (image->alpha_trait != BlendPixelTrait) &&
(IsImageGray(image,exception) != MagickFalse))
targa_info.image_type=TargaMonochrome;
else
*/
targa_info.image_type=TargaRGB;
targa_info.bits_per_pixel=24;
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
{
targa_info.bits_per_pixel=32;
targa_info.attributes=8; /* # of alpha bits */
*q++=ScaleQuantumToChar(GetPixelBlue(image,p));
*q++=ScaleQuantumToChar(GetPixelGreen(image,p));
*q++=ScaleQuantumToChar(GetPixelRed(image,p));
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
*q++=(unsigned char) ScaleQuantumToChar(GetPixelAlpha(image,p));
}
p+=GetPixelChannels(image);