[求助]turbo c 3.0显示BMP
今天路过贵宝地,看了上去回帖率很高,决定把我想问的问题在这问一问,希望大家咄咄帮忙
操作系统:WIN2000 编译环境:turbo c 3.0 目的: 显示256色 320X200的bmp图象文件 问题:我正在看《c游戏编程入门到精通》,看到显示bmp文件时,运行他给的代码,显示不出图象, 13H图形模式。 下面将给出bmp文件结构和程序代码供大家参考,看我到底什么地方出了问题 bmp文件结构: 1,文件信息区(14字节) typedef struct BMP_file{...}bitmapfile; 2,图象信息区(40字节) typedef struct BMP_info{...}bitmapinfo; 3,调色版区(1024字节) typedef struct 4,图象存储区(64000字节) bmp文件完整的结构定义: typedef struct bmp_picture_tp { bitmapfile file; bitmapinfo info; RGB_BMP palette[256]; char far *buffer; } bmp_picture, *bmp_picture_ptr; 程序代码: //-----------------------program start #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; //bug1 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; //bug2 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--) //bug4 { 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("256.bmp"); getch(); //bug3 Set_Video_Mode(TEXT_MODE); } //-----------------------program end "//bug1-4"是我加上去的标记,下面给出他们的说明 bug1:编译时出现的error。我的解决办法:在"=("后面加上"unsigned "。 bug2:编译时出现的warning。我的解决办法:去掉所在那一行。 bug3:编译时出现error。我的解决办法:更改为"getchar();" bug4:运行时,for循环语句没有出来,估计显示不出来与这里有关 最后:罗嗦了这么多,浪费了您的宝贵时间,实在抱歉的很。 我花了一周时间反复看了这段代码,对于显示的基本思路还是有了些了解,但到了最后居然显示不出来,对初学者的我来说,实在是太打击我了,还请各位大侠不吝赐教,我将感激不尽。 回贴或者发我邮箱hhw_Marz@tom.com都行哈 |