The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPImageIO Class Reference

#include <imageio.h>

List of all members.

Public Member Functions

BITMAPINFOHEADER LoadBitmapHeader (char *inFile)
void LoadBitmapPixels (BYTE *bitPixels, char *inFile, BITMAPINFOHEADER &bmih)
BITMAPINFOHEADER LoadBmp (BYTE *bitPixels, char *inFile)
int WriteBitmap (float *float_pBuffer, long lBufferSize, int lWidth, int lHeight, char *m_szSnappedName, int bitcount, bool flipped)
int WriteBitmap (unsigned char *pBuffer, long lBufferSize, int lWidth, int lHeight, char *m_szSnappedName, int bitcount=24)


Member Function Documentation

BITMAPINFOHEADER LoadBitmapHeader char *  inFile  ) 
 

Definition at line 200 of file imageio.cpp.

References BITMAPFILEHEADER, and BITMAPINFOHEADER.

00201 {
00202         BITMAPINFOHEADER bmih;
00203         ifstream is(inFile, ios::binary);
00204         is.seekg(sizeof(BITMAPFILEHEADER), ios_base::beg );
00205         is.read((char*) &bmih, sizeof( bmih ));
00206         is.close();
00207         return(bmih);
00208 }

void LoadBitmapPixels BYTE *  bitPixels,
char *  inFile,
BITMAPINFOHEADER bmih
 

Definition at line 212 of file imageio.cpp.

References BITMAPFILEHEADER, BITMAPINFOHEADER, BYTE, p, and y.

00213 {
00214         BITMAPFILEHEADER bmfh;
00215         int remainder;
00216         unsigned char * tempPixArray;
00217 
00218         ifstream is(inFile, ios::binary);
00219         is.read((char*) &bmfh, sizeof( bmfh ));
00220         is.seekg(sizeof(bmih), ios_base::cur);
00221 
00222         remainder = (4 - bmih.biWidth % 4) % 4;
00223         int size = bmfh.bfSize-bmfh.bfOffBits;
00224         int temp = bmfh.bfOffBits - 54;
00225         tempPixArray = new BYTE[size];
00226         
00227         if (bmih.biBitCount == 24)
00228         {
00229                 is.read((char*)bitPixels, size);
00230         }
00231 
00232         if (bmih.biBitCount == 8)
00233         {
00234                 is.read((char*)tempPixArray, temp);
00235                 is.read((char*)tempPixArray, size);
00236                 
00237         }
00238         
00239         //flip image
00240         int pos =0;
00241         if(bmih.biBitCount == 8){
00242                 for(int y = bmih.biHeight - 1; y >= 0; y--){
00243                         for(int x = 0; x < bmih.biWidth; x++){
00244                                 //is only functional if rgb(24 bit)
00245                                 for(int p = 0; p < bmih.biBitCount/8; p++){
00246                                         bitPixels[pos] = tempPixArray[x+y*bmih.biWidth+p];
00247                                         pos++;
00248                                 }
00249                         }
00250                 }
00251         } 
00252         
00253         delete [] tempPixArray;
00254 
00255 }

BITMAPINFOHEADER LoadBmp BYTE *  bitPixels,
char *  inFile
 

int WriteBitmap float *  float_pBuffer,
long  lBufferSize,
int  lWidth,
int  lHeight,
char *  m_szSnappedName,
int  bitcount,
bool  flipped
 

Definition at line 104 of file imageio.cpp.

References BITMAPFILEHEADER, BITMAPINFOHEADER, BYTE, i, n, and y.

