1 |
*** compface/compress.c Tue Jan 15 23:58:46 2002 |
2 |
--- /home/lkoeller/tmp/ports/mail/faces/work/faces/compface/compress.c Wed Jun 19 08:29:13 1991 |
3 |
*************** |
4 |
*** 17,113 **** |
5 |
#include "compface.h" |
6 |
|
7 |
int |
8 |
! Same(char *f, int wid, int hei) |
9 |
{ |
10 |
! char val, *row; |
11 |
! int x; |
12 |
|
13 |
val = *f; |
14 |
! while (hei--) { |
15 |
row = f; |
16 |
x = wid; |
17 |
! while (x--) { |
18 |
! if (*(row++) != val) { |
19 |
return(0); |
20 |
- } |
21 |
- } |
22 |
f += WIDTH; |
23 |
} |
24 |
! return(1); |
25 |
} |
26 |
|
27 |
- |
28 |
int |
29 |
! AllBlack(char *f, int wid, int hei) |
30 |
{ |
31 |
! if (wid > 3) { |
32 |
wid /= 2; |
33 |
hei /= 2; |
34 |
! return(AllBlack(f, wid, hei) && AllBlack(f + wid, wid, hei) && |
35 |
AllBlack(f + WIDTH * hei, wid, hei) && |
36 |
AllBlack(f + WIDTH * hei + wid, wid, hei)); |
37 |
- } else { |
38 |
- return(*f || *(f + 1) || *(f + WIDTH) || *(f + WIDTH + 1)); |
39 |
} |
40 |
} |
41 |
|
42 |
- |
43 |
int |
44 |
! AllWhite(char *f, int wid, int hei) |
45 |
{ |
46 |
! return((*f == 0) && Same(f, wid, hei)); |
47 |
} |
48 |
|
49 |
- |
50 |
void |
51 |
! PopGreys(char *f, int wid, int hei) |
52 |
{ |
53 |
! if (wid > 3) { |
54 |
wid /= 2; |
55 |
hei /= 2; |
56 |
PopGreys(f, wid, hei); |
57 |
PopGreys(f + wid, wid, hei); |
58 |
PopGreys(f + WIDTH * hei, wid, hei); |
59 |
PopGreys(f + WIDTH * hei + wid, wid, hei); |
60 |
! } else { |
61 |
wid = BigPop(freqs); |
62 |
! if (wid & 1) { |
63 |
*f = 1; |
64 |
! } |
65 |
! if (wid & 2) { |
66 |
*(f + 1) = 1; |
67 |
! } |
68 |
! if (wid & 4) { |
69 |
*(f + WIDTH) = 1; |
70 |
! } |
71 |
! if (wid & 8) { |
72 |
*(f + WIDTH + 1) = 1; |
73 |
} |
74 |
- } |
75 |
} |
76 |
|
77 |
- |
78 |
void |
79 |
! PushGreys(char *f, int wid, int hei) |
80 |
{ |
81 |
! if (wid > 3) { |
82 |
wid /= 2; |
83 |
hei /= 2; |
84 |
PushGreys(f, wid, hei); |
85 |
PushGreys(f + wid, wid, hei); |
86 |
PushGreys(f + WIDTH * hei, wid, hei); |
87 |
PushGreys(f + WIDTH * hei + wid, wid, hei); |
88 |
- } else { |
89 |
- RevPush(freqs + *f + 2 * *(f + 1) + |
90 |
- 4 * *(f + WIDTH) + 8 * *(f + WIDTH + 1)); |
91 |
} |
92 |
} |
93 |
|
94 |
- |
95 |
void |
96 |
! UnCompress(char *f, int wid, int hei, int lev) |
97 |
{ |
98 |
! switch (BigPop(&levels[lev][0])) { |
99 |
case WHITE : |
100 |
return; |
101 |
case BLACK : |
102 |
--- 16,120 ---- |
103 |
#include "compface.h" |
104 |
|
105 |
int |
106 |
! Same(f, wid, hei) |
107 |
! register char *f; |
108 |
! register int wid, hei; |
109 |
{ |
110 |
! register char val, *row; |
111 |
! register int x; |
112 |
|
113 |
val = *f; |
114 |
! while (hei--) |
115 |
! { |
116 |
row = f; |
117 |
x = wid; |
118 |
! while (x--) |
119 |
! if (*(row++) != val) |
120 |
return(0); |
121 |
f += WIDTH; |
122 |
} |
123 |
! return 1; |
124 |
} |
125 |
|
126 |
int |
127 |
! AllBlack(f, wid, hei) |
128 |
! char *f; |
129 |
! int wid, hei; |
130 |
{ |
131 |
! if (wid > 3) |
132 |
! { |
133 |
wid /= 2; |
134 |
hei /= 2; |
135 |
! return (AllBlack(f, wid, hei) && AllBlack(f + wid, wid, hei) && |
136 |
AllBlack(f + WIDTH * hei, wid, hei) && |
137 |
AllBlack(f + WIDTH * hei + wid, wid, hei)); |
138 |
} |
139 |
+ else |
140 |
+ return (*f || *(f + 1) || *(f + WIDTH) || *(f + WIDTH + 1)); |
141 |
} |
142 |
|
143 |
int |
144 |
! AllWhite(f, wid, hei) |
145 |
! char *f; |
146 |
! int wid, hei; |
147 |
{ |
148 |
! return ((*f == 0) && Same(f, wid, hei)); |
149 |
} |
150 |
|
151 |
void |
152 |
! PopGreys(f, wid, hei) |
153 |
! char *f; |
154 |
! int wid, hei; |
155 |
{ |
156 |
! if (wid > 3) |
157 |
! { |
158 |
wid /= 2; |
159 |
hei /= 2; |
160 |
PopGreys(f, wid, hei); |
161 |
PopGreys(f + wid, wid, hei); |
162 |
PopGreys(f + WIDTH * hei, wid, hei); |
163 |
PopGreys(f + WIDTH * hei + wid, wid, hei); |
164 |
! } |
165 |
! else |
166 |
! { |
167 |
wid = BigPop(freqs); |
168 |
! if (wid & 1) |
169 |
*f = 1; |
170 |
! if (wid & 2) |
171 |
*(f + 1) = 1; |
172 |
! if (wid & 4) |
173 |
*(f + WIDTH) = 1; |
174 |
! if (wid & 8) |
175 |
*(f + WIDTH + 1) = 1; |
176 |
} |
177 |
} |
178 |
|
179 |
void |
180 |
! PushGreys(f, wid, hei) |
181 |
! char *f; |
182 |
! int wid, hei; |
183 |
{ |
184 |
! if (wid > 3) |
185 |
! { |
186 |
wid /= 2; |
187 |
hei /= 2; |
188 |
PushGreys(f, wid, hei); |
189 |
PushGreys(f + wid, wid, hei); |
190 |
PushGreys(f + WIDTH * hei, wid, hei); |
191 |
PushGreys(f + WIDTH * hei + wid, wid, hei); |
192 |
} |
193 |
+ else |
194 |
+ RevPush(freqs + *f + 2 * *(f + 1) + 4 * *(f + WIDTH) + |
195 |
+ 8 * *(f + WIDTH + 1)); |
196 |
} |
197 |
|
198 |
void |
199 |
! UnCompress(f, wid, hei, lev) |
200 |
! register char *f; |
201 |
! register int wid, hei, lev; |
202 |
{ |
203 |
! switch (BigPop(&levels[lev][0])) |
204 |
! { |
205 |
case WHITE : |
206 |
return; |
207 |
case BLACK : |
208 |
*************** |
209 |
*** 125,139 **** |
210 |
} |
211 |
} |
212 |
|
213 |
- |
214 |
void |
215 |
! Compress(char *f, int wid, int hei, int lev) |
216 |
{ |
217 |
! if (AllWhite(f, wid, hei)) { |
218 |
RevPush(&levels[lev][WHITE]); |
219 |
return; |
220 |
} |
221 |
! if (AllBlack(f, wid, hei)) { |
222 |
RevPush(&levels[lev][BLACK]); |
223 |
PushGreys(f, wid, hei); |
224 |
return; |
225 |
--- 132,149 ---- |
226 |
} |
227 |
} |
228 |
|
229 |
void |
230 |
! Compress(f, wid, hei, lev) |
231 |
! register char *f; |
232 |
! register int wid, hei, lev; |
233 |
{ |
234 |
! if (AllWhite(f, wid, hei)) |
235 |
! { |
236 |
RevPush(&levels[lev][WHITE]); |
237 |
return; |
238 |
} |
239 |
! if (AllBlack(f, wid, hei)) |
240 |
! { |
241 |
RevPush(&levels[lev][BLACK]); |
242 |
PushGreys(f, wid, hei); |
243 |
return; |
244 |
*************** |
245 |
*** 149,164 **** |
246 |
} |
247 |
|
248 |
void |
249 |
! UnCompAll(char *fbuf) |
250 |
{ |
251 |
! char *p; |
252 |
|
253 |
BigClear(); |
254 |
BigRead(fbuf); |
255 |
p = F; |
256 |
! while (p < F + PIXELS) { |
257 |
*(p++) = 0; |
258 |
- } |
259 |
UnCompress(F, 16, 16, 0); |
260 |
UnCompress(F + 16, 16, 16, 0); |
261 |
UnCompress(F + 32, 16, 16, 0); |
262 |
--- 159,174 ---- |
263 |
} |
264 |
|
265 |
void |
266 |
! UnCompAll(fbuf) |
267 |
! char *fbuf; |
268 |
{ |
269 |
! register char *p; |
270 |
|
271 |
BigClear(); |
272 |
BigRead(fbuf); |
273 |
p = F; |
274 |
! while (p < F + PIXELS) |
275 |
*(p++) = 0; |
276 |
UnCompress(F, 16, 16, 0); |
277 |
UnCompress(F + 16, 16, 16, 0); |
278 |
UnCompress(F + 32, 16, 16, 0); |
279 |
*************** |
280 |
*** 171,177 **** |
281 |
} |
282 |
|
283 |
void |
284 |
! CompAll(char *fbuf) |
285 |
{ |
286 |
Compress(F, 16, 16, 0); |
287 |
Compress(F + 16, 16, 16, 0); |
288 |
--- 181,188 ---- |
289 |
} |
290 |
|
291 |
void |
292 |
! CompAll(fbuf) |
293 |
! char *fbuf; |
294 |
{ |
295 |
Compress(F, 16, 16, 0); |
296 |
Compress(F + 16, 16, 16, 0); |
297 |
*************** |
298 |
*** 183,190 **** |
299 |
Compress(F + WIDTH * 32 + 16, 16, 16, 0); |
300 |
Compress(F + WIDTH * 32 + 32, 16, 16, 0); |
301 |
BigClear(); |
302 |
! while (NumProbs > 0) { |
303 |
BigPush(ProbBuf[--NumProbs]); |
304 |
- } |
305 |
BigWrite(fbuf); |
306 |
} |
307 |
--- 194,200 ---- |
308 |
Compress(F + WIDTH * 32 + 16, 16, 16, 0); |
309 |
Compress(F + WIDTH * 32 + 32, 16, 16, 0); |
310 |
BigClear(); |
311 |
! while (NumProbs > 0) |
312 |
BigPush(ProbBuf[--NumProbs]); |
313 |
BigWrite(fbuf); |
314 |
} |