0
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3
|
|
4 #include "convert.h"
|
|
5 #include "tty.h"
|
|
6
|
|
7 /*** funx ***/
|
|
8
|
55
|
9 static int conv_rast2rgb(int i)
|
0
|
10 {
|
|
11 int r=0,g=0,b=0;
|
|
12
|
|
13 {int a=(i&8)?6:3;
|
|
14 if(i&4)r+=a;
|
|
15 if(i&2)g+=a;
|
|
16 if(i&1)b+=a;
|
|
17 if((i&15)==8)
|
|
18 {
|
|
19 r=2;
|
|
20 g=2;
|
|
21 b=2;
|
|
22 }
|
|
23 }
|
|
24
|
|
25 {int a=(i&128)?9:4;
|
|
26 if(i&64)r+=a;
|
|
27 if(i&32)g+=a;
|
|
28 if(i&16)b+=a;
|
|
29 if((i&0xf0)==128)
|
|
30 {
|
|
31 r+=3;
|
|
32 g+=3;
|
|
33 b+=3;
|
|
34 }
|
|
35 }
|
|
36
|
|
37 return (r<<8)|(g<<4)|b;
|
|
38 }
|
|
39
|
55
|
40 static int conv_rgbdiff(int a,int b)
|
0
|
41 {
|
|
42 int rd=((a>>8)&15)-((b>>8)&15);
|
|
43 int gd=((a>>4)&15)-((b>>4)&15);
|
|
44 int bd=(a&15)-(b&15);
|
|
45
|
|
46 return abs(rd)*3+abs(gd)*6+abs(bd); /* max diff 150 */
|
|
47 }
|
|
48
|
|
49 /*** table generators ***/
|
|
50
|
55
|
51 void convcalc_rast_ibmcol(void)
|
0
|
52 {
|
|
53 const char intens[16]=
|
|
54 {
|
|
55 0,1,6,7, 3,4,9,10,
|
|
56 1,2,9,10,5,6,13,15
|
|
57 };
|
|
58
|
|
59 int up,dn;
|
|
60 for(dn=0;dn<256;dn++)
|
|
61 for(up=0;up<256;up++)
|
|
62 {
|
|
63 int ch=176,at=dn|up;
|
|
64 int dins=intens[dn&15]+intens[(dn>>4)&15]*3;
|
|
65 int uins=intens[up&15]+intens[(up>>4)&15]*3;
|
|
66
|
|
67 if(uins>=(dins<<1))
|
|
68 {
|
|
69 ch=223;
|
|
70 at=((up>>4)&15)|(dn&0xf0);
|
|
71 }
|
|
72 else
|
|
73 if(dins>=(uins<<1))
|
|
74 {
|
|
75 ch=220;
|
|
76 at=((dn>>4)&15)|(up&0xf0);
|
|
77 }
|
|
78
|
|
79 pwpconv.rasthalve[BYTES2(up,dn)]=
|
|
80 pwpconv.megatab[BYTES2(ch,at)];
|
|
81 }
|
|
82 }
|
|
83
|
55
|
84 void convcalc_rast_col(void)
|
0
|
85 {
|
|
86 const char convtab[8*8]=
|
|
87 " .,%xuow"
|
|
88 " :;%xhbw"
|
|
89 "';?%UJdm"
|
|
90 "\";?%OO66"
|
|
91 "~^?TXS6W"
|
|
92 "^qqTS8WW"
|
|
93 "^?pYNNN@"
|
|
94 "^?q9MM@@";
|
|
95
|
|
96 int up,dn;
|
|
97 for(dn=0;dn<256;dn++)
|
|
98 for(up=0;up<256;up++)
|
|
99 {
|
|
100 int fg=((dn|up)|((dn|up)>>4))&15,
|
|
101 bg=((dn&up)&((dn&up)>>4))&15;
|
|
102
|
|
103 /* if limcols: bg == constant background or sumthing */
|
|
104
|
|
105 int dnbg=
|
|
106 conv_rgbdiff(conv_rast2rgb(bg*0x11),
|
|
107 conv_rast2rgb(dn)),
|
|
108 dnfg=
|
|
109 conv_rgbdiff(conv_rast2rgb(fg*0x11),
|
|
110 conv_rast2rgb(dn)),
|
|
111 upbg=
|
|
112 conv_rgbdiff(conv_rast2rgb(bg*0x11),
|
|
113 conv_rast2rgb(up)),
|
|
114 upfg=
|
|
115 conv_rgbdiff(conv_rast2rgb(fg*0x11),
|
|
116 conv_rast2rgb(up));
|
|
117
|
|
118 int dnpart=(dnfg*8)/(dnbg+dnfg+1),
|
|
119 uppart=(upfg*8)/(upbg+upfg+1);
|
|
120
|
|
121 if(dnpart>7)dnpart=7;
|
|
122 if(uppart>7)uppart=7;
|
|
123
|
|
124 pwpconv.rasthalve[BYTES2(dn,up)]=
|
|
125 pwpconv.megatab[
|
|
126 BYTES2(convtab[dnpart|(uppart<<3)],
|
|
127 (fg|(bg<<4)))&0xffff];
|
|
128 }
|
|
129 }
|
|
130
|
|
131 void convcalc_rast_mono()
|
|
132 {
|
|
133 const char intens[16]=
|
|
134 {
|
|
135 0,1,6,7, 3,4,9,10,
|
|
136 1,2,9,10,5,6,13,15
|
|
137 };
|
|
138
|
|
139 const char convtab[8*8]=
|
|
140 " .,%xuow"
|
|
141 " :;%xhbw"
|
|
142 "';?%UJdm"
|
|
143 "\";?%OO66"
|
|
144 "~^?TXS6W"
|
|
145 "^qqTS8WW"
|
|
146 "^?pYNNN@"
|
|
147 "^?q9MM@@";
|
|
148
|
|
149 /* kludge.. */
|
|
150 #ifndef __POSIX__
|
55
|
151 int col = 0x07;
|
0
|
152 #else
|
55
|
153 int col = (pwplib.dump_attr == tty_vt_dump_attr) ? 0x00 : 0x07;
|
0
|
154 #endif
|
|
155 int up,dn;
|
|
156
|
|
157 for(dn=0;dn<256;dn++)
|
|
158 for(up=0;up<256;up++)
|
|
159 {
|
|
160 int dins=(intens[dn&15]+intens[(dn>>4)&15]*3);
|
|
161 int uins=(intens[up&15]+intens[(up>>4)&15]*3);
|
|
162
|
|
163 if(dins<7 && uins<7 && (dins|uins))
|
|
164 {
|
|
165 if(uins>=dins)uins=7;
|
|
166 if(uins<=dins)dins=7;
|
|
167 }
|
|
168
|
|
169 dins/=7;
|
|
170 uins/=7;
|
|
171
|
|
172 if(dins>7)dins=7;
|
|
173 if(uins>7)uins=7;
|
|
174
|
|
175 #ifdef __POSIX__
|
|
176 if(pwp_tty.type==TTY_VT2XX)
|
|
177 pwpconv.rasthalve[BYTES2(up,dn)]=
|
|
178 BYTES2(32+(dins|(uins<<3)),0x10);
|
|
179 else
|
|
180 #endif
|
|
181 pwpconv.rasthalve[BYTES2(up,dn)]=
|
|
182 BYTES2(convtab[dins|(uins<<3)],col);
|
|
183 }
|
|
184 }
|
|
185
|
|
186 /******** conv_fromrast ***********/
|
|
187
|
56
|
188 void conv_fromrast_half(u8 *d, u8 *s, int hgt, int wdt)
|
0
|
189 {
|
56
|
190 u16 *dd = (u16 *) d;
|
|
191 for(hgt >>= 1; hgt; hgt--)
|
0
|
192 {
|
|
193 int x=wdt;
|
|
194 for(;x;x--)
|
|
195 {
|
56
|
196 *dd++ = pwpconv.rasthalve[BYTES2(s[0],s[wdt])];
|
0
|
197 s++;
|
|
198 }
|
|
199 s+=wdt;
|
|
200 }
|
|
201 }
|
|
202
|
56
|
203 void conv_fromrast_full(u8 *d, u8 *s, int lgt)
|
0
|
204 {
|
56
|
205 u16 *dd = (u16 *) d;
|
|
206 s++;
|
|
207 for(; lgt; lgt--)
|
0
|
208 {
|
56
|
209 /* NOTICE! ATTENTION! This was originally *d++ .. does that even work?
|
|
210 * -- ccr
|
|
211 */
|
|
212 *dd++ = pwpconv.rasthalve[BYTES2(s[0],s[0])];
|
0
|
213 s++;
|
|
214 }
|
|
215 }
|
|
216
|
|
217 /*********************************/
|
|
218
|
55
|
219 void conv_dump_rast(void)
|
0
|
220 {
|
|
221 TEMPMALL(u8,tmp,pwplib.videobuf.height*pwplib.videobuf.width*2);
|
|
222
|
|
223 /*
|
|
224 if(pwplib.setup[SETUP_LOSSY])
|
|
225 conv_losestuff(pwplib.videobuf.d,
|
|
226 pwplib.videobuf.height*pwplib.videobuf.width,1);
|
|
227 */
|
|
228 if(pwplib.setup[SETUP_HALVE])
|
|
229 {
|
|
230 u8*push=pwplib.videobuf.d;
|
|
231 conv_fromrast_half(tmp,pwplib.videobuf.d,
|
|
232 pwplib.videobuf.height,pwplib.videobuf.width);
|
|
233
|
|
234 pwplib.videobuf.d=tmp;
|
|
235 pwplib.videobuf.height>>=1;
|
|
236 pwpconv.orig_dump_attr();
|
|
237 pwplib.videobuf.height<<=1;
|
|
238 pwplib.videobuf.d=push;
|
|
239 }
|
|
240 else
|
|
241 {u8*push=pwplib.videobuf.d;
|
|
242
|
|
243 conv_fromrast_full(tmp,pwplib.videobuf.d,
|
|
244 pwplib.videobuf.height*pwplib.videobuf.width);
|
|
245
|
|
246 pwplib.videobuf.d=tmp;
|
|
247 pwpconv.orig_dump_attr();
|
|
248 pwplib.videobuf.d=push;
|
|
249 }
|
|
250
|
|
251 TEMPFREE(tmp);
|
|
252 }
|