设为首页 加入收藏

TOP

DOS下显示8位256色BMP位图(一)
2014-11-23 23:39:53 来源: 作者: 【 】 浏览:35
Tags:DOS 显示 8位 256 BMP位图

#include

#include //exit()

#include<dos.h> //in86()

#include //close()

#include //open()

#include //lseek(),read()

#include //outp(),getch()

#define VGA256 0x13 //320*200 256色 显示模式

#define TEXT_MODE 0x03 //80×25 16 色 文本模式

#define SCREEN_HEIGHT 200 //图象高度,像素单位

#define SCREEN_WIDTH 320 //图象宽度,像素单位

#define PALETTE_MASK 0x3c6 //调色板屏蔽寄存器端口,放入0xff可以通过调色板索引寄存器0x3c7和0x3c8访问你希望的寄存器

#define PALETTE_REGISTER_RD 0x3c7 //读颜色寄存器端口

#define PALETTE_REGISTER_WR 0x3c8 //写颜色寄存器端口

#define PALETTE_DATA 0x3c9 //调色板数据寄存器端口

unsigned char far *video_buffer=(char far *)0xA0000000L;

typedef struct BMP_file

{

unsigned int bfType; //这里恒定等于0x4D42,ASCII字符‘BM’

unsigned long bfSize; //文件大小,以字节为单位

unsigned int Reserved1; //备用,必须为0

unsigned int reserved2; //备用,必须为0

unsigned long bfOffset; //数据区在文件中的位置偏移量,以字节为单位

}bitmapfile; //文件头结构体,14 字节

typedef struct BMP_info

{

unsigned long biSize; //位图信息头大小,本结构所占用字节数

unsigned long biWidth; //图象宽度,像素单位

unsigned long biHeight; //图象高度,像素单位

unsigned int biPlanes; //位平面树,目标设备的级别,必须为1

unsigned int biBitCount; //单位像素的位数,表示BMP图片的颜色位数,必须是1(双色 ),4(16色),8(256色),24位图(真彩色),32位图

unsigned long biCompression; //图片压缩属性,必须为:0(不压缩),1(BI_RLE8压缩类型)或2(BI_RLE4压缩类型)之一

unsigned long biSizeImage; //表示图片数据区的大小,当biBompression等于0时,这里的值可以省略

unsigned long biXpolsPerMeter; //水平分辨率,每米像素数,可省略

unsigned long biYpelsPerMeter; //垂直分辨率,每米像素数,可省略

unsigned long biClrUsed; //表示使用了多少个颜色索引表,一般biBitCount属性小于16才会用到,等于0时表示有2^biBitCount个颜色索引表

unsigned long biClrImportant; //表示有多少个重要的颜色,等于0时表示所有颜色都很重要

}bitmapinfo; //位图信息头,40 字节

typedef struct RGB_BMP_typ

{

unsigned char blue; //蓝色的亮度(值范围为0-255)

unsigned char green; //绿色的亮度(值范围为0-255)

unsigned char red; //红色的亮度(值范围为0-255)

unsigned char reserved; //保留,必须为0

}RGB_BMP,*RGB_BMP_ptr; //单个像素颜色结构体,4 字节

typedef struct bmp_picture_typ

{

bitmapfile file; //位图文件头

bitmapinfo info; //位图信息头

RGB_BMP palette[256]; //位图颜色表

} 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>>2);

outp(PALETTE_DATA,color->green>>2);

outp(PALETTE_DATA,color->blue>>2);

}

void Check_Bmp(bmp_picture_ptr bmp_ptr) //检测是否是BMP文件

{

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 16 color BMP file!\n");

exit(1);

}

}

void BMP_Load_Screen(char *bmp) //载入BMP文件并显示……

{

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇可变参数宏__VA_ARGS__ 下一篇在对话框显示出来后立即执行一段..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: