Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

CImage Class Reference

#include <ATGAImage.h>

List of all members.

Public Methods

 CImage ()
virtual ~CImage ()
void DecodeT10Tga24 (const tgaHeader &Header, int &nImageSize)
void DecodeT2Tga24 (const tgaHeader &Header, const int &nImageSize)
void DecodeT10Tga16 (const tgaHeader &Header, const int &nImageSize)
void DecodeT2Tga16 (const tgaHeader &Header, const int &nImageSize)
void LoadBmp (const string &strFileName)
void LoadTga (const string &strFileName)
UBYTEGetImageData ()
UBYTE GetBPP ()
UINT GetHeight ()
UINT GetWidth ()
void SetAlpha (UBYTE AlphaValue)
void bAlphaChannel (bool bAlpha)
void LoadRaw (const string &strName, int nSize)

Private Attributes

UBYTEm_ubImageData
UINT m_dwHeight
UINT m_dwWidth
UBYTE m_ubBpp
bool m_bAlpha
UBYTE m_ubAlphaValue


Constructor & Destructor Documentation

CImage::CImage  
 

Definition at line 28 of file ATGAImage.cpp.

References m_bAlpha, m_dwHeight, m_dwWidth, m_ubAlphaValue, m_ubBpp, and m_ubImageData.

00029 {
00030         m_ubImageData = NULL;
00031         m_dwHeight = 0;
00032         m_dwWidth = 0;
00033         m_ubBpp = 0;
00034         m_ubAlphaValue = 128;
00035         m_bAlpha = false;
00036 }

CImage::~CImage   [virtual]
 

Definition at line 38 of file ATGAImage.cpp.

00039 {
00040 /*      if (m_ubImageData != NULL)
00041                 delete [] m_ubImageData;
00042         m_ubImageData = NULL;*/
00043 }


Member Function Documentation

void CImage::bAlphaChannel bool    bAlpha
 

Definition at line 243 of file ATGAImage.cpp.

References m_bAlpha.

00244 {
00245         m_bAlpha = bAlpha;
00246 }

void CImage::DecodeT10Tga16 const tgaHeader   Header,
const int &    nImageSize
[inline]
 

void CImage::DecodeT10Tga24 const tgaHeader   Header,
int &    nImageSize
[inline]
 

Definition at line 137 of file ATGAImage.cpp.

References tgaHeader::Height, m_ubAlphaValue, m_ubBpp, m_ubImageData, UBYTE, and tgaHeader::Width.

Referenced by LoadTga().

