% Read/Write Truevision Targa Image Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 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 %
image->columns=tga_info.width;
image->rows=tga_info.height;
alpha_bits=(tga_info.attributes & 0x0FU);
- image->matte=(alpha_bits > 0) || (tga_info.bits_per_pixel == 32) ?
- MagickTrue : MagickFalse;
+ image->alpha_trait=(alpha_bits > 0) || (tga_info.bits_per_pixel == 32) ||
+ (tga_info.colormap_size == 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 :
comment=DestroyString(comment);
}
(void) ResetMagickMemory(&pixel,0,sizeof(pixel));
- pixel.alpha=(Quantum) OpaqueAlpha;
+ pixel.alpha=(MagickRealType) OpaqueAlpha;
if (tga_info.colormap_type != 0)
{
/*
/*
Gray scale.
*/
- pixel.red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
+ pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
pixel.green=pixel.red;
pixel.blue=pixel.red;
break;
j=(unsigned char) ReadBlobByte(image);
k=(unsigned char) ReadBlobByte(image);
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);
+ pixel.red=(MagickRealType) ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,
+ range);
+ pixel.green=(MagickRealType) ScaleAnyToQuantum((1UL*(k & 0x03)
+ << 3)+(1UL*(j & 0xe0) >> 5),range);
+ pixel.blue=(MagickRealType) ScaleAnyToQuantum(1UL*(j & 0x1f),range);
break;
}
case 24:
- case 32:
{
/*
8 bits each of blue, green and red.
*/
- pixel.blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
- pixel.green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
- pixel.red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
+ pixel.blue=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
+ pixel.green=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
+ pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
+ break;
+ }
+ case 32:
+ {
+ /*
+ 8 bits each of blue, green, red, and alpha.
+ */
+ pixel.blue=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
+ pixel.green=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
+ pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
+ pixel.alpha=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ ReadBlobByte(image));
break;
}
}
1UL*index,exception)];
else
{
- pixel.red=ScaleCharToQuantum((unsigned char) index);
- pixel.green=ScaleCharToQuantum((unsigned char) index);
- pixel.blue=ScaleCharToQuantum((unsigned char) index);
+ pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ index);
+ pixel.green=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ index);
+ pixel.blue=(MagickRealType) ScaleCharToQuantum((unsigned char)
+ index);
}
break;
}
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.red=(MagickRealType) ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,
+ range);
+ pixel.green=(MagickRealType) ScaleAnyToQuantum((1UL*(k & 0x03)
+ << 3)+(1UL*(j & 0xe0) >> 5),range);
+ pixel.blue=(MagickRealType) ScaleAnyToQuantum(1UL*(j & 0x1f),range);
+ if (image->alpha_trait == BlendPixelTrait)
+ pixel.alpha=(MagickRealType) ((k & 0x80) == 0 ? (Quantum)
+ OpaqueAlpha : (Quantum) TransparentAlpha);
if (image->storage_class == PseudoClass)
index=ConstrainColormapIndex(image,((size_t) k << 8)+j,exception);
break;
*/
if (ReadBlob(image,3,pixels) != 3)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
- pixel.blue=ScaleCharToQuantum(pixels[0]);
- pixel.green=ScaleCharToQuantum(pixels[1]);
- pixel.red=ScaleCharToQuantum(pixels[2]);
+ pixel.blue=(MagickRealType) ScaleCharToQuantum(pixels[0]);
+ pixel.green=(MagickRealType) ScaleCharToQuantum(pixels[1]);
+ pixel.red=(MagickRealType) ScaleCharToQuantum(pixels[2]);
break;
}
case 32:
*/
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]);
+ pixel.blue=(MagickRealType) ScaleCharToQuantum(pixels[0]);
+ pixel.green=(MagickRealType) ScaleCharToQuantum(pixels[1]);
+ pixel.red=(MagickRealType) ScaleCharToQuantum(pixels[2]);
+ pixel.alpha=(MagickRealType) ScaleCharToQuantum(pixels[3]);
break;
}
}
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
if (image->storage_class == PseudoClass)
SetPixelIndex(image,index,q);
- SetPixelRed(image,pixel.red,q);
- SetPixelGreen(image,pixel.green,q);
- SetPixelBlue(image,pixel.blue,q);
- if (image->matte != MagickFalse)
- SetPixelAlpha(image,pixel.alpha,q);
+ SetPixelRed(image,ClampToQuantum(pixel.red),q);
+ SetPixelGreen(image,ClampToQuantum(pixel.green),q);
+ SetPixelBlue(image,ClampToQuantum(pixel.blue),q);
+ if (image->alpha_trait == BlendPixelTrait)
+ SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
q+=GetPixelChannels(image);
}
if (((unsigned char) (tga_info.attributes & 0xc0) >> 6) == 4)
*/
if ((image->columns > 65535L) || (image->rows > 65535L))
ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
- if (IssRGBColorspace(image->colorspace) == MagickFalse)
- (void) TransformImageColorspace(image,sRGBColorspace,exception);
+ (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=targa_colormap;
for (i=0; i < (ssize_t) image->colors; i++)
{
- *q++=ScaleQuantumToChar(image->colormap[i].blue);
- *q++=ScaleQuantumToChar(image->colormap[i].green);
- *q++=ScaleQuantumToChar(image->colormap[i].red);
+ *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].blue));
+ *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].green));
+ *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].red));
}
(void) WriteBlob(image,(size_t) (3*targa_info.colormap_length),
targa_colormap);
*q++=(unsigned char) GetPixelIndex(image,p);
else
if (targa_info.image_type == TargaMonochrome)
- *q++=(unsigned char) ScaleQuantumToChar(GetPixelIntensity(image,p));
+ *q++=(unsigned char) ScaleQuantumToChar((ClampToQuantum(
+ GetPixelLuma(image,p))));
else
{
*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);