00105 {
00106         int extrabytes = (4 - lWidth % 4) % 4;
00107         const int size = ((lWidth+extrabytes)*lHeight)*(bitcount/8);
00108         const int imSize = (lWidth*lHeight)*(bitcount/8);
00109         BYTE * tempbuffer;
00110         BYTE * pBuffer = new BYTE[imSize];
00111         BYTE *temp;
00112         float *ftemp;
00113         int pos = 0;
00114 
00115         if(flipped) temp = &pBuffer[0];
00116         else temp = &pBuffer[imSize-1];
00117         ftemp = float_pBuffer;
00118         // switch from float to unsigned char
00119         for(int height = 0; height < lHeight; height++) { 
00120                 int y = height;
00121                 if(!flipped) y = lHeight-y;
00122                 for (int width = 0; width < lWidth; width++) {
00123                         for(int bitSize = 0; bitSize < bitcount/8; bitSize++){
00124                                 if (flipped) *temp++ = static_cast<unsigned char>(*ftemp++);
00125                                 else *temp-- = static_cast<unsigned char>(*ftemp++);
00126                         }
00127                 }
00128         }
00129 
00130         /*if width is not multple of four then extra bytes need to be added*/
00131         if(extrabytes){
00132                 int pos = 0;
00133                 tempbuffer = new BYTE[size];
00134                 for(int y=0;y<lHeight;y++){
00135                         for(int x =0; x< lWidth;x++)
00136                         {
00137                                 tempbuffer[pos] = pBuffer[x+y*lWidth];
00138                                 pos++;
00139                         }
00140                         for(x = 0; x < extrabytes*(bitcount/8); x++)
00141                         {
00142                                 tempbuffer[pos] = 0;
00143                                 pos++;
00144                         }
00145                 }
00146                 lBufferSize = pos;
00147         }
00148 
00149         BITMAPFILEHEADER bfh;
00150         BITMAPINFOHEADER bih;
00151         ofstream os(m_szSnappedName, ios::binary);
00152         memset( &bfh, 0, sizeof( bfh ) );
00153         bfh.bfType = 'MB';
00154         bfh.bfSize = sizeof( bfh ) + lBufferSize + sizeof( BITMAPINFOHEADER );
00155         if(bitcount == 24)
00156                 bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );
00157         else if(bitcount == 8)
00158                 bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER ) + 1024;
00159         //bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );
00160         os.write((char*)&bfh, sizeof(bfh)); 
00161         //os.flush();
00162         memset( &bih, 0, sizeof( bih ) );
00163         bih.biSize = sizeof( bih );
00164         bih.biWidth = lWidth;
00165         bih.biHeight = lHeight;
00166         bih.biPlanes = 1;
00167         bih.biBitCount = bitcount;
00168         os.write((char*)&bih, sizeof(bih));
00169         //os.flush();
00170         /*adds header buffer needed for 8 bit*/
00171         if(bitcount == 8)
00172         {
00173                 unsigned char update = 0;
00174                 unsigned char buffArray[1024];
00175                 int i = 0;
00176                 while(i < 1024)
00177                 {
00178                         for(int n = 0; n < 3; n++,i++)
00179                                 buffArray[i] = update;
00180                         update++;
00181                         buffArray[i] = 0;
00182                         i++;
00183                 }
00184                 os.write((char*)buffArray, 1024);
00185         }
00186         /*adds extrabyte buffer for every row*/
00187         if(extrabytes){
00188                 os.write((char*)tempbuffer, sizeof(char)*lBufferSize);
00189                 delete [] tempbuffer;
00190         }
00191         else
00192                 os.write((char*)pBuffer, sizeof(char)*lBufferSize);
00193         //os.flush();
00194         os.close();
00195         return 0;
00196 }

int WriteBitmap unsigned char *  pBuffer,
long  lBufferSize,
int  lWidth,
int  lHeight,
char *  m_szSnappedName,
int  bitcount = 24
 

Definition at line 27 of file imageio.cpp.

References BITMAPFILEHEADER, BITMAPINFOHEADER, BYTE, i, n, and y.

Referenced by MPColorTracker::WriteBitmap().

00028 {
00029         int extrabytes = (4 - lWidth % 4) % 4;
00030         const int size = ((lWidth+extrabytes)*lHeight)*(bitcount/8);
00031         unsigned char * tempbuffer;
00032         int pos = 0;
00033 
00034         /*if width is not multple of four then extra bytes need to be added*/
00035         if(extrabytes){
00036                 int pos = 0;
00037                 tempbuffer = new BYTE[size];
00038                 for(int y=0;y<lHeight;y++){
00039                         for(int x =0; x< lWidth;x++)
00040                         {
00041                                 tempbuffer[pos] = pBuffer[x+y*lWidth];
00042                                 pos++;
00043                         }
00044                         for(x = 0; x < extrabytes*(bitcount/8); x++)
00045                         {
00046                                 tempbuffer[pos] = 0;
00047                                 pos++;
00048                         }
00049                 }
00050                 lBufferSize = pos;
00051         }
00052 
00053         BITMAPFILEHEADER bfh;
00054         BITMAPINFOHEADER bih;
00055         ofstream os(m_szSnappedName, ios::binary);
00056         memset( &bfh, 0, sizeof( bfh ) );
00057         bfh.bfType = 'MB';
00058         bfh.bfSize = sizeof( bfh ) + lBufferSize + sizeof( BITMAPINFOHEADER );
00059         if(bitcount == 24)
00060                 bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );
00061         else if(bitcount == 8)
00062                 bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER ) + 1024;
00063         //bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );
00064         os.write((char*)&bfh, sizeof(bfh)); 
00065         //os.flush();
00066         memset( &bih, 0, sizeof( bih ) );
00067         bih.biSize = sizeof( bih );
00068         bih.biWidth = lWidth;
00069         bih.biHeight = lHeight;
00070         bih.biPlanes = 1;
00071         bih.biBitCount = bitcount;
00072         os.write((char*)&bih, sizeof(bih));
00073         //os.flush();
00074         /*adds header buffer needed for 8 bit*/
00075         if(bitcount == 8)
00076         {
00077                 unsigned char update = 0;
00078                 unsigned char buffArray[1024];
00079                 int i = 0;
00080                 while(i < 1024)
00081                 {
00082                         for(int n = 0; n < 3; n++,i++)
00083                                 buffArray[i] = update;
00084                         update++;
00085                         buffArray[i] = 0;
00086                         i++;
00087                 }
00088                 os.write((char*)buffArray, 1024);
00089         }
00090         /*adds extrabyte buffer for every row*/
00091         if(extrabytes){
00092                 os.write((char*)tempbuffer, sizeof(char)*lBufferSize);
00093                 delete [] tempbuffer;
00094         }
00095         else
00096                 os.write((char*)pBuffer, sizeof(char)*lBufferSize);
00097         //os.flush();
00098         os.close();
00099         return 0;
00100 }


The documentation for this class was generated from the following files:
Generated on Mon Nov 8 17:08:37 2004 for MPT by  doxygen 1.3.9.1