📄 borland c.cpp
字号:
//位图显示程序
//分类:Borland C
//定义为图结构
struct bmphead
{
unsigned char b;
unsigned char m;
unsigned long bfsize;
unsigned int bfresterved1;
unsigned int bfresterved2;
unsigned long bfoffbits;
unsigned long bitsize;
unsigned long bmpwidth;
unsigned long bmpheight;
unsigned int bmpplanes;
unsigned int bmpcount;
unsigned long bmpcompression;
unsigned long bmpimgsize;
unsigned long bmpxpeispermeter;
unsigned long bmpypeispermeter;
unsigned long bmpcirused;
unsigned long bmpimportant;
};
////////////////////////////////////////////////////////////////////////////////
struct ColorIndex
{
unsigned char Blue;
unsigned char Green;
unsigned char Red;
unsigned char Reserved;
};
int pageno;
/*==============================================================================================*/
void SetPlate(int ColorIndex,char Red,char Green,char Blue)
{
outportb(0x3c8,ColorIndex);
outportb(0x3c9,Red);
outportb(0x3c9,Green);
outportb(0x3c9,Blue);
}
/*----------------------------------------------------------------------------------------------*/
/*显示函数*/
void showbmp(int x,int y,char *filename)
{
FILE *fp;
char c,temp1,temp2;
struct bmphead bmp;
struct ColorIndex index[16];
register int m;
unsigned long n = 0;
register unsigned long i=0,j=0;
/* struct palettetype oldq; */
//struct palettetype *sq;
/* getpalette(&oldq); */
if((fp=fopen(filename,"rb"))==NULL)
{
//printf("can't open file!");
return;
}
else
{
fread(&bmp,sizeof(struct bmphead),1,fp);
fread(index,sizeof(struct ColorIndex),16,fp);
}
if(bmp.bmpwidth%32==0)
{
n = bmp.bmpwidth/2;
}
else
{
n=4+bmp.bmpwidth/2-(bmp.bmpwidth/2)%4;
}
m=9;
SetPlate(57,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(58,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(59,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(60,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(61,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(62,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(63,index[m].Red,index[m].Green,index[m].Blue);
fseek(fp, bmp.bfoffbits,0);
for(m=0; m<bmp.bmpheight; m++)
{
j=0;
for(i=0;i<n;i++)
{
c=fgetc(fp);
if(j<bmp.bmpwidth)
{
temp1=(c&0xF0)>>4;
temp2=c&0x0F;
if(temp1 != 0)
{
putpixel(x+(int)j,320+y-m,(int)temp1);
}
j++;
if(temp2 != 0)
{
putpixel(x+(int)j,320+y-m,temp2);
}
j++;
}
}
}
fclose(fp);
}
//你可以通过这个链接引用该篇文章:http://sgfxj.bokee.com/tb.b?diaryId=11301842
//2006.7.8 12:52 作者:落泪天使 收藏 | 评论:0 | 阅读:0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -