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