I've done this about a billion times and yet this time its not working right.
This is insane. Here is the code.
This header is just the two headers in the SDK merged together.
Code:
struct VoxelRGB
{
__int8 red;
__int8 green;
__int8 blue;
};
struct BMPHeader
{
__int16 Type;
__int32 Size;
__int32 Reserved;
__int32 Offset;
__int32 HeaderSize;
__int32 Width;
__int32 Height;
__int16 Planes;
__int16 BitsPerPixel;
__int32 Compression;
__int32 ImageSize;
__int32 XPixelsPerMeter;
__int32 YPixelsPerMeter;
__int32 ColorsUsed;
__int32 ColorsImportant;
};
BMPHeader ColorMapInfo;
...
...
void LoadBMPColorMap(std::string File,VoxelRGB *Map,BMPHeader bmpinfo);
...
...
void Setup(void)
{
LoadBMPColorMap("blah blah blah",ColorMap,ColorMapInfo);
}
void LoadBMPColorMap(std::string File,VoxelRGB *Map,BMPHeader bmpinfo)
{
FILE *fp;
fp=fopen(File.c_str(),"rb");
fread(&bmpinfo,sizeof(BMPHeader),1,fp);
char txt[10];
//Just to be sure
memset(txt,0,10);
//Problem here??
sprintf(txt,"%lu",bmpinfo.Size);
MessageBox(0,txt,0,0);
fclose(fp);
}
The Type field is correct with 0x4D42 which means it's reading the first __int16 right. Then it proceeds to tell me that the Size is only 3 bytes??? Stupid. I opened this file in QuickBasic 7.1 and read the Size member and it was correct. The file is good but for some stupid reason my code doesn't work. Either I'm not using sprintf() right which is showing erroneous values or something else is wrong.
I even commented out all dynamic memory allocation prior to this function. The only thing happening is the loading of the bmpheader, but it doesn't work?
I've tried _read,_open, fread, fopen, etc. All have the same result. WTH is going on?
I feel stupid for asking this.
Structure alignment is 8 bytes, but I have changed it and the same thing happens. The file is 256x256 in 32 bit color. Something somewhere is fragging my structure alignment.
I even took out the code that loaded the image data into the VoxelRGB map. It made no difference and it didn't work because the width was being reported well into the billions. Trying to access memory using y*width+x when width is near 3 billion...well Windows doesn't like that. Clearly an alignment problem somewhere.
But if the first __int16 is correct, how can the member immediately following that one be off?? Weird.
Sorry I can't post the entire program here....it's enormous.