/*6-1.c*/
#include "conio.h"
#include "stdio.h"
#include "dos.h"
#include "stdlib.h"
#define lengthlimit 640
#define highlimit 480
int Set640_480 (void)
{
asm mov ax,4f02h
asm mov bx,0101h
asm int 10h
if((_AL==0x4f)&&(_AH==0))
{
return(0);
}
return(1);
}
void Set_Page(int page)
{
asm mov ax,4f05h
asm mov bx,0
asm mov dx,page
asm int 10h
}
void myputpixel (int row,int col,unsigned char color)
/*(row,col)画点的坐标,color画点颜色*/
{
unsigned long dantance;
unsigned y;
static int totalpage=0;
int page;
dantance=1l*col*lengthlimit+row;
y=(unsigned)(dantance&0X0000ffffl);
page=(int)(1.0*dantance/65536);
if (totalpage!=page) { totalpage=page; Set_Page(page); }
asm {
mov ax,0a000h
mov es,ax
mov si,y
mov al,color
mov es:[si],al
}
}
void bmpout(char *bmpstr)
/* 打开文件名为*bmpstr的BMP文件,输出图象*/
{
FILE *bmpfp;
struct bmp{
int bftype;
long bfsize;
long bfr;
long bfoff;
long bisize;
long biwidth ;
long biheight;
} bmpp;
struct DAC{
char blue;
char green;
char red;
};
struct DAC dacp[256];
char pp;
int colorcount,x,y,i,j,x0=0,y0=470,k,bibit,svg;
char resev,buf1 ;
void *buf;
Set640_480();
if((bmpfp=fopen(bmpstr,"rb"))==NULL)
{
printf("can't open file");
return;
}
fread(&bmpp,sizeof(bmpp),1,bmpfp);
fseek(bmpfp,28l,SEEK_SET);
fread(&bibit,2,1,bmpfp);
fseek(bmpfp,46l,SEEK_SET);
fread(&colorcount,sizeof(colorcount),1,bmpfp);
if (colorcount==0) { colorcount=256;}
fseek (bmpfp,54l,SEEK_SET);
for (i=0;i {
fread(&dacp[i],3,1,bmpfp);
fread(&resev,1,1,bmpfp);
}
for(i=0;i {
pp=dacp[i].red>>2;
dacp[i].red=dacp[i].blue>>2;
dacp[i].blue=pp;
dacp[i].green=(dacp[i].green>>2);
}
asm push es
_ES=FP_SEG(dacp);
_DX=FP_OFF (dacp);
asm mov bx,0
asm mov cx,colorcount
asm mov ah,10h
asm mov al,12h
asm int 10h
asm pop es
fseek(bmpfp,bmpp.bfoff,SEEK_SET);
buf=malloc(bmpp.biwidth);
for(i=0;i {
y=y0-i;
fread(buf,bmpp.biwidth,1,bmpfp);
for( j=x0;j myputpixel(j,y,*((unsigned char*)buf+j));
}
free(buf);
getch();
fclose(bmpfp);
delay(500);
return;
}
void main()
{
bmpout("*.bmp"); /* 打开某一BMP文件并输出图象*/
}