#include <TAPsBitmapImageHandler.hpp>

Public Member Functions | |
| bool | Available () const |
| BitmapImage () | |
| unsigned char *const | GetConstPtrToImageData () const |
| unsigned int | GetHeight () const |
| unsigned int | GetImageSize () const |
| unsigned int | GetWidth () const |
| bool | LoadBitmapFile (char *pcFileName) |
| ~BitmapImage () | |
Private Types | |
| typedef struct BitmapImage::tagBITMAPFILEHEADER | BITMAPFILEHEADER |
| typedef struct BitmapImage::tagBITMAPINFOHEADER | BITMAPINFOHEADER |
Private Attributes | |
| BITMAPINFOHEADER | m_pBitmapInfoHeader_st |
| unsigned char * | m_pucBitmapImage |
Static Private Attributes | |
| static const WORD | SM_BITMAP_ID = 0x4D42 |
Classes | |
| struct | tagBITMAPFILEHEADER |
| struct | tagBITMAPINFOHEADER |
Definition at line 38 of file TAPsBitmapImageHandler.hpp.
typedef struct BitmapImage::tagBITMAPFILEHEADER BitmapImage::BITMAPFILEHEADER [private] |
typedef struct BitmapImage::tagBITMAPINFOHEADER BitmapImage::BITMAPINFOHEADER [private] |
| BitmapImage::BitmapImage | ( | ) | [inline] |
Definition at line 68 of file TAPsBitmapImageHandler.hpp.
00069 { 00070 m_pucBitmapImage = NULL; 00071 } // END: Constructor
| BitmapImage::~BitmapImage | ( | ) | [inline] |
Definition at line 75 of file TAPsBitmapImageHandler.hpp.
00076 { 00077 // reclaim the allocated memory if any 00078 if ( m_pucBitmapImage != NULL ) { 00079 delete [] m_pucBitmapImage; 00080 m_pucBitmapImage = NULL; 00081 } 00082 } // END: Destructor
| bool BitmapImage::Available | ( | ) | const [inline] |
Definition at line 236 of file TAPsBitmapImageHandler.hpp.
00236 { 00237 return m_pucBitmapImage != NULL ? true : false; 00238 } // END: Available()
| unsigned char* const BitmapImage::GetConstPtrToImageData | ( | ) | const [inline] |
Definition at line 230 of file TAPsBitmapImageHandler.hpp.
00230 { 00231 return m_pucBitmapImage; 00232 } // END: GetConstPtrToImageData()
| unsigned int BitmapImage::GetHeight | ( | ) | const [inline] |
Definition at line 217 of file TAPsBitmapImageHandler.hpp.
00217 { 00218 //return m_ucHeight; 00219 return static_cast<unsigned int>( m_pBitmapInfoHeader_st.biHeight ); 00220 } // END: GetHeight()
| unsigned int BitmapImage::GetImageSize | ( | ) | const [inline] |
Definition at line 224 of file TAPsBitmapImageHandler.hpp.
00224 { 00225 return static_cast<unsigned int>( m_pBitmapInfoHeader_st.biSizeImage ); 00226 } // END: GetImageSize()
| unsigned int BitmapImage::GetWidth | ( | ) | const [inline] |
Definition at line 210 of file TAPsBitmapImageHandler.hpp.
00210 { 00211 return static_cast<unsigned int>( m_pBitmapInfoHeader_st.biHeight ); 00212 //return m_ucWidth; 00213 } // END: GetWidth()
| bool BitmapImage::LoadBitmapFile | ( | char * | pcFileName | ) | [inline] |
Definition at line 87 of file TAPsBitmapImageHandler.hpp.
00088 { 00089 FILE *filePtr; // the file pointer 00090 BITMAPFILEHEADER bitmapFileHeader; // bitmap file header 00091 unsigned int uiImageIdx = 0; // image index counter 00092 unsigned char ucTempRGB; // swap variable 00093 00094 // reclaim the allocated memory if any 00095 if ( m_pucBitmapImage != NULL ) { 00096 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Erase an old BMP image data\n") ); 00097 delete [] m_pucBitmapImage; 00098 m_pucBitmapImage = NULL; 00099 } 00100 00101 // try to open filename in "read binary" mode 00102 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("sizeof(WORD) = %d\n", sizeof(WORD)) ); 00103 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("sizeof(DWORD) = %d\n", sizeof(DWORD)) ); 00104 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("sizeof(BITMAPFILEHEADER) = %d\n", sizeof(BITMAPFILEHEADER)) ); 00105 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("sizeof(BITMAPINFOHEADER) = %d\n", sizeof(BITMAPINFOHEADER)) ); 00106 00107 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("FileName = %s\n", pcFileName) ); 00108 if ( ( filePtr = fopen( pcFileName, "rb" ) ) == NULL ) { 00109 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("unsucceed opening the BMP image file\n") ); 00110 return false; 00111 } 00112 else { 00113 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("succeed opening the BMP image file\n") ); 00114 } 00115 00116 // read the bitmap file header 00117 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Read the BMP image file header\n") ); 00118 //return false; 00119 //fread( &bitmapFileHeader, sizeof( BITMAPFILEHEADER ), 1, filePtr ); 00120 fread( &bitmapFileHeader.bfType, sizeof( WORD ), 1, filePtr ); 00121 fread( &bitmapFileHeader.bfSize, sizeof( DWORD ), 1, filePtr ); 00122 fread( &bitmapFileHeader.bfReserved1, sizeof( WORD ), 1, filePtr ); 00123 fread( &bitmapFileHeader.bfReserved2, sizeof( WORD ), 1, filePtr ); 00124 fread( &bitmapFileHeader.bfOffBits, sizeof( DWORD ), 1, filePtr ); 00125 00126 // verify that this is a bitmap by checking for the universal bitmap id 00127 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Check whether the BMP image is a bitmap image\n") ); 00128 00129 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("bfType = %d and SM_BITMAP_ID = %d\n", bitmapFileHeader.bfType, SM_BITMAP_ID) ); 00130 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("bfSize = %d\n", bitmapFileHeader.bfSize) ); 00131 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("bfOffbits = %d\n", bitmapFileHeader.bfOffBits) ); 00132 if ( bitmapFileHeader.bfType != SM_BITMAP_ID ) { 00133 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("No, it's not!\n") ); 00134 fclose( filePtr ); 00135 return false; 00136 } 00137 else { 00138 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Yes, it is.\n") ); 00139 } 00140 00141 fseek( filePtr, 14, SEEK_SET ); 00142 00143 // read the bitmap information header 00144 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Read bitmap info header\n") ); 00145 00146 fread( &m_pBitmapInfoHeader_st, sizeof( BITMAPINFOHEADER ), 1, filePtr ); 00147 00148 00149 // HACK 00150 m_pBitmapInfoHeader_st.biSizeImage = m_pBitmapInfoHeader_st.biWidth * m_pBitmapInfoHeader_st.biHeight * 3; 00151 00152 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biSize = %d\n", m_pBitmapInfoHeader_st.biSize) ); 00153 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biWidth = %d\n", m_pBitmapInfoHeader_st.biWidth) ); 00154 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biHeight = %d\n", m_pBitmapInfoHeader_st.biHeight) ); 00155 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biPlanes = %d\n", m_pBitmapInfoHeader_st.biPlanes) ); 00156 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biBitCount = %d\n", m_pBitmapInfoHeader_st.biBitCount) ); 00157 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biCompression = %d\n", m_pBitmapInfoHeader_st.biCompression) ); 00158 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biSizeImage = %d\n", m_pBitmapInfoHeader_st.biSizeImage) ); 00159 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biXPelsPerMeter = %d\n", m_pBitmapInfoHeader_st.biXPelsPerMeter) ); 00160 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biYPelsPerMeter = %d\n", m_pBitmapInfoHeader_st.biYPelsPerMeter) ); 00161 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biClrUsed = %d\n", m_pBitmapInfoHeader_st.biClrUsed) ); 00162 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("biClrImportant = %d\n", m_pBitmapInfoHeader_st.biClrImportant) ); 00163 00164 // move file pointer to beginning of bitmap data 00165 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Go to the start of data\n") ); 00166 fseek( filePtr, bitmapFileHeader.bfOffBits, SEEK_SET ); 00167 00168 // allocate enough memory for the bitmap image data 00169 m_pucBitmapImage = new unsigned char[ m_pBitmapInfoHeader_st.biSizeImage ]; 00170 00171 // verify memory allocation 00172 if ( !m_pucBitmapImage ) { 00173 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Couldn't allocate memory for the texture\n") ); 00174 fclose( filePtr ); 00175 return false; 00176 } 00177 else { 00178 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("memory allocated for the texture, move on\n") ); 00179 } 00180 00181 // read in the bitmap image data 00182 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Read bitmap pixel data\n") ); 00183 fread( m_pucBitmapImage, 1, m_pBitmapInfoHeader_st.biSizeImage, filePtr ); 00184 00185 // make sure bitmap image data was read 00186 //if ( !m_pucBitmapImage ) { 00187 // fclose( filePtr ); 00188 // return false; 00189 //} 00190 00191 // swap the R and B values to get RGB since the bitmap color format is 00192 // in BGR 00193 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Change BGR to RGB\n") ); 00194 for ( uiImageIdx = 0; uiImageIdx < m_pBitmapInfoHeader_st.biSizeImage; uiImageIdx += 3 ) { 00195 ucTempRGB = m_pucBitmapImage[ uiImageIdx ]; 00196 m_pucBitmapImage[ uiImageIdx ] = m_pucBitmapImage[ uiImageIdx + 2 ]; 00197 m_pucBitmapImage[ uiImageIdx + 2 ] = ucTempRGB; 00198 } 00199 00200 // close the file 00201 fclose( filePtr ); 00202 00203 BITMAPIMAGE_H_DEBUG_MODE_BY_PRINTF( ("Done image loading\n") ); 00204 return true; // successful loading 00205 } // END: LoadBitMapFile()
Definition at line 246 of file TAPsBitmapImageHandler.hpp.
unsigned char* BitmapImage::m_pucBitmapImage [private] |
Definition at line 247 of file TAPsBitmapImageHandler.hpp.
BEGIN_NAMESPACE_TAPs const WORD BitmapImage::SM_BITMAP_ID = 0x4D42 [static, private] |
Definition at line 244 of file TAPsBitmapImageHandler.hpp.
1.5.6