| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2197 人关注过本帖
标题:求教一个关于256色BMP文件的调用的问题
取消只看楼主 加入收藏
guoshimin
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-1-26
收藏
 问题点数:0 回复次数:0 
求教一个关于256色BMP文件的调用的问题

看了以下的关于读取256色BMP文件并显示的程序都不知几遍了,就是看不出有什么不对。但就是一运行就自动退出,大家帮忙看一下吧:

#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

#define VGA256 0x13
#define TEXT_MODE 0x03

unsigned char far *video_buffer=(char far *)0xA0000000L; /*显存首地址*/

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 /*BMP文件结构*/
{
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) /*在屏幕上显示BMP文件*/
{
int i,fp;
bmp_picture bmp256;
char *file_name;
if((fp=open(bmp,O_RDONLY))==-1)
{
printf("\nOpen error !\n");
return;
}
read(fp,&bmp256.file,sizeof(bitmapfile));
read(fp,&bmp256.info,sizeof(bitmapinfo));
Check_Bmp((bmp_picture_ptr)&bmp256);
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 Set_Video_Mode(int mode) /*设置显示模式*/
{
union REGS inregs,outregs;
inregs.h.ah=0;
inregs.h.al=(unsigned char)mode;
int86(0x10,&inregs,&outregs);
}

int main()
{
Set_Video_Mode(VGA256);
BMP_Load_Screen("e:\\tc\\output\\256.bmp");/*所用图形文件已经附上,以供调试*/
getch();
Set_Video_Mode(TEXT_MODE);
}

图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: BMP文件 include define PALETTE 
2007-01-26 01:03
快速回复:求教一个关于256色BMP文件的调用的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019421 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved