]> 4ch.mooo.com Git - 16.git/blob - 16/v2/source/UTIL/PCX2FNT/PCX2FNT.C
attempted font system added
[16.git] / 16 / v2 / source / UTIL / PCX2FNT / PCX2FNT.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #include <stdio.h>\r
18 #include <malloc.h>\r
19 \r
20 char fname1[100], fname2[100];\r
21 int xs, ys, ns;\r
22 FILE *fnt,*pcxf;\r
23 char *virscr;\r
24 \r
25 char manufacturer;                     // pcx header\r
26 char version;\r
27 char encoding;\r
28 char bits_per_pixel;\r
29 short int xmin,ymin;\r
30 short int xmax,ymax;\r
31 short int hres;\r
32 short int vres;\r
33 char palette[48];\r
34 char reserved;\r
35 char color_planes;\r
36 short int bytes_per_line;\r
37 short int palette_type;\r
38 char filler[58];\r
39 unsigned char pal[768];\r
40 \r
41 unsigned short int width,depth;\r
42 unsigned short int bytes;\r
43 unsigned char c, run, ss=0;\r
44 unsigned int vidoffset, n=0;\r
45 \r
46 void ReadPCXLine(unsigned char *dest)\r
47 {\r
48   int j;\r
49   n=0;\r
50 \r
51   do {\r
52   c=fgetc(pcxf) & 0xff;\r
53     if ((c & 0xc0)==0xc0) {\r
54        run=c & 0x3f;\r
55        c=fgetc(pcxf);\r
56        for (j=0; j<run; j++)\r
57            dest[vidoffset+n+j]=c;\r
58        n+=run; }\r
59     else { dest[vidoffset+n]=c;\r
60            n++; }\r
61   } while (n<bytes);\r
62 }\r
63 \r
64 void LoadPCXHeader()\r
65 {\r
66   fread(&manufacturer,1,1,pcxf);\r
67   fread(&version,1,1,pcxf);\r
68   fread(&encoding,1,1,pcxf);\r
69   fread(&bits_per_pixel,1,1,pcxf);\r
70   fread(&xmin,1,2,pcxf);\r
71   fread(&ymin,1,2,pcxf);\r
72   fread(&xmax,1,2,pcxf);\r
73   fread(&ymax,1,2,pcxf);\r
74   fread(&hres,1,2,pcxf);\r
75   fread(&vres,1,2,pcxf);\r
76   fread(&palette,1,48,pcxf);\r
77   fread(&reserved,1,1,pcxf);\r
78   fread(&color_planes,1,1,pcxf);\r
79   fread(&bytes_per_line,1,2,pcxf);\r
80   fread(&palette_type,1,2,pcxf);\r
81   fread(&filler,1,58,pcxf);\r
82   fseek(pcxf,-768L,SEEK_END);\r
83   fread(&pal,1,768,pcxf);\r
84   fseek(pcxf,128L,SEEK_SET);\r
85   width=xmax-xmin+1;\r
86   depth=ymax-ymin+1;\r
87   bytes=bytes_per_line;\r
88 }\r
89 \r
90 void dumpframe(int x, int y)\r
91 { int i,j;\r
92   unsigned char c;\r
93 \r
94   for (i=y; i<y+ys; i++)\r
95    for (j=x; j<x+xs; j++)\r
96      {\r
97        c=virscr[(i*width)+j];\r
98        fwrite(&c, 1, 1, fnt);\r
99      }\r
100 }\r
101 \r
102 int main()\r
103 {\r
104   int i,j,z;\r
105 \r
106   printf("PCX2FNT v.3.00 Copyright (C)1998 BJ Eirich \n");\r
107   printf("PCX filename: "); fflush(stdout);\r
108   scanf("%s",fname1);\r
109   pcxf=fopen(fname1,"rb");\r
110   printf("FNT filename: "); fflush(stdout);\r
111   scanf("%s",fname2);\r
112   fnt=fopen(fname2, "wb");\r
113   printf("Width of font: "); fflush(stdout);\r
114   scanf("%d", &xs);\r
115   printf("Height of font: "); fflush(stdout);\r
116   scanf("%d", &ys);\r
117   printf("Number of subsets: "); fflush(stdout);\r
118   scanf("%d", &ns);\r
119 \r
120   version=1;\r
121   fwrite(&version, 1, 1, fnt);\r
122   fwrite(&xs, 1, 2, fnt);\r
123   fwrite(&ys, 1, 2, fnt);\r
124   fwrite(&ns, 1, 2, fnt);\r
125 \r
126   LoadPCXHeader();\r
127   virscr=(char *) malloc(width*depth);\r
128   for (i=0; i<depth; i++)\r
129   {\r
130     vidoffset=i*width;\r
131     ReadPCXLine(virscr);\r
132   }\r
133 \r
134   for (z=0; z<ns; z++)\r
135     for (i=0; i<5; i++)\r
136       for (j=0; j<20; j++)\r
137         if ((i*20)+j<96) dumpframe((j*(xs+1))+1,(i*(ys+1))+(1+(ys+1)*(z*5)));\r
138 \r
139 //  for (i=0; i<5; i++)\r
140 //   for (j=0; j<20; j++)\r
141 //      if ((i*20)+j<96) dumpframe((j*(xs+1))+1,(i*(ys+1))+(1+(ys+1)*5));\r
142 \r
143   fclose(pcxf);\r
144   fclose(fnt);\r
145 \r
146   return 0;\r
147 }\r