1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*
* Compface - 48x48x1 image compression and decompression
*
* Copyright (c) James Ashton - Sydney University - June 1990.
*
* Written 11th November 1989.
*
* Permission is given to distribute these sources, as long as the
* copyright messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors on inaccuracies inherent
* either to the comments or the code of this program, but if reported
* to me, then an attempt will be made to fix them.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "compface.h"
int compface_xbitmap=0;
void
BigRead(fbuf)
register char *fbuf;
{
register int c;
while (*fbuf != '\0')
{
c = *(fbuf++);
if ((c < FIRSTPRINT) || (c > LASTPRINT))
continue;
BigMul(NUMPRINTS);
BigAdd((WORD)(c - FIRSTPRINT));
}
}
void
BigWrite(fbuf)
register char *fbuf;
{
static WORD tmp;
static char buf[DIGITS];
register char *s;
register int i;
s = buf;
while (B.b_words > 0)
{
BigDiv(NUMPRINTS, &tmp);
*(s++) = tmp + FIRSTPRINT;
}
i = 7; /* leave room for the field name on the first line */
*(fbuf++) = ' ';
while (s-- > buf)
{
if (i == 0)
*(fbuf++) = ' ';
*(fbuf++) = *s;
if (++i >= MAXLINELEN)
{
*(fbuf++) = '\n';
i = 0;
}
}
if (i > 0)
*(fbuf++) = '\n';
*(fbuf++) = '\0';
}
void
ReadFace(fbuf)
char *fbuf;
{
register int c, i;
register char *s, *t;
static char table_inv[] = { 0,8,4,12,2,10,6,14,1,9, 5,13, 3,11, 7,15 };
static char table_nop[] = { 0,1,2, 3,4, 5,6, 7,8,9,10,11,12,13,14,15 };
char *table = table_nop; /* optionally invert bits in nibble */
register inc = 0; /* optionally swap nimmles */
int bits;
int len;
t = s = fbuf;
/* Does this look like an X bitmap ? */
if (sscanf(s, "#define %*s %d", &bits) == 1) {
if (bits == 48) {
char type1[256];
char type2[256];
while (*s && *s++ != '\n');
if (sscanf(s, "#define %*s %d", &bits) == 1) if (bits == 48) {
while (*s && *s++ != '\n');
for (len=0; s[len] && s[len]!='\n'; len++);
if (len<255) {
if (sscanf(s, "static %s %s", type1,type2)==2 &&
(!strcmp(type1, "char") ||
!strcmp(type2, "char"))) {
while (*s && *s++ != '\n');
inc = 1;
table = table_inv;
}
else fprintf(stderr, "warning: xbitmap line 3 not static [unsigned] short ...\n");
} else fprintf(stderr, "warning: xbitmap line 3 too long\n");
}
else fprintf(stderr, "warning: xbitmaps must be 48x48\n");
}
else fprintf(stderr, "warning: xbitmaps must be 48x48\n");
}
/* Ensure s is reset if it was not an X bitmap ... */
if (! inc) s = fbuf;
for(i = strlen(s); i > 0; i--)
{
c = (int)*(s++);
if ((c >= '0') && (c <= '9'))
{
if (t >= fbuf + DIGITS)
{
status = ERR_EXCESS;
break;
}
(t++)[inc] = table[c - '0']; inc = - inc;
}
else if ((c >= 'A') && (c <= 'F'))
{
if (t >= fbuf + DIGITS)
{
status = ERR_EXCESS;
break;
}
(t++)[inc] = table[c - 'A' + 10]; inc = - inc;
}
else if ((c >= 'a') && (c <= 'f'))
{
if (t >= fbuf + DIGITS)
{
status = ERR_EXCESS;
break;
}
(t++)[inc] = table[c - 'a' + 10]; inc = - inc;
}
else if (((c == 'x') || (c == 'X')) && (t > fbuf) &&
((t-1)[-inc] == table[0])) { t--; inc = -inc; }
}
if (t < fbuf + DIGITS)
longjmp(comp_env, ERR_INSUFF);
s = fbuf;
t = F;
c = 1 << (BITSPERDIG - 1);
while (t < F + PIXELS)
{
*(t++) = (*s & c) ? 1 : 0;
if ((c >>= 1) == 0)
{
s++;
c = 1 << (BITSPERDIG - 1);
}
}
}
void
WriteFace(fbuf)
char *fbuf;
{
register char *s, *t;
register int i, bits, digits, words;
int digsperword = DIGSPERWORD;
int wordsperline = WORDSPERLINE;
s = F;
t = fbuf;
bits = digits = words = i = 0;
if (compface_xbitmap) {
sprintf(t,"#define noname_width 48\n#define noname_height 48\nstatic char noname_bits[] = {\n ");
while (*t) t++;
digsperword = 2;
wordsperline = 15;
}
while (s < F + PIXELS)
{
if ((bits == 0) && (digits == 0))
{
*(t++) = '0';
*(t++) = 'x';
}
if (compface_xbitmap) {
if (*(s++))
i = (i >> 1) | 0x8;
else
i >>= 1;
}
else {
if (*(s++))
i = i * 2 + 1;
else
i *= 2;
}
if (++bits == BITSPERDIG)
{
if (compface_xbitmap) {
t++;
t[-(digits & 1) * 2] = *(i + HexDigits);
}
else *(t++) = *(i + HexDigits);
bits = i = 0;
if (++digits == digsperword)
{
if (compface_xbitmap && (s >= F + PIXELS))
break;
*(t++) = ',';
digits = 0;
if (++words == wordsperline)
{
*(t++) = '\n';
if (compface_xbitmap) *(t++) = ' ';
words = 0;
}
}
}
}
if (compface_xbitmap) {
sprintf(t, "};\n");
while (*t) t++;
}
*(t++) = '\0';
}
|