Yeah I figured it out this morning. I opened Wordpad and loaded the source, and it screamed at me. Swapped the parms and it worked fine. And I know explorer rounds. Just have a file-format problem that maybe you can explain.
I am trying to convert Daggerfall IMG files to 24bit bitmaps. The IMG file format is easy enough and consists of a header followed by a linear bitmap. However the bitmap references a palette of RGB data. I know the 24bit bitmap format is BGR, but it isn't comming out right. I want you to see my code and make sure I am going from RGB to BGR properly, or if it's something else. If my bitmap code is correct, then I can concentrate on the old format.
bool ConvertIMG(char *FileName)
{
//About 200 lines from start to here, but left out
//because they deal with reading the old IMG file
BMFH.bfType = 0x4d42;
BMFH.bfSize = ((sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)) + (((sizeof(char) * IMGHeader.Width) * IMGHeader.Height) * 3));
BMFH.bfReserved1 = 0;
BMFH.bfReserved2 = 0;
BMFH.bfOffBits = (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));
BMIH.biSize = sizeof(BITMAPINFOHEADER);
BMIH.biWidth = IMGHeader.Width;
BMIH.biHeight = -IMGHeader.Height;
BMIH.biPlanes = 1;
BMIH.biBitCount = 24;
BMIH.biCompression = BI_RGB;
BMIH.biSizeImage = 0;
BMIH.biXPelsPerMeter = IMGHeader.Width;
BMIH.biYPelsPerMeter = IMGHeader.Height;
BMIH.biClrUsed = 0;
BMIH.biClrImportant = 0;
fwrite(&BMFH, sizeof(BITMAPFILEHEADER), 1, pImageFile);
fwrite(&BMIH, sizeof(BITMAPINFOHEADER), 1, pImageFile);
for(int Loop = 0; Loop < (IMGHeader.Width * IMGHeader.Height); Loop++)
{
fwrite(&(IMGHeader.Palette[pImage[Loop] + 2]), sizeof(char), 1, pImageFile);
fwrite(&(IMGHeader.Palette[pImage[Loop] + 1]), sizeof(char), 1, pImageFile);
fwrite(&(IMGHeader.Palette[pImage[Loop]]), sizeof(char), 1, pImageFile);
}
fclose(pImageFile);
return true;
}
OK, IMGHeader.Palette is a "char[768]". That is a 256-color palette of RGB data in that order. The pImage is a pointer to a "char" array that was dynamically created with enough storage for the linear bitmap data. The bitmap data ranges 0-255 and references an RGB triplet in the palette. Does it look like I setup the two bitmap headers properly? I know I'm putting the RGB data into the new file as BGR, as you can see, but it isn't comming out right. If the bitmap is good, then I can concentrate on finding the right palette. Daggerfall uses like ten different palette-files, of which four are 768b in size and just contain an array of 256 RGB triplets. The others have an 8bit header, then the 256 RGB triplets.
And on a final note, Daggerfall is a 16bit DOS game, so the files are byte-aligned. I read in the data like this:
//This would read int he first four header vars
short int XOffset, YOffset;
short int Width, Height;
...
fread(&XOffset, sizeof(char[2]), 1, File);
fread(&YOffset, sizeof(char[2]), 1, File);
fread(&Width, sizeof(char[2]), 1, File);
fread(&Height, sizeof(char[2]), 1, File);
Those variables are "short" in DOS, which are 2bytes in size. I assume this is the correct way to read them in. After all, the image comes out nearly-perfect, but off-color. Thanks for the help!
-
Sephiroth