home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP03 / TGA32.HPP < prev   
C/C++ Source or Header  |  1996-02-20  |  2KB  |  62 lines

  1. //
  2. // A class to read 256-color, uncompressed, TGA images
  3. // in 32-bit mode.
  4. //
  5. // Written by John De Goes
  6. //
  7.  
  8. #include <Stdio.h>
  9.  
  10. typedef unsigned char BYTE;
  11. typedef short unsigned int WORD;
  12. typedef unsigned long DWORD;
  13.  
  14.  
  15. // A TGA header. I use the word "palette" instead of 
  16. // TGA's "color map".
  17. struct TGAHeader {
  18. BYTE IDLength;       // The length of the text identification
  19. BYTE PaletteType;    // This is really a color map type
  20. BYTE ImageType;      // 0 = no image data; 1 = uncompressed
  21.                      // color mapped; 2 = uncompressed true color
  22. WORD FirstColor;     // Tells which palette color to start with
  23. WORD PaletteColors;  // Number of colors in the palette
  24. BYTE PaletteEntrySize;    // Number of bits per palette entry
  25. WORD Left;                // Just what you think it is...
  26. WORD Top;                 // Just what you think it is...
  27. WORD ImageWidth;          // Just what you think it is...
  28. WORD ImageHeight;         // Just what you think it is...
  29. BYTE PixelBits;           // The number of bits per pixel
  30. BYTE DescriptorBits; // The image orientation
  31. int Load(FILE *File);
  32. };
  33.  
  34. // A TGA class
  35. class TGAImage {
  36. public:
  37. // Constructer
  38. TGAImage() { ImageID = NULL; Image = NULL; Palette = NULL; }
  39.  
  40. // Destructer - deallocate memory:
  41. ~TGAImage()
  42.   {
  43.   if ( ImageID )
  44.      delete [] ImageID;
  45.   if ( Image != NULL )
  46.      delete [] Image;
  47.   if ( Palette != NULL )
  48.      delete [] Palette;
  49.   }
  50. // The TGA header
  51. TGAHeader Header;
  52. // The image ID
  53. BYTE *ImageID;
  54. // The Image
  55. BYTE *Image;
  56. // The palette
  57. BYTE *Palette;
  58. // The width, height, and size of image
  59. int Width, Height, ImageSize;
  60. // The function to load the TGA image
  61. int Load(char *FileName);
  62. };