[英]Displaying a bitmap in 13h graphics mode, with use of C++
I'm trying to display a 320x200x8 bitmap.我正在尝试显示 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. BMP 文件源自使用标准图形轴的 OS/2 — 原点位于显示屏的左下方,正 y 向上移动屏幕。 Data that is stored in OS/2 order and then displayed in raster order will appear to be upside down.
以 OS/2 顺序存储然后以光栅顺序显示的数据将看起来是颠倒的。
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:看起来你已经假设了一个最多 200 行的源文件,并且正在将数据直接加载到视频缓冲区(即
A000:0000
),所以对你来说等价的就很简单:
for(int y = bmih.biHeight - 1; --y; y >= 0) {
fread(&video_memory[y * 320], bmih.biWidth, 1, bitmap_file);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.