Game Development Reference
In-Depth Information
'ImageType' member of the header would be set to TGA_RLE. The values
for these constants are stored in the 'tga.h' file, which is part of the
Toon3D source code. The storage width of a TGA file is aligned so that the
number of bytes used to store a line is always divisible by 4. This is called
DWORD alignment. The simplest way to DWORD align the width is to add
3 to the width and zero out bits 0 and 1 of the value. Any number that is
divisible by 4 will have 0 in bits 0 and 1. We can zero bits 0 and 1 by
bitwise And-ing the number with the complement of 3, a number that has
every bit set apart from bits 0 and 1. Then we create a BYTE buffer to
store our pixel data and read the image data one scan line at a time.
BOOL CTGA::Load(CFile &tgaFile)
int bytesRead;
bytesRead = tgaFile.Read( &tgaHdr, sizeof(TGAHEADER));
if (bytesRead != sizeof(BITMAPFILEHEADER)) {
TRACE(”CTGA::Load>> Failed to read file header”);
return FALSE;
// Skip image ID
if (tgaHdr.CmapType != 0 || tgaHdr.PixelDepth!=24 ||
tgaHdr.ImageType != TGA_RGB){
TRACE(”CTGA::Load>> Only 24 bit RGB files are supported.”);
return FALSE;
int width = tgaHdr.ImageWidth * 3;
width = (width + 3) & ~3; //DWORD align
BYTE *bits = new BYTE[width * tgaHdr.ImageHeight];
if (!ReadImage(tgaFile, tgaHdr, bits)){
if (m_hdr) delete m_hdr;
m_hdr = NULL;
if (m_bits) delete [] m_bits;
m_bits = NULL;
delete [] bits;
return FALSE;
Search Nedrilad ::

Custom Search