Thanks iMalc, everything you write makes sense.
So just to clarify, if I have the number 127 and I put it in a signed integer, if will come out as zero? Regardless of the fact that in the original file it was 127?
Over the 24 bit thing, yeah I was wondering whether I needed to unsign it, and then break it into three bytes, rather than what currently seems like one large number - but actually to compare two images that isnt going to make the difference...Yeah you are right BTW it is 24 bit bitmaps.
Reading around, I should be making an array like:
Code:
std::vector<std::bitset<24> > pixel;
or
Code:
struct ThreeBytes {
uint32_t value:24;
};
Then declaring a new one like:
Code:
ThreeBytes *pixel= new ThreeBytes[dInfo.imageWidth][dInfo.imageHeight];
However that gives me this error:
error: 'dInfo' cannot appear in a constant-expression
Yeah, I can see why reading sizeof(pixel) is so wrong. Have made a variable at the start that is the size now...
EDIT:
I think from rechecking the bitmpa format, each pixel maybe 32 bit because the last byte is padding...
So in other words I need to break it down to bytes (4 of them) and display only the first three?
So I have changed my method to this:
Code:
void displayPixelData(fstream &dFile, Image &dInfo)
{
unsigned int pixel[dInfo.imageWidth][dInfo.imageHeight];
unsigned char bytes[4];
int imageSize = sizeof(pixel[0][0]);
for(int i = 0; i < dInfo.imageWidth; i++)
{
for(int j = 0; j < dInfo.imageHeight; j++)
{
dFile.seekg(dInfo.offSet + i);
dFile.read(reinterpret_cast<char *>(&pixel[i][j]), imageSize);
bytes[0] = (pixel[i][j] >> 24) & 0xFF;
bytes[1] = (pixel[i][j] >> 16) & 0xFF;
bytes[2] = (pixel[i][j] >> 8) & 0xFF;
bytes[3] = pixel[i][j] & 0xFF;
printf("%x %x %x %x", bytes[0], bytes[1], bytes[2], bytes[3]);
//cout << pixel[i][j] << ",";
}
cout <<","<< endl;
}
Does that improve things?