All pastes #884573 Raw Edit

aux

public text v1 · immutable
#884573 ·published 2008-01-30 13:34 UTC
rendered paste body
typedef union
{
  unsigned char[3] _c;
  unsigned int rgb;
} uPixel;

// ... somewhere there is a struct containing all header info sequentially

void read()
{
   std::ifstream _file;
   _file.open("somefile.bmp", std::ios::in | std::ios::binary);
   
   // new struct header obj
   bithdr_t _hdr;

   // read all header info
   _file((char*)&_hdr, sizeof(_hdr));

   
   uPixel* pixel = new uPixel[_hdr.length];
   
   // HERE IS THE PROBLEM...
   unsigned int n = 0;
   while(n < _hdr.datablock_len)
   {
      ++n;

     // THIS MUST BE WRONG and it will read up to 4bytes, because of the int inside the union .....
      _file.read((char*)&pixel[n], sizeof(uPixel));
   }

   _file.close();  
}