文档库 最新最全的文档下载
当前位置:文档库 › c++图形头文件

c++图形头文件

#include
#include
#include
#include
#include

下面是读取 BMP 格式的函数及其他(针对640*480*256色BMP文件)

#define ADDRESS(X,Y) ((UNLONG)(Y) << 7) + ((UNLONG)(Y) << 9) + ((UNLONG)(X))
#define XOR '^'
/* 逻辑异或符号 */
#define AND '&'
/* 逻辑和符号 */
#define NORMAL 0
#define SCREENWIDTH 640
/* 屏幕的宽度 */
#define SCREENHEIGHT 480
/* 屏幕的高度 */
#define PALETTEMASK 0x3C6
/* 用于申请使用调色板的通讯端口 */
#define PALETTEDATA 0x3C9
/* 用于传输数据的端口 */
#define PALETTEREGISTERWR 0x3C8
/* 用于写数据的端口 */
#define PALETTEREGISTERRD 0x3C7
/* 用于读数据的端口 */
#define UNLONG unsigned long
/* UNSIGNED LONG */
#define UNINT unsigned int
/* UNSIGNED INT */
#define UNCHAR unsigned char
/* UNSIGNED CHAR */
UNCHAR newpage,oldpage;
union REGS reg;

typedef struct BMPHeaderType /* BMP 文件头信息 */
{
UNINT type; /* 文件类型,通常为 BM */
UNLONG size; /* 文件长度 */
UNINT reserved1,reserved2; /* 保留 */
UNLONG offset; /* 文件描述区长度 */
}
BMPHeader,*BMPHeaderPtr;

typedef struct BMPImageType /* BMP 图像信息区 */
{
UNLONG size; /* 图形面积 */
UNLONG width,height; /* 图形高度和宽度 */
UNINT planes;
UNINT bitcount; /* 每个像素占位 */
UNLONG compression; /* 是否压缩 */
UNLONG imagesize;
UNLONG xpols,ypols;
UNLONG clrused;
UNLONG clrimportant;
}
BMPImage,*BMPImagePtr;

typedef struct BMPPaletteType /* BMP 调色板 */
{
UNCHAR blue; /* 蓝色 */
UNCHAR green; /* 绿色 */
UNCHAR red; /* 红色 */
UNCHAR reserved; /* 保留 */
}
BMPPalette,*BMPPalettePtr;

typedef struct BMPPictureType /* BMP 文件结构 */
{
BMPHeader header; /* 文件头 */
BMPImage image; /* 图像数据区 */
BMPPalette palette[256]; /* 调色板 */
}
BMPPicture,*BMPPicturePtr;

void SelectPage(UNCHAR page)
{
reg.x.ax = 0x4F05; /* 将数据存入存储器 */
reg.x.bx = 0;
reg.x.dx = page;

int86(0x10, ®, ®); /* 调用中断 */
}

void SetPaletteRegisterForBMP(UNCHAR index, BMPPalettePtr color)
{
outp(PALETTEMASK, 0xFF);
outp(PALETTEREGISTERWR, index);
outp(PALETTEDATA, color->red);
outp(PALETTEDATA, color->green);
outp(PALETTEDATA, color->blue);
}

void PutPixel(UNINT x, UNINT y, UNCHAR color, UNCHAR SYMBOL)
{
UNLONG address = ADDRESS(x,y); /* 得到点在显存中的位置 */
UNLONG offset; /* 保存偏移值 */

newpage = (address >> 16); /* 计算页面 */
if (newpage != oldpage) /* 如果新页面不等于旧页面则更换页面 */
{
SelectPage(newpage); /*

以提高一定的效率 */
oldpage = newpage; /* 保存页面 */
}

offset = address - (newpage << 16);
/* 计算偏移值 */
if (SYMBOL != XOR) /* 判断是否用异或的方法画点 */
videobuffer[offset] = color;

else if (SYMBOL == XOR)
videobuffer[offset] = color ^ videobuffer[offset];

}

void LoadBMP(UNCHAR *filename, UNCHAR enablepalette, UNCHAR SYMBOL)
{
int index,i,j;
UNCHAR data; /* 变量,文件流和结构体 */
FILE *stream;
BMPPicture bmpfile;

if ((stream = fopen(filename,"rb")) == NULL)
exit(0); /* 成功打开文件 */

fseek(stream,54L,SEEK_SET); /* 跳过头信息区 */

for (index=0;index<256;index++) /* 读取调色板 */
{
bmpfile.palette[index].blue = getc(stream)>>2;
/* 蓝色 */
bmpfile.palette[index].green = getc(stream)>>2;
/* 绿色 */
bmpfile.palette[index].red = getc(stream)>>2;
/* 红色 */
bmpfile.palette[index].reserved = getc(stream);
/* 保留 */
}

for (i=SCREENHEIGHT-1;i>=0;i--)
{ /* 按照特有的方式写入屏幕 */
for (j=0;j{
data = getc(stream);
/* 读取数据 */
PutPixel(j, i, data, SYMBOL);
/* 写屏幕 */
}
}

fclose(stream);

if (enablepalette) /* 设置调色板 */
for (i=0;i<256;i++)
SetPaletteRegisterForBMP(i,(BMPPalettePtr)&bmpfile.palette[i]);
}
这是我从我的文件里乱摘出来的,有什么没有定义的可以再告诉我。

相关文档