Reputation: 63
I'm trying to display a 320x200x8 bitmap. I got the palette working just fine, but when i try to display the bits, the image is upside down. What should be changed here?
void display_image_data(char *file_name)
{
bitmap_file = fopen(file_name, "rb");
fread(&bmfh, sizeof(bmfh), 1, bitmap_file);
fread(&bmih, sizeof(bmih), 1, bitmap_file);
fread(&palette[0], bmih.biClrUsed * sizeof(RGBQUAD), 1, bitmap_file);
fread(&video_memory[0], bmih.biWidth * bmih.biHeight, 1, bitmap_file);
fclose(bitmap_file);
}
Upvotes: 1
Views: 145
Reputation: 100632
BMP files originate from OS/2 which uses standard graphing axes — the origin is at the lower left of the display and positive y moves up the screen. Data that is stored in OS/2 order and then displayed in raster order will appear to be upside down.
So you just need to read the data line by line and store those lines in the correct places.
It looks like you're already assuming a source file of at most 200 lines and are loading the data directly to the video buffer (i.e. A000:0000
) so the equivalent for you would be as simple as:
for(int y = bmih.biHeight - 1; --y; y >= 0) {
fread(&video_memory[y * 320], bmih.biWidth, 1, bitmap_file);
}
Upvotes: 2