⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makegbp.c

📁 一个C做的蛇蛇游戏阿
💻 C
字号:
/******************************************/
/*        makegbp.c of goldenbugs         */
/*                                        */
/*            make gbp files              */
/*                                        */
/*          Cat Tom  4.12.2003            */
/******************************************/


#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<graphics.h>
#include<bios.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>


struct bmphead{
unsigned char b;
unsigned char m;
unsigned long bfsize;
unsigned int bfresterved1;
unsigned int bfresterved2;
unsigned long bfoffbits;
unsigned long bitsize;
unsigned long bmpwidth;
unsigned long bmpheight;
unsigned int bmpplanes;
unsigned int bmpcount;
unsigned long bmpcompression;
unsigned long bmpimgsize;
unsigned long bmpxpeispermeter;
unsigned long bmpypeispermeter;
unsigned long bmpcirused;
unsigned long bmpimportant;
}bmp;
/*----------------------------------------------------------------------------------------------*/
struct ColorIndex
{
        unsigned char Blue;
        unsigned char Green;
        unsigned char Red;
        unsigned char Reserved;
}index[16];
int pageno;

/*==============================================================================================*/
void SetPlate(int ColorIndex,char Red,char Green,char Blue)
{
        outportb(0x3c8,ColorIndex);
        outportb(0x3c9,Red);
        outportb(0x3c9,Green);
        outportb(0x3c9,Blue);
}
/*----------------------------------------------------------------------------------------------*/


showbmp(int x,int y,char*filename)
{
 FILE *fp;
 char c,temp1,temp2;
 register int m;
 int n;
 register unsigned long i=0,j=0;
 struct palettetype  *sq;

 if((fp=fopen(filename,"rb"))==NULL)
   printf("can't open file!");
 else
   {
    fread(&bmp,sizeof(struct bmphead),1,fp);
    fread(index,sizeof(struct ColorIndex),16,fp);
   }

 if(bmp.bmpwidth%32==0)n=bmp.bmpwidth/2;
 else n=4+bmp.bmpwidth/2-(bmp.bmpwidth/2)%4;


 fseek(fp,bmp.bfoffbits,0);

 for(m=0; m<bmp.bmpheight; m++)
   {
    j=0;
    for(i=0;i<n;i++)
      {
       c=fgetc(fp);
       if(j<bmp.bmpwidth)
         {
          temp1=(c&0xF0)>>4;
          temp2=c&0x0F;
          putpixel(x+j,y+m,temp1);
          j++;
          putpixel(x+j,y+m,temp2);
          j++;
         }
      }
   }

 fclose(fp);
}


void savepic(char *filename)
{
 FILE *fp;
 unsigned i=0,size;
 void *w;
 long temp=bmp.bmpheight;

 if((fp=fopen(filename,"wb"))==NULL)
 {
  printf("file open error!\n");
  exit(0);
 }

 fwrite(&bmp.bmpwidth,sizeof(long),1,fp);
 fwrite(&bmp.bmpheight,sizeof(long),1,fp);
 while(temp>=200)
   {
    size=imagesize(0,0,bmp.bmpwidth-1,199);
    w=malloc(size);
    getimage(0,i*200,bmp.bmpwidth-1,199+i*200,w);
    fwrite(w,size,1,fp);
    free(w);
    temp-=200;
    i++;
   }
 if(temp>0)
   {
    size=imagesize(0,0,bmp.bmpwidth-1,temp-1);
    w=malloc(size);
    getimage(0,i*200,bmp.bmpwidth-1,temp+i*200-1,w);
    fwrite(w,size,1,fp);
    free(w);
   }

 fclose(fp);
}


main()
{
 int gd=VGA,gm=VGAHI;
 char a[20],b[20];
 printf("to change bmp into gbp.\n\n");
 printf("input the filename of the BMP(*.bmp):");
 gets(a);
 printf("input the filename of the GBP(*.gbp):");
 gets(b);
 initgraph(&gd,&gm,"");
 showbmp(0,0,a);
 savepic(b);
 getch();
 closegraph();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -