home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cutting-Edge 3D Game Programming with C++
/
CE3DC++.ISO
/
BOOK
/
CHAP03
/
TGA32.HPP
< prev
Wrap
C/C++ Source or Header
|
1996-02-20
|
2KB
|
62 lines
//
// A class to read 256-color, uncompressed, TGA images
// in 32-bit mode.
//
// Written by John De Goes
//
#include <Stdio.h>
typedef unsigned char BYTE;
typedef short unsigned int WORD;
typedef unsigned long DWORD;
// A TGA header. I use the word "palette" instead of
// TGA's "color map".
struct TGAHeader {
BYTE IDLength; // The length of the text identification
BYTE PaletteType; // This is really a color map type
BYTE ImageType; // 0 = no image data; 1 = uncompressed
// color mapped; 2 = uncompressed true color
WORD FirstColor; // Tells which palette color to start with
WORD PaletteColors; // Number of colors in the palette
BYTE PaletteEntrySize; // Number of bits per palette entry
WORD Left; // Just what you think it is...
WORD Top; // Just what you think it is...
WORD ImageWidth; // Just what you think it is...
WORD ImageHeight; // Just what you think it is...
BYTE PixelBits; // The number of bits per pixel
BYTE DescriptorBits; // The image orientation
int Load(FILE *File);
};
// A TGA class
class TGAImage {
public:
// Constructer
TGAImage() { ImageID = NULL; Image = NULL; Palette = NULL; }
// Destructer - deallocate memory:
~TGAImage()
{
if ( ImageID )
delete [] ImageID;
if ( Image != NULL )
delete [] Image;
if ( Palette != NULL )
delete [] Palette;
}
// The TGA header
TGAHeader Header;
// The image ID
BYTE *ImageID;
// The Image
BYTE *Image;
// The palette
BYTE *Palette;
// The width, height, and size of image
int Width, Height, ImageSize;
// The function to load the TGA image
int Load(char *FileName);
};