0
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3
|
|
4 #include "pwplib.h"
|
|
5 #include "convert.h"
|
|
6
|
|
7 /*
|
|
8 * Doubleheight IBM
|
|
9 *
|
|
10 */
|
|
11
|
|
12 void convcalc_1to12() /* &1 == ibm2ibm, */
|
|
13 {
|
|
14 u8 tabsrc[]=
|
|
15 {
|
|
16 '\"', '\"',' ',
|
|
17 '/', '|','/',
|
|
18 '\'', '\'',' ',
|
|
19 '/', '|', '/',
|
|
20
|
|
21 '\\', '\\','|',
|
|
22 '^', '^', ' ',
|
|
23
|
|
24 '`', '`', ' ',
|
|
25
|
|
26 '|', '|', '|',
|
|
27 '~', '~', ' ',
|
|
28
|
|
29 176, 176, 176,
|
|
30 177, 177, 177,
|
|
31 178, 178, 178,
|
|
32
|
|
33 179, 179, 179,
|
|
34 180, 179, 180,
|
|
35 181, 179, 181,
|
|
36 182, 186, 182,
|
|
37 185, 186, 185,
|
|
38 186, 186, 186,
|
|
39 188, 186, 188,
|
|
40 189, 186, 189,
|
|
41 190, 179, 190,
|
|
42 192, 179, 192,
|
|
43 193, 179, 193,
|
|
44 195, 179, 195,
|
|
45 197, 179, 197,
|
|
46 198, 179, 198,
|
|
47 199, 186, 199,
|
|
48 200, 186, 200,
|
|
49 202, 186, 202,
|
|
50 204, 186, 204,
|
|
51 206, 186, 206,
|
|
52 207, 179, 207,
|
|
53 208, 186, 208,
|
|
54 211, 186, 211,
|
|
55 212, 179, 212,
|
|
56 215, 186, 215,
|
|
57 216, 179, 216,
|
|
58 217, 179, 217,
|
|
59
|
|
60 219, 219, 219,
|
|
61 220, 32, 219,
|
|
62 221, 221, 221,
|
|
63 222, 222, 222,
|
|
64 223, 219, 32,
|
|
65 0
|
|
66 };
|
|
67 u8*t=tabsrc;
|
|
68
|
|
69 int i=0;
|
|
70
|
|
71 for(;i<256;i++)
|
|
72 {
|
|
73 pwpconv.tab1to12[i]=BYTES2(pwpconv.font[i],32);
|
|
74 }
|
|
75
|
|
76 while(*t)
|
|
77 {
|
|
78 pwpconv.tab1to12[*t]=BYTES2(pwpconv.font[t[2]],pwpconv.font[t[1]]);
|
|
79 t+=3;
|
|
80 }
|
|
81 }
|
|
82
|
|
83 void conv_1to12(u8*d,u8*s,int w,int h)
|
|
84 {
|
|
85 w<<=1;
|
|
86 for(;h;h--)
|
|
87 {
|
|
88 int x=w>>1;
|
|
89 for(;x;x--)
|
|
90 {
|
|
91 int a=pwpconv.tab1to12[*s];
|
|
92
|
|
93 d[0]=SECONDBYTE(a);
|
|
94 d[w]=FIRSTBYTE(a);
|
|
95 d[1]=d[w+1]=s[1];
|
|
96
|
|
97 d+=2;
|
|
98 s+=2;
|
|
99 }
|
|
100 d+=w;
|
|
101 }
|
|
102 }
|
|
103
|
|
104 /*
|
|
105 * Megatab (ibm color16x16 => any) initialization
|
|
106 *
|
|
107 *
|
|
108 */
|
|
109
|
|
110 /*
|
|
111 * purely font/charset related
|
|
112 */
|
|
113
|
|
114 void convcalc_ascii()
|
|
115 {
|
|
116 memcpy(pwpconv.font,
|
|
117 /*00*/ " OOwoxAoooo6qrn*"
|
|
118 /*10*/ "><8!PS_8^v><L-^v"
|
|
119 /*20*/ " !\"#$%&'()*+,-./"
|
|
120 /*30*/ "0123456789:;<=>?"
|
|
121 /*40*/ "@ABCDEFGHIJKLMNO"
|
|
122 /*50*/ "PQRSTUVWXYZ[\\]^_"
|
|
123 /*60*/ "`abcdefghijklmno"
|
|
124 /*70*/ "pqrstuvwxyz{|}~A"
|
|
125 /*80*/ "CueaaaaceeeiiiAA"
|
|
126 /*90*/ "E&&ooouuyOUcEVPf"
|
|
127 /*A0*/ "aiounNao?--%%!<>"
|
|
128 /*B0*/ "%#M||||..||.'''."
|
|
129 /*C0*/ "`--|-+||`.--|-+-"
|
|
130 /*D0*/ "---``-.++'.8opd^"
|
|
131 /*E0*/ "aBrhEouiO0Od-%EA"
|
|
132 /*F0*/ "=+><|J%~o-.Vn2o ",256*sizeof(char));
|
|
133 }
|
|
134
|
|
135 void convcalc_termsafe()
|
|
136 {
|
|
137 int i=256;u8*s=pwpconv.font;
|
|
138 for(;i;i--)
|
|
139 {
|
|
140 if(*s<32 || *s==127)*s=32;
|
|
141 s++;
|
|
142 }
|
|
143 }
|
|
144
|
|
145 /*
|
|
146 * purely colortab related
|
|
147 */
|
|
148
|
|
149 void convcalc_monotab(int parms)
|
|
150 {
|
|
151 memset(pwpconv.col,(parms&1)?0x00:0x07,256*sizeof(u8));
|
|
152 }
|
|
153
|
|
154 void convcalc_monotab_attr(int parms)
|
|
155 {
|
|
156 u8 attrmo[2][2]= /* &1: 0=ansicol_dump, 1=vt_dump */
|
|
157 {
|
|
158 0x00,0x01,
|
|
159 0x07,0x70
|
|
160 };
|
|
161
|
|
162 const char intens[16]=
|
|
163 {
|
|
164 0,1,6,7, 3,4,9,10,
|
|
165 1,2,9,10,5,6,13,15
|
|
166 };
|
|
167
|
|
168 int i=0;
|
|
169 for(;i<256;i++)
|
|
170 pwpconv.col[i]=
|
|
171 attrmo[parms&1][intens[i&15]>intens[(i>>4)&15]?0:1];
|
|
172 }
|
|
173
|
|
174 void convcalc_colortab(int parms)
|
|
175 {
|
|
176 int i;
|
|
177 char tabs[32];
|
|
178
|
|
179 for(i=0;i<32;i++)tabs[i]=i&15;
|
|
180
|
|
181 if(parms&1){ /* 8 colors in foreground, else 16 */
|
|
182 memcpy(tabs+8, "\003\003\002\003\004\005\006\007",8);
|
|
183 }
|
|
184
|
|
185 if(parms&2) /* 8 colors in background, else 16 */
|
|
186 memcpy(tabs+24, "\003\003\002\003\004\005\006\007",8);
|
|
187
|
|
188 if(parms&4) /* ansi color order (bgr) instead of cga (rgb) */
|
|
189 for(i=0;i<32;i++)
|
|
190 tabs[i]=(tabs[i]&~7)|
|
|
191 "\000\004\002\006\001\005\003\007"[tabs[i]&7];
|
|
192
|
|
193 for(i=0;i<256;i++)
|
|
194 pwpconv.col[i]=tabs[i&15]|(tabs[16+((i>>4)&15)]<<4);
|
|
195 }
|
|
196
|
|
197 /*
|
|
198 * finishing the megatab
|
|
199 */
|
|
200
|
|
201 /*
|
|
202 1: eliminate 178/219 (if inverse supported & 178/219 doesnt exist)
|
|
203 2: eliminate halfblocks (if chars, preferably if we have rasterchar && fullres)
|
|
204 4: replace rasters (if no bgcolors or no colors at all? smwhr else?)
|
|
205 8: sometimes repl 176 with 177 (if only 8 colors at bg - dont use with &4)
|
|
206
|
|
207 normal ascii rasterchars: 176='%', 177='@'
|
|
208 in vt100, both 176&177 are replaced with halfraster
|
|
209 */
|
|
210 void convcalc_megatab_finish(int flags)
|
|
211 {
|
|
212 const char intens[16]=
|
|
213 {
|
|
214 0,1,6,7, 3,4,9,10,
|
|
215 1,2,9,10,5,6,13,15
|
|
216 };
|
|
217
|
|
218 int ch,at;
|
|
219 u8*s=(u8*)pwpconv.megatab;
|
|
220
|
|
221 # ifndef BIG_ENDIAN
|
|
222 for(at=0;at<256;at++)
|
|
223 for(ch=0;ch<256;ch++)
|
|
224 # else
|
|
225 for(ch=0;ch<256;ch++)
|
|
226 for(at=0;at<256;at++)
|
|
227 # endif
|
|
228 {
|
|
229 int fg=at&15,bg=(at>>4)&15,at1=at,ch1=ch;
|
|
230
|
|
231 if(ch==32 || ch==0 || ch==255)fg=bg;else
|
|
232 if(ch==219)bg=fg;
|
|
233
|
|
234 if(fg==bg)
|
|
235 {
|
|
236 if(fg&8)
|
|
237 {
|
|
238 ch1=219;at1=fg;
|
|
239 }
|
|
240 else
|
|
241 {
|
|
242 ch1=32;at1=fg<<4;
|
|
243 }
|
|
244 }
|
|
245 else
|
|
246 if(ch>=220 && ch<=223)
|
|
247 {
|
|
248 if((at1&128) && intens[bg]>intens[fg])
|
|
249 {
|
|
250 ch1=223-(ch1-220);
|
|
251 at1=((at1>>4)&15)|((at1<<4)&0xf0);
|
|
252 }
|
|
253 if(flags&2)ch1=177;
|
|
254 }
|
|
255 else
|
|
256 if(ch>=176 && ch<=178)
|
|
257 {
|
|
258 if((at1&128) || intens[bg]>intens[fg])
|
|
259 {
|
|
260 if(ch1==176)ch1=178; else
|
|
261 if(ch1==178)ch1=176;
|
|
262
|
|
263 at1=((at1>>4)&15)|((at1<<4)&0xf0);
|
|
264
|
|
265 /* flags&8: use 177 when 176 with doublebright */
|
|
266 if((at1&128) && (flags&8) && (ch1==176))
|
|
267 ch1=177;
|
|
268 }
|
|
269 }
|
|
270
|
|
271 /* flags&1: eliminate 178/219 */
|
|
272 if((ch1==178 || (ch1==219)) && (flags&1))
|
|
273 {
|
|
274 ch1=(ch1==178)?176:32;
|
|
275 at1=((at1>>4)&15)|((at1<<4)&0xf0);
|
|
276 }
|
|
277
|
|
278 /* flags&4: replace rasters (32/176/177) with something else
|
|
279 (replace color info with char stuff
|
|
280 */
|
|
281
|
|
282 s[0]=pwpconv.font[ch1];
|
|
283 s[1]=pwpconv.col[at1];
|
|
284
|
|
285 s+=2;
|
|
286 }
|
|
287 }
|
|
288
|
|
289 /*******************************/
|
|
290
|
|
291
|
|
292 void conv_dump_ibm_megatab()
|
|
293 {
|
|
294 TEMPMALL(u16,tmp,pwplib.videobuf.height*pwplib.videobuf.width*2),
|
|
295 *s=(u16*)pwplib.videobuf.d,*d=tmp;
|
|
296
|
|
297 int i=pwplib.videobuf.height*pwplib.videobuf.width;
|
|
298 for(;i;i--)*d++=pwpconv.megatab[*s++];
|
|
299
|
|
300 {u8*pushed=pwplib.videobuf.d;
|
|
301 pwplib.videobuf.d=(u8*)tmp;
|
|
302 pwpconv.orig_dump_attr();
|
|
303 pwplib.videobuf.d=pushed;
|
|
304 }
|
|
305
|
|
306 TEMPFREE(tmp);
|
|
307 }
|
|
308
|
|
309 void conv_fromibm_double()
|
|
310 {
|
|
311 int lgt=pwplib.videobuf.width*pwplib.videobuf.height;
|
|
312
|
|
313 TEMPMALL(u8,tmp,lgt*2*2);
|
|
314
|
|
315 conv_1to12(tmp,pwplib.videobuf.d,pwplib.videobuf.width,pwplib.videobuf.height);
|
|
316
|
|
317 {char*save=pwplib.videobuf.d;
|
|
318 pwplib.videobuf.d=tmp;
|
|
319 pwplib.videobuf.height<<=1;
|
|
320 conv_dump_ibm_megatab();
|
|
321 pwplib.videobuf.height>>=1;
|
|
322 pwplib.videobuf.d=save;
|
|
323 }
|
|
324
|
|
325 TEMPFREE(tmp);
|
|
326 }
|
|
327
|
|
328 void conv_fromibm_half()
|
|
329 {
|
|
330 TEMPMALL(u8,tmp,pwplib.videobuf.width*pwplib.videobuf.height),
|
|
331 *d=tmp,*s=pwplib.videobuf.d;
|
|
332
|
|
333 int y;
|
|
334 y=pwplib.videobuf.height>>1;
|
|
335
|
|
336 for(;y;y--)
|
|
337 {
|
|
338 int x=pwplib.videobuf.width,
|
|
339 w=x<<1;
|
|
340 for(;x;x--)
|
|
341 {
|
|
342 d[0]=pwpconv.font[s[0]];
|
|
343 d[1]=s[1]|s[1+w];
|
|
344 s+=2;d+=2;
|
|
345 }
|
|
346 s+=w;
|
|
347 }
|
|
348
|
|
349 {char*save=pwplib.videobuf.d;
|
|
350 pwplib.videobuf.d=tmp;
|
|
351 pwplib.videobuf.height>>=1;
|
|
352 conv_dump_ibm_megatab();
|
|
353 pwpconv.orig_dump_attr();
|
|
354 pwplib.videobuf.d=save;
|
|
355 pwplib.videobuf.height<<=1;
|
|
356 }
|
|
357
|
|
358 TEMPFREE(tmp);
|
|
359 }
|
|
360
|
|
361 /* dump_ibm_halved, dump_ibm_realsize */
|
|
362 void conv_dump_ibm()
|
|
363 {
|
|
364 if(pwplib.setup[SETUP_HALVE])
|
|
365 {
|
|
366 if(pwplib.videobuf.height==50) /* kludge */
|
|
367 conv_fromibm_half();
|
|
368 else conv_dump_ibm_megatab();
|
|
369 }
|
|
370 else
|
|
371 {
|
|
372 if(pwplib.videobuf.height==50)
|
|
373 conv_dump_ibm_megatab();
|
|
374 else conv_fromibm_double();
|
|
375 }
|
|
376 }
|