Game Development Reference
In-Depth Information
}else{
if (m_hdr) delete m_hdr;
m_hdr = new TGAHEADER;
memcpy( m_hdr, &tgaHdr, sizeof(TGAHEADER));
if (m_bits) delete [] m_bits;
m_bits = bits;
}
return TRUE;
}
The Load function uses the call to ReadImage to actually access the
pixel data. The function is very simple, just moving through the data one
scan line at a time. A TGA file can have the x and y values reversed in
some cases and the function checks whether the y values are flipped. A
Windows bitmap is usually stored so that the last scan line is the first and
if you regularily work with such files then you may want to force the TGA
file to load flipped.
BOOL CTGA::ReadImage(CFile &f, BYTE *buffer, TGAHEADER &hdr)
{
int swidth = hdr.ImageWidth * 3;
// Bits 5 of the Image Descriptor byte control the ordering of
// the pixels we check whether we are upside down
BOOL yReversed = ((hdr.ImagDesc & 32) == 32);
BYTE *bits;
for (int y=0; y<hdr.ImageHeight; y++){
if (yReversed){
bits = GetPixelAddress(0, y, hdr, buffer);
}else{
bits = GetPixelAddress(0, Height-y-1, hdr, buffer);
}
if (tgaFile.Read(bits, swidth)!=swidth) return FALSE;
}
return TRUE;
}
The 'ReadImage' function uses a call to 'GetPixelAddress', which
returns the position in the BYTE array for a particular pixel address.
Search Nedrilad ::




Custom Search