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

📄 zitopcx.c

📁 pcx转黑白低图形
💻 C
字号:
/***************************************
function:gb2312.k16 to *.pcx, one word => one pcx file 
author  :hanyu
Data    :1/2/04 1:12PM ----1/3/04 4:19PM
version : 1.0  
***************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>
#include<fcntl.h>
FILE *fhzk16,  *findex;
int posword;
char colorref_buf[256*3+1];
void F_initpcx(void);
int convert(unsigned char,unsigned  char );
int F_getbit(char ch1, char pbit);
struct PCXHead {
	 char   ID;
	 char   Version;
	 char   Encoding;
	 char   BitPerPixel;
	 short  X1;
	 short  Y1;
     short  X2;
     short  Y2;
     short  HRes;
     short  VRes;
	 char   ClrMap[16*3];
     char   Reserved1;
     char   NumPlanes;
     short  BPL;
     short  Pal_t;
     char   Filler[58];
   } sHeader;

void main(int argc,char *argv[])
{
FILE	*finput;
int 	lpbuf;
unsigned char  line_buf[256];
unsigned char tempwd, tempwd1;

//	 argc=2; 	argv[1]="input.txt";

	 if(argc!=2)
		{
			printf("\n usage\t:zitopcx <input.txt>");
			printf("\n usage\t:input.txt file include chinese word \n that want to conver island g*.pcx\n");
			printf("zitopcx.exe version 1.0 Copyright(c) 2004.1 by Hanyu. VTD. \n");
			exit(1);
		}

	if((finput=fopen(argv[1],"r"))==NULL)
		{    printf("cannot open the file : %s please to check the  file",argv[1]);
			  exit(1);
		}
	if((fhzk16=fopen("gb2312.k16","rb"))==NULL)
		{    printf("cannot open the file : <gb2312.k16> please to check the  file");
			  exit(1);
		}
	system("mkdir out");
	if((findex=fopen("out\\index.txt","w+"))==NULL)
		{    printf("cannot open the file : <index.txt> please to check the  file");
			  exit(1);
		}
	F_initpcx();


	posword = 0;
	while(!feof(finput))
	{
		fgets(line_buf,256,finput);
		if(feof(finput))break;
		lpbuf = 0;    //line ponit
		while(!(line_buf[lpbuf]==0x0D||line_buf[lpbuf]==0x0A))
		{
		  tempwd = line_buf[lpbuf++]; //in one line, one byte.
		  if(tempwd<0xa1)
		  {   continue;
		  }
		  tempwd1 = line_buf[lpbuf++]; //jmp 2
		  if(!convert(tempwd,tempwd1))
		  {
			posword++;			//convert sucess.
			///////get index file of pcx
			char t[20],tzi[5];	
			itoa(1000-1+posword,t,10);
			strcat(t,"		");
			tzi[0]= tempwd;tzi[1]=tempwd1;tzi[2]=0x0d,tzi[3]=0xa;tzi[4]=0;
			strcat(t,tzi);
			fwrite(t,strlen(t),1,findex);
	
			////////
		  }
		  //next word .
		}
	}//end while
	fcloseall();
	printf("\nin :zitopcx.exe input.txt");
	printf("\nout:g*.pcx and index.txt" );
	printf("\nzitopcx version 1.0 Copyright(c) 2004.1 by Hanyu. VTD. \n");
}//end main
///////////////////////////////////////////

void F_initpcx(void)
{
FILE 	*fcolorref;
//pcx file head
	 memset(&sHeader,0,128);   //128

	 sHeader.ID = 0xa;
	 sHeader.Version = 5;
	 sHeader.Encoding = 1;
	 sHeader.BitPerPixel = 8;
	 sHeader.X1 = 0;
	 sHeader.Y1 = 0;
	 sHeader.X2 = 15;
	 sHeader.Y2 = 15;
	 sHeader.HRes = 16;
	 sHeader.VRes = 16;
	 ;sHeader.ClrMap[16*3];
	 ;sHeader.Reserved1;
	 sHeader.NumPlanes = 1;
	 sHeader.BPL = 16;
	 ;sHeader.Pal_t;
	 ;sHeader.Filler[58];

//pcx file tail.
	if((fcolorref=fopen("corefe","rb"))==NULL)
		{    printf("cannot open the file : <gb2312.k16> please to check the  file");
			  exit(1);
		}
//	int t= strlen(colorref_buf)+1; 256*3+1;
	fread(colorref_buf, 256*3+1, 1,fcolorref);
	fclose(fcolorref);
}

convert(unsigned char tempwd, unsigned char tempwd1)
{
unsigned long curpos=0;
char wd_buf[16*2],pcx_buf[16*16],pcxname[20];
int i1,i2,i3, i=0, j=0, whflag=0,bkflag=0;

int ppcx_buf = 0, lpinline=0;
FILE *fpcx;
	memset(pcx_buf,0,16*16);
	curpos = ((tempwd-0xa1)*94+(tempwd1-0xa1))*32L;
	fseek(fhzk16,curpos,0);
	fread(wd_buf,16*2,1,fhzk16);

	for(i1=0;i1<16;i1++)
	{
	  lpinline = 0;
	  for(i2=0;i2<2;i2++)
	  {
		for(i3=0;i3<8;i3++)
		{
		  lpinline++;
		  if(!F_getbit(wd_buf[i1*2+i2],7-i3))
		  { i++;                  //white.
			if(i==1&&j==1)
			  bkflag = 1;
		  }
		  else
		  { j++;
			if(i==1&&j==1)
			  whflag = 1;
		  }

		  if(lpinline==16) //one line  has been finished
		  {
			if(i==0&&j==1)
			  goto One_black;
			if(i==1&&j==0)
			  goto One_white;
			if(i==0&&j>1)
			  goto N_black;
			if(i>1&&j==0)
			  goto N_white;
			if(i>1&&j==1)
			{
			  pcx_buf[ppcx_buf++] = 0xc0+i;
			  pcx_buf[ppcx_buf++] = 0x11;  //0xff;
			  i=0;
			  pcx_buf[ppcx_buf++] = 0x0;
			  j=0;
			  bkflag = 0; continue;
			}
			if(j>1&&i==1)
			{
			  pcx_buf[ppcx_buf++] = 0xc0+j;
			  pcx_buf[ppcx_buf++] = 0x0;
			  j=0;
			  pcx_buf[ppcx_buf++] = 0x11;  //grey  0xff; //white
			  i=0;
			  whflag = 0; continue;
			}
			if(i==1&&j==1)
			{
			   if(bkflag)
               { 
                pcx_buf[ppcx_buf++] = 0x0;  //black
                pcx_buf[ppcx_buf++] = 0x11;  //grey  0xff; //white
			   }
			   else
			   {
			    pcx_buf[ppcx_buf++] = 0x11;  //grey  0xff; //white
			    pcx_buf[ppcx_buf++] = 0x0;  //black
			   }
			    j=0;
				bkflag = 0; 
			    i=0;
			    whflag = 0; continue;
			}
		  }


///////////////////////////////////////////////////
		  if(whflag)
		  {
One_white:
			//pcx_buf[ppcx_buf++] = 0xc1;
			pcx_buf[ppcx_buf++] = 0x11;  //grey  0xff; //white
			i=0;
			whflag = 0; continue;
		  }
		  if(bkflag)
		  {
One_black:
			pcx_buf[ppcx_buf++] = 0x0;
			j=0;
			bkflag = 0; continue;
		  }
		  if(j==1&&i>1)
		  {
N_white:
			pcx_buf[ppcx_buf++] = 0xc0+i;
			pcx_buf[ppcx_buf++] = 0x11;  //0xff;
			i=0;
			continue;
		  }
		  if(i==1&&j>1)
		  {
N_black:
			pcx_buf[ppcx_buf++] = 0xc0+j;
			pcx_buf[ppcx_buf++] = 0x0;
			j=0;
		  }

		}
	  }
	}//end the word

//out *.pcx	file.
	itoa(1000+posword,pcxname,10);
	strcat(pcxname,".pcx");
char t[20];
	strcpy(t,pcxname);
	strcpy(pcxname,"out\\g");
	strcat(pcxname,t);
	if((fpcx=fopen(pcxname,"w+b"))==NULL)
		{    printf("cannot open the file : %s please to check the  file",pcxname);
			  exit(1);
		}

	//allpcx_buf  //save all data
	fwrite(&sHeader,128,1,fpcx);
	fwrite(pcx_buf,ppcx_buf,1,fpcx);
	fwrite(colorref_buf,256*3+1,1,fpcx);
	
	fclose(fpcx);
	return 0;

}

int F_getbit(char ch1, char pbit)
{
	int res;

	res = ch1>>pbit;
	res &= 1;
	if(res>0)
	  return 1;
	else
	  return 0;
}

⌨️ 快捷键说明

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