I found a function on the 'net which is supposed to load an 8bit bitmap and display it. I think the problem is it loads it but doesn't display it - if this is the case, could somebody tell me how I should display it?
Here it is:
Code:
/* LoadBMP(): Loads an 8bit Bitmap */
int LoadBMP (char *filename)
{
FILE *BMPFile;
unsigned char c, Palette[256][4];
unsigned int offset, lines, paddedWidth;
/* This checks for the file */
BMPFile = fopen(filename, "rb");
if (BMPFile == NULL)
{
printf("Cant open file.");
return 1;
}
/* Read the header information */
fread(&Header, 54, 1, BMPFile);
if (Header.bfType != 19778 || Header.bfReserved != 0 || Header.biPlanes != 1)
{
/* Not a valid bitmap file - don't display */
printf("Not a valid bitmap.");
fclose(BMPFile);
return 1;
}
if (Header.biCompression != 0)
{
/* Compressed file - don't display */
printf("Compressed file.");
fclose(BMPFile);
return 1;
}
if (Header.biBitCount != 8)
{
/* If the file is other than 8-bit dont read. */
printf("Not an 8-bit bitmap.");
fclose(BMPFile);
return 1;
}
if (Header.biWidth > 320 || Header.biHeight > 200)
{
/* If its larger than 320*200 dont load. */
printf("Size too large.");
fclose(BMPFile);
return 1;
}
/* Load the palette info */
fread(&Palette, 1024, 1, BMPFile);
for (c = 0; c < 255; c++)
SetDAC(c, Palette[c][2] >> 2, Palette[c][1] >> 2, Palette[c][0] >> 2);
offset = (100 + (Header.biHeight >> 1)) * 320 + 160 - (Header.biWidth >> 1);
lines = 0;
paddedWidth = Header.biWidth & 0xFFFC;
if (Header.biWidth != paddedWidth)
paddedWidth += 4;
/* Loop for reading lines */
while (lines < Header.biHeight)
{
fread(VideoRAM + offset, paddedWidth, 1, BMPFile);
offset -= 320;
lines++;
}
fclose(BMPFile);
return 0;
}
Sorry about the spazzy layout, I copied and pasted it from my IDE.
It's probably a really n00bish problem