/*单个汉字库字摸提取程序,tc2.0编译*/
#include "stdio.h"
#include "dos.h"
#include "process.h"
#include "string.h"
void main(void) {
long int num_bytes,qm,wm;
unsigned char d,i,j,k,a[132],b[132];
unsigned char * data;
unsigned char * hz;
static unsigned char dd[103];
FILE *fp;
//
if ((fp=fopen("hzk16f","rb"))==NULL) {
printf("can't open hzk16n");
exit(1);
}
clrscr();
while (1) {
data=(unsigned char *) malloc(33);
printf("please input:n");
scanf("%s",dd); /*输入一个汉字*/
qm=* dd; /*通过区位码计算其在hzk16f文件中的偏移地址*/
qm=qm-161;
if (qm>87) exit(0);
wm=* (dd+1);
wm=wm-161;
if (wm>94) exit(0);
num_bytes=((long)qm*94+wm)*32;
fseek(fp,num_bytes,SEEK_SET);
fgets(data,33,fp);
for (i=0;i<32;i++) b[i]=* data++;
for (i=0;i<32;i+=2) a[i/2]=b[i];
for (i=0;i<32;i+=2) a[i/2+16]=b[i+1];
for (i=8;i<16;i++) b[i]=a[i];
for (i=8;i<16;i++) a[i]=a[i+8];
for (i=8;i<16;i++) a[i+8]=b[i];
/*转换,hzf16f在电脑的储存格式是以行为字节计算的,一般的lcd都采用以列为字节计算*/
for (k=0;k<32;k+=8) {
for (j=0;j<8;j++) {
d=0;
for (i=0;i<8;i++) {
if (a[i+k]>=0x80) {
switch (i) {
case 0:d+=1;break;
case 1:d+=2;break;
case 2:d+=4;break;
case 3:d+=8;break;
case 4:d+=0x10;break;
case 5:d+=0x20;break;
case 6:d+=0x40;break;
case 7:d+=0x80;break;
}
}
}
for (i=0;i<8;i++) a[i+k]<<=1;
b[j+k]=d;
}
}
clrscr();
printf("/*%s:*/n",dd); /*输出0x00格式的16进制数*/
for (k=0;k<32;k+=8) {
for (j=0;j<8;j++) printf("0x%x,",b[j+k]);
printf("n");
}
getch();
}
}