#include<io.h>
#include<stdio.h>
#include<dos.h>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<bios.h>
#include<mem.h>
#include<fcntl.h>
#include<stdlib.h>
#include<conio.h>
#define SCREEN_HEIGHT 200
#define SCREEN_WIDTH 320
#define PALETTE_MASK 0x3c6
#define PALETTE_REGISTER_RD 0x3c7
#define PALETTE_REGISTER_WR 0x3c8
#define PALETTE_DATA 0x3c9
unsigned char far *video_buffer=(char far *)0xA0000000L;
#define VGA256 0x13
#define TEXT_MODE 0x03
typedef struct BMP_file
{
unsigned int bfType;
unsigned long bfsize;
unsigned int Reserve1;
unsigned int reserve2;
unsigned long bfOffset;
} bitmapfile;
typedef struct BMP_info
{
unsigned long biSize;
unsigned long biWidth;
unsigned long biHight;
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_Video_Mode(int mode);
void Set_BMP_Palette_Register(int index,RGB_BMP_ptr color);
void Check_Bmp(bmp_picture_ptr bmp_ptr);
void BMP_Init(bmp_picture_ptr image);
void BMP_Show_buffer2(bmp_picture_ptr image);
void BMP_Load_Screen(char *bmp);
void main()
{
Set_Video_Mode(VGA256);
BMP_Load_Screen("256.bmp");
getch();
Set_Video_Mode(TEXT_MODE);
}
void Set_Video_Mode(int mode)
{
union REGS inregs,outregs;
inregs.h.ah=0;
inregs.h.al=(unsigned char)mode;
int86(0x10,&inregs,&outregs);
}
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_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_Show_Buffer2(bmp_picture_ptr image)
{
_fmemcpy((char far *)video_buffer,(char far *)image->buffer,(unsigned int)SCREEN_WIDTH*SCREEN_HEIGHT/2);
}
void BMP_Load_Screen(char *bmp)
{
int i,fp;
unsigned int bytes;
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);
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);
_dos_read(fp,&video_buffer[i*SCREEN_WIDTH],SCREEN_WIDTH,&bytes);
}
close(fp);
}
BMP.rar_bc++
版权申诉
155 浏览量
2022-09-24
07:34:57
上传
评论
收藏 4KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/3b38fb294f114a0a8dfd7bc633aed231_weixin_42660494.jpg!1)
alvarocfc
- 粉丝: 114
- 资源: 1万+
最新资源
- 图标生成工具 Windows 版本(支持.ico和.icns)IconBuilder v1.1
- 666662222277777
- 图标生成工具 Mac 版本(支持.ico和.icns)IconBuilder v1.1
- 求最大公约数(简单).cpp
- elasticsearch数据库下载、配置、使用案例
- springboot的概要介绍与分析
- C语言的概要介绍与分析
- 第一个较大的Android项目,基于Android平台的图书管理系统(Android studio).zip
- Cisco Packet Tracer 6.2 for Windows Instructor Version
- 使⽤pyIAST计算⽓体吸附选择性
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)