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

📄 pcx.cpp

📁 超级玛丽游戏源码
💻 CPP
字号:
#include <dos.h>
#include <stdlib.h>
#include <mem.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <io.h>
#include "engine.h"

typedef struct{
	       char signature;
	       char version;
	       char encoding;
	       char bits_per_pixel;
	       int x_min;
	       int y_min;
	       int x_max;
	       int y_max;
	       int h_res;
	       int v_res;
	       char palette[48];
	       char reserved;
	       char color_plane_num;
	       int paletle_type;
	       char zero_pad[58];
	       }PCX_Head;
#define PCX_ID 0x0a

void setallpalette(char far *pal)
 {
  register i;
  outportb(0x3c8,0);
  for(i=0;i<768;i++)outportb(0x3c9,*pal++>>=2);
 }

/*
  if((pcxfile=fopen(argv[1],"rb"))==NULL)exit(1);

  if(fread(&pcxhead,sizeof(PCX_Head),1,pcxfile)!=1||
  (width=pcxhead.x_max-pcxhead.x_min+1)<0||
  (height=pcxhead.y_max-pcxhead.y_min+1)<0)exit(1);
  fseek(pcxfile,-768L,SEEK_END);
  fread(pal,3,0x100,pcxfile);
  setallpalette(pal);
  fseek(pcxfile,0x80l,SEEK_SET);
    for(x=100;x<200;x++){
   v[640*4+x]=4;
   }
*/



void unpackpcxline(BITMAP *buff,FILE *pcxfile,unsigned bytes)
 {
  unsigned i=0;
  char ch;
  register count;
  char far *buf=buff->buffer;
  do{
     if(((ch=fgetc(pcxfile))&0xc0)==0xc0){
	       count=ch&0x3f;
	       i+=count;
	       ch=fgetc(pcxfile);
	       while(count--)*buf++=ch;
	      }
     else{
	  *buf++=ch;
	  i++;
	 }
    }while(i<bytes);
 }



BITMAP *LoadPcxFile(char fn[])
{
  FILE *pcxfile;
  BITMAP *temp;
  unsigned char pal[768];
  PCX_Head pcxhead;
  int w,h;
  if((pcxfile=fopen(fn,"rb"))==NULL)exit(1);
  if(fread(&pcxhead,sizeof(PCX_Head),1,pcxfile)!=1||
  (w=pcxhead.x_max-pcxhead.x_min+1)<0||
  (h=pcxhead.y_max-pcxhead.y_min+1)<0)
  {
     printf("Error load pcx file");
     exit(1);
  }
  fseek(pcxfile,-768L,SEEK_END);
  fread(pal,3,0x100,pcxfile);
  setallpalette(pal);
  fseek(pcxfile,0x80l,SEEK_SET);

  temp=creat_bitmap(w,h);
  unpackpcxline(temp,pcxfile,w*h);
  return temp;
}



⌨️ 快捷键说明

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