00138 {
00139         UBYTE p[4];
00140 
00141         int tempImageSize;
00142 
00143         if (m_bAlpha)
00144                         tempImageSize = Header.Width * Header.Height * 4;
00145                 else
00146                         tempImageSize = nImageSize;
00147 
00148         UBYTE * TempData = new UBYTE [nImageSize];
00149         if (TempData != NULL)
00150         {
00151                 memcpy(TempData, m_ubImageData, sizeof(UBYTE) * tempImageSize);
00152         }
00153         
00154         int nReadCnt = 0;
00155 
00156         UBYTE ubPacketInfo;
00157         short PacketType;
00158         short PixelCount;
00159 
00160         for (int i = 0; i < tempImageSize; /*i +=m_ubBpp */)
00161         {
00162                 ubPacketInfo = TempData[nReadCnt];
00163                 nReadCnt++;
00164 
00165                 // Check to see if it's encoded RLE or not
00166                 PacketType = 0x80 & ubPacketInfo;
00167 
00168                 // Get number of pixels in run - can go beyond current line
00169                 //short PixelCount2 = ( 0x007f & ubPacketInfo );
00170                 PixelCount = ubPacketInfo;
00171 
00172                 if (PixelCount < 128)
00173                         PixelCount++;
00174                 else
00175                         PixelCount -= 127;
00176 
00177                 if (PacketType)
00178                 {
00179                         // read the colors swap BGAR to RGBA
00180                         p[3] = TempData[nReadCnt + 0]; // B
00181                         p[2] = TempData[nReadCnt + 1]; // G
00182                         p[1] = TempData[nReadCnt + 2]; // R
00183 
00184                         nReadCnt += 3;
00185 
00186                         if (m_ubBpp == 4)
00187                                 p[0] = TempData[nReadCnt + 3];  //change when done
00188                         else if (m_bAlpha)
00189                         {
00190                                 p[0] = m_ubAlphaValue;          // Alpha channel color change to variable
00191                         }
00192 
00193                         
00194                         while(PixelCount--)
00195                         {
00196                                 // read the colors swap BGAR to RGBA
00197                                 m_ubImageData[i++] = p[1];
00198                                 m_ubImageData[i++] = p[2];
00199                                 m_ubImageData[i++] = p[3];
00200 
00201                                 if (m_ubBpp == 4)
00202                                         m_ubImageData[i++] = p[0];
00203                                 else if (m_bAlpha)
00204                                         m_ubImageData[i++] = p[0];              // Alpha channel color change to variable*/
00205 
00206                         }
00207                 }
00208                 else
00209                 {
00210                         while(PixelCount--)
00211                         {
00212                                 p[3] = TempData[nReadCnt + 0]; // B
00213                                 p[2] = TempData[nReadCnt + 1]; // G
00214                                 p[1] = TempData[nReadCnt + 2]; // R
00215 
00216                                 nReadCnt += 3;
00217                                 m_ubImageData[i++] = p[1];
00218                                 m_ubImageData[i++] = p[2];
00219                                 m_ubImageData[i++] = p[3];
00220 
00221                                 if (m_ubBpp == 4)
00222                                 {
00223                                         m_ubImageData[i++] = TempData[nReadCnt];
00224                                 
00225                                         nReadCnt++;
00226                                 }
00227                                 else if (m_bAlpha)
00228                                 {
00229                                         m_ubImageData[i++] = m_ubAlphaValue;            // Alpha channel color change to variable
00230                                 }
00231                         }
00232                 }       
00233         }
00234 
00235         delete [] TempData;
00236 }

void CImage::DecodeT2Tga16 const tgaHeader   Header,
const int &    nImageSize
[inline]
 

void CImage::DecodeT2Tga24 const tgaHeader   Header,
const int &    nImageSize
[inline]
 

Definition at line 124 of file ATGAImage.cpp.

References m_ubBpp, m_ubImageData, and UBYTE.

Referenced by LoadTga().

00125 {
00126         UBYTE ColorSwap;
00127 
00128         // BGAR to ARGB
00129         for (int i = 0; i < nImageSize; i+=m_ubBpp)
00130         {
00131                 ColorSwap = m_ubImageData[i];
00132                 m_ubImageData[i] = m_ubImageData[i + 2];
00133                 m_ubImageData[i + 2] = ColorSwap;
00134         }
00135 }

UBYTE CImage::GetBPP  
 

Definition at line 108 of file ATGAImage.cpp.

References m_ubBpp, and UBYTE.

00109 {
00110         return m_ubBpp;
00111 }

UINT CImage::GetHeight  
 

Definition at line 113 of file ATGAImage.cpp.

References m_dwHeight, and UINT.

Referenced by terrain_create().

00114 {
00115         return m_dwHeight;
00116 }

UBYTE * CImage::GetImageData  
 

Definition at line 102 of file ATGAImage.cpp.

References m_ubImageData, and UBYTE.

Referenced by terrain_create().

00103 {
00104         return m_ubImageData;
00105 }

UINT CImage::GetWidth  
 

Definition at line 118 of file ATGAImage.cpp.

References m_dwWidth, and UINT.

Referenced by terrain_create().

00119 {
00120         return m_dwWidth;
00121 }

void CImage::LoadBmp const string &    strFileName
 

Definition at line 45 of file ATGAImage.cpp.

00046 {
00047         
00048 }

void CImage::LoadRaw const string &    strName,
int    nSize
 

Definition at line 248 of file ATGAImage.cpp.

References m_ubBpp, m_ubImageData, and UBYTE.

