首页 > 用户发贴区 > 编程问题提问区 > 求助 怎么用c直接写显存显示bmp图像
2006
10-27

求助 怎么用c直接写显存显示bmp图像

谢谢啊  随便帮我看看这程序什么地方错 谢谢啊


/* Note:Your choice is C IDE */
#include <stdio.h>
#include <dos.h>
#include <math.h>
#include <io.h>
#include <bios.h>
#include <fcntl.h>
 
#define PI 3.1415927
#define VGA256 0×13
#define TEXT_MODE 0×03
#define VIDEOBUF 0xA0000000L
#define PALETTE_MASK 0x3c6
#define PALETTE_REGISTER_RD 0x3c7
#define PALETTE_REGISTER_WR 0x3c8
#define PALETTE_DATA 0x3c9


 


unsigned char far *Video_Buff = (char far *)VIDEOBUF;
float Look_sin[361], Look_cos[361];  


typedef struct Bmp_File
{
 unsigned int i_bfType;
 unsigned long l_bfSize;
 unsigned int i_Reserved1;
 unsigned long l_Reserved2; 
}bitMapFile;


typedef struct Bmp_Info
{
 unsigned long l_biSize;
 unsigned long l_biWidth;
 unsigned long l_biHeight;
 unsigned int  i_biPlance;
 unsigned int  i_biBitCount;
 unsigned long l_biCompression;
 unsigned long l_biSizeImage;
 unsigned long l_biXpolsPerMeter;
 unsigned long l_biYpolsPerMeter;
 unsigned long l_biClrUsed;
 unsigned long l_biClrImportant;
}bitMapInfo;


typedef struct RGB_Bmp_typ
{
 unsigned char c_blue;
 unsigned char c_green;
 unsigned char c_red;
 unsigned char c_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 Create_Table( void );
void  Set_Video_Mode( int mode );
void  V_Line( int i_x1, int i_y1, int i_y2, int i_Color);
void H_Line( int i_x1, int i_y1, int i_x2, int i_Color);
void Arc( int i_x, int i_y, int i_Radius, int i_Start, int i_End, int i_Color);
int Set_Bmp_Video( int fp, int file_Height, unsigned int file_Width);
void Set_Video_Palette(bmp_Picture_ptr bmpPt, int index);
int Load_Screen( char *path ); 
void Check_File(int fp, bmp_Picture_ptr bmpPt);


int main()
{
 
 int ix=10, iy=10;
 Create_Table();
 Set_Video_Mode( VGA256 );
    Video_Buff[(iy)<<8+(iy)<<6+ix] = 15;
 getch();
 V_Line(50, 20, 100, 10);
 getch();
 H_Line(60, 30, 200, 6);
 getch();
 Arc(160, 100, 20, 0, 360, 9);
 getch();
 Load_Screen(“1.bmp”);
 Set_Video_Mode( TEXT_MODE );
      
}


void Create_Table( void )
{
  int degree;
  for(degree = 0; degree<361; degree++){
     Look_sin[degree] = (float)sin((double)degree*PI/180);
     Look_cos[degree] = (float)cos((double)degree*PI/180);   
   } 
}


void  Set_Video_Mode( int mode )
{
 union REGS inregs, outregs;
 inregs.h.ah = 0;
 inregs.h.al = (unsigned char)mode;
 int86( 0×10, &inregs, &outregs ); 
}


void  V_Line( int i_x1, int i_y1, int i_y2, int i_Color)
{
  int i;
  for(i = i_y1; i<i_y2-i_y1; i++)
     Video_Buff[i*320+i_x1] = i_Color ;
}


void H_Line( int i_x1, int i_y1, int i_x2, int i_Color)
{
 int i;
 for(i = i_x1; i<i_x2-i_x1; i++)
    Video_Buff[i_y1*320+i] = i_Color;
}


void Arc( int i_x, int i_y, int i_Radius, int i_Start, int i_End, int i_Color)
{
  int x, y;
  for(; i_Start<i_End; i_Start++){
      x = i_x+i_Radius*Look_cos[i_Start];
      y = i_y+i_Radius*Look_sin[i_Start];
      Video_Buff[y*320+x] = i_Color; 
   } 



int Set_Bmp_Video( int fp, int file_Height, unsigned int file_Width)
{
   int  i; 
   for(i = file_Height-1; i>=0; i– ){
    lseek(fp, 1078+(long)file_Width*i,SEEK_SET);
    read(fp, &Video_Buff[(file_Height-i-1)*file_Width], file_Width); 
    }
}



int Load_Screen( char *path )
{
  int fp, i,index;
  bmp_Picture bmpPt;
  if((fp = open(path, O_RDONLY)) == -1) 
   return ;
  read(fp, &(bmpPt.file), sizeof(bitMapFile));
  read(fp, &(bmpPt.info), sizeof(bitMapInfo));
  Check_File( fp, (bmp_Picture_ptr)&bmpPt );     
  lseek(fp, 54, 0); 
  for(i = 0; i<256; i++){   
  read(fp, &(bmpPt.palette[i].c_blue), 1);
  read(fp, &(bmpPt.palette[i].c_green), 1);
  read(fp, &(bmpPt.palette[i].c_red), 1);
  read(fp, &(bmpPt.palette[i].c_reserved),1);
  }
  for(index = 0; index<256; index++)
      Set_Video_Palette( &bmpPt, index);    
  Set_Bmp_Video(fp, 200, 320);
  close(fp); 
}


void Set_Video_Palette(bmp_Picture_ptr bmpPt, int index)

  outportb(PALETTE_MASK,0xff);
  outportb(PALETTE_REGISTER_WR, index);
  outportb(PALETTE_DATA, bmpPt->palette[index].c_red>>2);
  outportb(PALETTE_DATA, bmpPt->palette[index].c_green>>2);
  outportb(PALETTE_DATA, bmpPt->palette[index].c_blue>>2);  
}



void Check_File(int fp, bmp_Picture_ptr bmpPt)
{   
 if(bmpPt->file.i_bfType != 0x4d42){
  printf(“Erroer”);
  exit(1);
 }
 if(bmpPt->info.l_biCompression != 0){
  printf(“Can not display a compression file”);
  exit(1);
 }
 if(bmpPt->info.i_biBitCount != 8){
  printf(“Not a index 256color file. “);
  exit(1);
  } 
}


求助 怎么用c直接写显存显示bmp图像》有 1 条评论

  1. cboy 说:

    这么长的代码,没空调试.还是靠自己吧.以下的是参考.TC下的BMP参考

    http://www.vcgood.com/bbs/forum_posts.asp?TID=1263&PN=1&TPN=1

留下一个回复