简体   繁体   中英

Displaying a bitmap in 13h graphics mode, with use of C++

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);
}

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 (ie 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM