640*480 256 色 .BMP 文件显示程序,可以浏览、同时显示 4 幅图象,也可以 在屏幕上开一个窗口显示 .BMP 图象,并可以使用上下左右箭头键、PageUp/PageDown、Ctrl+Left、Ctrl+Right键浏览整幅图象,在S3、ATI等VGA卡上 调试通过
/*
SHOWBMP.C --- Show .BMP files images for SVGA 640*480(256/16) mode
M.L.Y 2000.9, 2000.12
Please compile this file by Borland C++ 3.1:
BCC -ml SHOWBMP.C
*/
#include
#include
#include
#include
#include "GCFSVGA.C"
typedef struct
{
int bfType; /* 文件类型, 必须为 "BM" (0x4D42) */
long bfSize; /* 文件的大小(字节) */
int bfReserved1; /* 保留, 必须为 0 */
int bfReserved2; /* 保留, 必须为 0 */
long bfoffBits; /* 位图阵列相对于文件头的偏移量(字节) */
} BITMAPFILEHEADER; /* 文件头结构 */
typedef struct
{
long biSize; /* size of BITMAPINFOHEADER */
long biWidth; /* 位图宽度(像素) */
long biHeight; /* 位图高度(像素) */
int biPlanes; /* 目标设备的位平面数, 必须置为1 */
int biBitCount; /* 每个像素的位数, 1,4,8或24 */
long biCompress; /* 位图阵列的压缩方法,0=不压缩 */
long biSizeImage; /* 图像大小(字节) */
long biXPelsPerMeter; /* 目标设备水平每米像素个数 */
long biYPelsPerMeter; /* 目标设备垂直每米像素个数 */
long biClrUsed; /* 位图实际使用的颜色表的颜色数 */
long biClrImportant; /* 重要颜色索引的个数 */
} BITMAPINFOHEADER; /* 位图信息头结构 */
typedef struct
{
USGC rgbBlue;
USGC rgbGreen;
USGC rgbRed;
USGC rgbReserved;
} RGBQUAD;
BITMAPFILEHEADER FileHead;
BITMAPINFOHEADER InfoHead;
int gl_index_color = NO; /* first .BMP file */
/* ------------------------------------------------------------------------- */
int read_palette(FILE *fp, USGC pal[][3], int colornum)
/*
将文件(指针fp)的当前位置的调色板数据读到 pal 中,colornum 是颜色数
*/
{
int i;
memset(pal, 0, 3*colornum);
for(i = 0; i < colornum; i++)
{
pal[i][2] = (char)fgetc(fp) >> 2; /* Blue */
pal[i][1] = (char)fgetc(fp) >> 2; /* Green */
pal[i][0] = (char)fgetc(fp) >> 2; /* Red */
fgetc(fp);
}
return 0;
}
/* ------------------------------------------------------------------------- */
int show_bmp(FILE *fp, int color_index[256])
/*
按当前参数重新显示 .BMP 文件(文件指针 fp) (2色,16色或256色)
若是非第一幅图象,以第一幅图象调色板为准,颜色号索引表为 color_index
返回: 0 --- ok
-1 --- 显示图象时读文件出错
*/
{
int y, n, i, j, k;
long file_pos;
USGC buf[4096]; /* 文件中读出的一行图象 */
USGC linebuf[4096]; /* line buffer (一行图象) */