00249 {
00250         FILE *pFile = NULL;
00251         m_ubBpp = 1;
00252 
00253         // Open The File In Read / Binary Mode.
00254         pFile = fopen(strName.data(), "rb");
00255 
00256         // Check To See If We Found The File And Could Open It
00257         if (pFile == NULL)
00258         {
00259                 // Display Error Message And Stop The Function
00260                 MessageBox(NULL, "Can't Find The Height Map!", "Error", MB_OK);
00261                 return;
00262         }
00263 
00264         m_ubImageData = new UBYTE [nSize];
00265         fread(m_ubImageData, 1, nSize, pFile);
00266 
00267         // After We Read The Data, It's A Good Idea To Check If Everything Read Fine
00268         int result = ferror(pFile);
00269 
00270         // Check If We Received An Error
00271         if (result)
00272         {
00273                 MessageBox(NULL, "Failed To Get Data!", "Error", MB_OK);
00274         }
00275 
00276         // Close The File.*/
00277         fclose(pFile);
00278 }

void CImage::LoadTga const string &    strFileName
 

Definition at line 50 of file ATGAImage.cpp.

References tgaHeader::BitsPerPixel, tgaHeader::DataTypeCode, DecodeT10Tga24(), DecodeT2Tga24(), tgaHeader::Height, m_dwHeight, m_dwWidth, m_ubBpp, m_ubImageData, UBYTE, and tgaHeader::Width.

Referenced by terrain_create().

00051 {
00052         FILE* pFile;
00053         tgaHeader Header;
00054 
00055         pFile = fopen(strFileName.data(), "rb");
00056 
00057         if (!pFile)
00058         {
00059                 return;
00060         }
00061 
00062         // Load header
00063         fread (&Header, sizeof(tgaHeader), 1, pFile);
00064 
00065         m_dwWidth = Header.Width;
00066         m_dwHeight = Header.Height;
00067         m_ubBpp = Header.BitsPerPixel / 8;
00068 
00069         // if we want an alpha channel for the 24 bit graphic and make it 32 bit 
00070         int ColorDepth = m_ubBpp;
00071 
00072         if (m_bAlpha)
00073                 ColorDepth++;
00074 
00075         int nImageSize = m_dwWidth * m_dwHeight * ColorDepth;
00076 
00077         m_ubImageData = new UBYTE [nImageSize];
00078         if (m_ubImageData == NULL)
00079         {
00080                 fclose(pFile);
00081                 return;
00082         }
00083 
00084         // Is the data read equal to the amount we wanted?
00085         if (nImageSize != 
00086                 fread (m_ubImageData, sizeof(UBYTE), nImageSize, pFile) && Header.DataTypeCode == 2)
00087         {
00088                 fclose(pFile);
00089                 return;
00090         }
00091 
00092         if (Header.DataTypeCode == 2)   // uncompressed data
00093                 DecodeT2Tga24(Header, nImageSize);
00094 
00095         else if (Header.DataTypeCode == 10)   // RLE compressed
00096                 DecodeT10Tga24(Header, nImageSize);
00097 
00098         // close file
00099         fclose(pFile);
00100 }

void CImage::SetAlpha UBYTE    AlphaValue
 

Definition at line 238 of file ATGAImage.cpp.

References m_ubAlphaValue.

00239 {
00240         m_ubAlphaValue = AlphaValue;
00241 }


Member Data Documentation

bool CImage::m_bAlpha [private]
 

Definition at line 117 of file ATGAImage.h.

Referenced by bAlphaChannel(), and CImage().

UINT CImage::m_dwHeight [private]
 

Definition at line 114 of file ATGAImage.h.

Referenced by CImage(), GetHeight(), and LoadTga().

UINT CImage::m_dwWidth [private]
 

Definition at line 115 of file ATGAImage.h.

Referenced by CImage(), GetWidth(), and LoadTga().

UBYTE CImage::m_ubAlphaValue [private]
 

Definition at line 118 of file ATGAImage.h.

Referenced by CImage(), DecodeT10Tga24(), and SetAlpha().

UBYTE CImage::m_ubBpp [private]
 

Definition at line 116 of file ATGAImage.h.

Referenced by CImage(), DecodeT10Tga24(), DecodeT2Tga24(), GetBPP(), LoadRaw(), and LoadTga().

UBYTE* CImage::m_ubImageData [private]
 

Definition at line 113 of file ATGAImage.h.

Referenced by CImage(), DecodeT10Tga24(), DecodeT2Tga24(), GetImageData(), LoadRaw(), and LoadTga().


The documentation for this class was generated from the following files:
Generated on Wed Apr 23 05:52:03 2003 for Modern Warfare by doxygen1.3-rc2