无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 2302|回复: 3
打印 上一主题 下一主题

可以在DOS下显示256色BMP的C程序

[复制链接]
跳转到指定楼层
1#
发表于 2003-1-4 18:07:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "dos.h"
#include "fcntl.h"
#include "io.h"
#define TEXT_BIG_CURSOR 0
#define TEXT_NORMAL_CURSOR 7
unsigned char set_SVGA_mode(int vmode)
{union REGS r;
r.x.ax=0x4f02;
r.x.bx=vmode;
int86(0x10,&r,&r);
return(r.h.ah);
}
void hide_text_cursor(void)
{union REGS r;
r.h.ah=1;
r.h.ch=32;
int86(0x10,&r,&r);
}
selectpage(register char page)  /*换页函数*/
{union REGS r;
r.x.ax=0x4f05;
r.x.bx=0;
r.x.dx=page;   /*选择页面*/
int86(0x10,&r,&r);
}
void show_text_cursor(char size)
/*(10-17):自定义文本光标)*/
{union REGS r;
r.h.ah=1;
r.h.cl=size;
r.h.ch=7;
int86(0x10,&r,&r);
}
unsigned int get_SVGA_mode()
{union REGS r;
r.x.ax=0x4f03;
int86(0x10,&r,&r);
return(r.x.bx);
}
unsigned int Vmode=0;
void init16M()  /*屏幕初始化*/
{Vmode=get_SVGA_mode();
hide_text_cursor();
if(set_SVGA_mode(0x115))
{printf("\nSorry, Your graphics driver does not supplied.\n");
  show_text_cursor(TEXT_NORMAL_CURSOR);
  exit(0);
}
}
void close16M() /*恢复文本模式*/
{if(Vmode!=0)
{set_SVGA_mode(Vmode);
  show_text_cursor(TEXT_NORMAL_CURSOR);
}
}
typedef struct  /*16Mrgb像素类型*/
{unsigned char b;
unsigned char g;
unsigned char r;
}rgb16M;
unsigned char nowpage,lastpage=8;
void writevideo(long position,char value)
{nowpage=position/65536;
if(nowpage!=lastpage)
{selectpage(nowpage);
  lastpage=nowpage;
}
pokeb(0xa000,position%65536,value);
}
void putpoint16M(int x,int y,rgb16M color)
/*16M真彩色 800*600写点函数*/
{register long temp=3200l*y+4l*x;
writevideo(temp,color.b);
writevideo(temp+1,color.g);
writevideo(temp+2,color.r);
}
rgb16M *malloc();
#include "dir.h"
#include "dos.h"
char dir_input(char *fileformat,char *selectfile)
/*列表选择函数,返回0为选择了不存在的文件*/
{struct ffblk *ff,temp;
ff=&temp;
clrscr();
puts("Select a file from the list:");
if(findfirst(fileformat,ff,FA_ARCH|FA_HIDDEN))exit(0);
printf("\n%-20s",ff->ff_name);
while(!findnext(ff))
{printf("%-20s",ff->ff_name);
  if(wherey()==25)getch();
}
printf("\n\nInput a filename:");
gets(selectfile);
return(findfirst(fileformat,ff,FA_ARCH));
}
main()
{register int wl,ll,i,j,x0,y0,fp;int temp;
register char fix;char filename[13];
register rgb16M *buffer;
dir_input("*.bmp",filename);
init16M();
if((fp=open(filename,O_RDONLY|O_BINARY))==-1){close16M();exit(0);}
lseek(fp,18,SEEK_SET);
read(fp,&temp,4);wl=temp;
read(fp,&temp,4);ll=temp;
fix=(wl%4)?(4-wl%4):0;
x0=(800-wl)/2;y0=(600-ll)/2;
lseek(fp,54,SEEK_SET);
buffer=malloc(wl*sizeof(rgb16M));
for(j=ll-1;j>=0;j--)
{read(fp,buffer,wl*3);
  lseek(fp,fix,SEEK_CUR);
  for(i=0;i<wl;i++)
   putpoint16M(x0+i,y0+j,buffer);
}
getch();
close(fp);
close16M();
}
2#
发表于 2003-1-5 12:51:22 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

3#
发表于 2003-1-5 17:01:12 | 只看该作者

可以在DOS下显示256色BMP的C程序

DJGPP里有库函数,直接Include就可以用了。
回复

使用道具 举报

4#
发表于 2003-1-5 21:42:35 | 只看该作者

可以在DOS下显示256色BMP的C程序

学习一下。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2025-5-12 12:35

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表