📄 bmp.h
字号:
typedef struct BMP_file
{
unsigned int bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int reserved2;
unsigned long bfOffset;
}
bitmapfile;
typedef struct BMP_info
{
unsigned long biSize;
unsigned long biWidth;
unsigned long biHeight;
unsigned int biPlanes;
unsigned int biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
unsigned long biXpolsPerMeter;
unsigned long biYpelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
}
bitmapinfo;
typedef struct RGB_BMP_typ
{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char reserved;
}RGB_BMP,*RGB_BMP_ptr;
typedef struct bmp_picture_typ
{
bitmapfile file;
bitmapinfo info;
RGB_BMP palette[256];
char far *buffer;
} bmp_picture, *bmp_picture_ptr;
void Set_BMP_Palette_Register(int index,RGB_BMP_ptr color)
{
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_WR,index);
outp(PALETTE_DATA,color->red);
outp(PALETTE_DATA,color->green);
outp(PALETTE_DATA,color->blue);
}
void Check_Bmp(bmp_picture_ptr bmp_ptr)
{
if(bmp_ptr->file.bfType!=0x4d42)
{
printf("Not a BMP file!\n");
exit(1);
}
if(bmp_ptr->info.biCompression!=0)
{
printf("Can not display a compressed BMP file!\n");
exit(1);
}
if(bmp_ptr->info.biBitCount!=8)
{
printf("Not a index 16color BMP file!\n");
exit(1);
}
}
void BMP_Load_Screen(char *bmp)
{
int i,fp;
bmp_picture bmp256;
char *file_name;
if ((fp=open(bmp,O_RDONLY))==1)
return;
read(fp,&bmp256.file,sizeof(bitmapfile));
read(fp,&bmp256.info,sizeof(bitmapinfo));
Check_Bmp((bmp_picture_ptr)&bmp256);//u can ingore it
// lseek(fp,54,0);
for (i=0;i<256;i++)
{
read(fp,&bmp256.palette[i].blue,1);
read(fp,&bmp256.palette[i].green,1);
read(fp,&bmp256.palette[i].red,1);
read(fp,&bmp256.palette[i].reserved,1);
bmp256.palette[i].blue=bmp256.palette[i].blue>>2;
bmp256.palette[i].green=bmp256.palette[i].green>>2;
bmp256.palette[i].red=bmp256.palette[i].red>>2;
}
for (i=0;i<256;i++)
Set_BMP_Palette_Register(i,(RGB_BMP_ptr)&bmp256.palette[i]);
for(i=SCREEN_HEIGHT-1;i>=0;i--)
{
lseek(fp,1078+(long)(SCREEN_HEIGHT-i-1)*SCREEN_WIDTH,0);
read(fp,&video_buffer[i*SCREEN_WIDTH],SCREEN_WIDTH);
}
close(fp);
}
void BMP_Init(bmp_picture_ptr image)
//申请图像大小的内存空间
{
unsigned int a=(unsigned int)(SCREEN_WIDTH * SCREEN_HEIGHT + 1);
if((image->buffer = (char far *)malloc(a))==NULL)
{
printf("\ncouldn't allocate screen buffer");
exit(1);
}
}
void BMP_Delete(bmp_picture_ptr image)
{
free(image->buffer);
}
void BMP_Load(char *bmp, bmp_picture_ptr bmp256)
{
int i,fp;
char *file_name;
if ((fp=open(bmp,O_RDONLY))==1)
return;
read(fp,&bmp256->file,sizeof(bitmapfile));
read(fp,&bmp256->info,sizeof(bitmapinfo));
Check_Bmp(bmp256);//u can ingore it
// lseek(fp,54,0);
for (i=0;i<256;i++)
{
read(fp,&bmp256->palette[i].blue,1);
read(fp,&bmp256->palette[i].green,1);
read(fp,&bmp256->palette[i].red,1);
read(fp,&bmp256->palette[i].reserved,1);
bmp256->palette[i].blue=bmp256->palette[i].blue>>2;
bmp256->palette[i].green=bmp256->palette[i].green>>2;
bmp256->palette[i].red=bmp256->palette[i].red>>2;
}
for (i=0;i<256;i++)
Set_BMP_Palette_Register(i,(RGB_BMP_ptr)&bmp256->palette[i]);
for(i=SCREEN_HEIGHT1-1;i>=0;i--)
{
lseek(fp,1078+(long)(SCREEN_HEIGHT1-i-1)*SCREEN_WIDTH,0);
read(fp,&bmp256->buffer[i*SCREEN_WIDTH],SCREEN_WIDTH);
}
close(fp);
}
void BMP_Show_Buffer(bmp_picture_ptr image)
//将内存中的图像显示
{
char far *data;
data=image->buffer;
asm push ds;
asm les di,video_buffer;
asm lds si,data;
asm mov cx,SCREEN_HEIGHT*SCREEN_WIDTH/2;
asm cld;
asm rep movsw;
asm pop ds;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -