"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "viewfax-2.6/faxinit.c" of archive viewfax-2.6.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 /* Initialise fax decoder tables
2 Copyright (C) 1990, 1995 Frank D. Cringle.
3
4 This file is part of viewfax - g3/g4 fax processing software.
5
6 viewfax is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include <sys/types.h>
21 #include "faxexpand.h"
22
23 struct tabent MainTable[128];
24 struct tabent WhiteTable[4096];
25 struct tabent BlackTable[8192];
26
27 struct proto {
28 t16bits code; /* right justified, lsb-first, zero filled */
29 t16bits val; /* (pixel count)<<4 + code width */
30 };
31
32 static struct proto Pass[] = {
33 { 0x0008, 4 },
34 { 0, 0 }
35 };
36
37 static struct proto Horiz[] = {
38 { 0x0004, 3 },
39 { 0, 0 }
40 };
41
42 static struct proto V0[] = {
43 { 0x0001, 1 },
44 { 0, 0 }
45 };
46
47 static struct proto VR[] = {
48 { 0x0006, (1<<4)+3 },
49 { 0x0030, (2<<4)+6 },
50 { 0x0060, (3<<4)+7 },
51 { 0, 0 }
52 };
53
54 static struct proto VL[] = {
55 { 0x0002, (1<<4)+3 },
56 { 0x0010, (2<<4)+6 },
57 { 0x0020, (3<<4)+7 },
58 { 0, 0 }
59 };
60
61 static struct proto ExtV[] = {
62 { 0x0040, 7 },
63 { 0, 0 }
64 };
65
66 static struct proto EOLV[] = {
67 { 0x0000, 7 },
68 { 0, 0 }
69 };
70
71 static struct proto MakeUpW[] = {
72 { 0x001b, 1029 },
73 { 0x0009, 2053 },
74 { 0x003a, 3078 },
75 { 0x0076, 4103 },
76 { 0x006c, 5128 },
77 { 0x00ec, 6152 },
78 { 0x0026, 7176 },
79 { 0x00a6, 8200 },
80 { 0x0016, 9224 },
81 { 0x00e6, 10248 },
82 { 0x0066, 11273 },
83 { 0x0166, 12297 },
84 { 0x0096, 13321 },
85 { 0x0196, 14345 },
86 { 0x0056, 15369 },
87 { 0x0156, 16393 },
88 { 0x00d6, 17417 },
89 { 0x01d6, 18441 },
90 { 0x0036, 19465 },
91 { 0x0136, 20489 },
92 { 0x00b6, 21513 },
93 { 0x01b6, 22537 },
94 { 0x0032, 23561 },
95 { 0x0132, 24585 },
96 { 0x00b2, 25609 },
97 { 0x0006, 26630 },
98 { 0x01b2, 27657 },
99 { 0, 0 }
100 };
101
102 static struct proto MakeUpB[] = {
103 { 0x03c0, 1034 },
104 { 0x0130, 2060 },
105 { 0x0930, 3084 },
106 { 0x0da0, 4108 },
107 { 0x0cc0, 5132 },
108 { 0x02c0, 6156 },
109 { 0x0ac0, 7180 },
110 { 0x06c0, 8205 },
111 { 0x16c0, 9229 },
112 { 0x0a40, 10253 },
113 { 0x1a40, 11277 },
114 { 0x0640, 12301 },
115 { 0x1640, 13325 },
116 { 0x09c0, 14349 },
117 { 0x19c0, 15373 },
118 { 0x05c0, 16397 },
119 { 0x15c0, 17421 },
120 { 0x0dc0, 18445 },
121 { 0x1dc0, 19469 },
122 { 0x0940, 20493 },
123 { 0x1940, 21517 },
124 { 0x0540, 22541 },
125 { 0x1540, 23565 },
126 { 0x0b40, 24589 },
127 { 0x1b40, 25613 },
128 { 0x04c0, 26637 },
129 { 0x14c0, 27661 },
130 { 0, 0 }
131 };
132
133 static struct proto MakeUp[] = {
134 { 0x0080, 28683 },
135 { 0x0180, 29707 },
136 { 0x0580, 30731 },
137 { 0x0480, 31756 },
138 { 0x0c80, 32780 },
139 { 0x0280, 33804 },
140 { 0x0a80, 34828 },
141 { 0x0680, 35852 },
142 { 0x0e80, 36876 },
143 { 0x0380, 37900 },
144 { 0x0b80, 38924 },
145 { 0x0780, 39948 },
146 { 0x0f80, 40972 },
147 { 0, 0 }
148 };
149
150 static struct proto TermW[] = {
151 { 0x00ac, 8 },
152 { 0x0038, 22 },
153 { 0x000e, 36 },
154 { 0x0001, 52 },
155 { 0x000d, 68 },
156 { 0x0003, 84 },
157 { 0x0007, 100 },
158 { 0x000f, 116 },
159 { 0x0019, 133 },
160 { 0x0005, 149 },
161 { 0x001c, 165 },
162 { 0x0002, 181 },
163 { 0x0004, 198 },
164 { 0x0030, 214 },
165 { 0x000b, 230 },
166 { 0x002b, 246 },
167 { 0x0015, 262 },
168 { 0x0035, 278 },
169 { 0x0072, 295 },
170 { 0x0018, 311 },
171 { 0x0008, 327 },
172 { 0x0074, 343 },
173 { 0x0060, 359 },
174 { 0x0010, 375 },
175 { 0x000a, 391 },
176 { 0x006a, 407 },
177 { 0x0064, 423 },
178 { 0x0012, 439 },
179 { 0x000c, 455 },
180 { 0x0040, 472 },
181 { 0x00c0, 488 },
182 { 0x0058, 504 },
183 { 0x00d8, 520 },
184 { 0x0048, 536 },
185 { 0x00c8, 552 },
186 { 0x0028, 568 },
187 { 0x00a8, 584 },
188 { 0x0068, 600 },
189 { 0x00e8, 616 },
190 { 0x0014, 632 },
191 { 0x0094, 648 },
192 { 0x0054, 664 },
193 { 0x00d4, 680 },
194 { 0x0034, 696 },
195 { 0x00b4, 712 },
196 { 0x0020, 728 },
197 { 0x00a0, 744 },
198 { 0x0050, 760 },
199 { 0x00d0, 776 },
200 { 0x004a, 792 },
201 { 0x00ca, 808 },
202 { 0x002a, 824 },
203 { 0x00aa, 840 },
204 { 0x0024, 856 },
205 { 0x00a4, 872 },
206 { 0x001a, 888 },
207 { 0x009a, 904 },
208 { 0x005a, 920 },
209 { 0x00da, 936 },
210 { 0x0052, 952 },
211 { 0x00d2, 968 },
212 { 0x004c, 984 },
213 { 0x00cc, 1000 },
214 { 0x002c, 1016 },
215 { 0, 0 }
216 };
217
218 static struct proto TermB[] = {
219 { 0x03b0, 10 },
220 { 0x0002, 19 },
221 { 0x0003, 34 },
222 { 0x0001, 50 },
223 { 0x0006, 67 },
224 { 0x000c, 84 },
225 { 0x0004, 100 },
226 { 0x0018, 117 },
227 { 0x0028, 134 },
228 { 0x0008, 150 },
229 { 0x0010, 167 },
230 { 0x0050, 183 },
231 { 0x0070, 199 },
232 { 0x0020, 216 },
233 { 0x00e0, 232 },
234 { 0x0030, 249 },
235 { 0x03a0, 266 },
236 { 0x0060, 282 },
237 { 0x0040, 298 },
238 { 0x0730, 315 },
239 { 0x00b0, 331 },
240 { 0x01b0, 347 },
241 { 0x0760, 363 },
242 { 0x00a0, 379 },
243 { 0x0740, 395 },
244 { 0x00c0, 411 },
245 { 0x0530, 428 },
246 { 0x0d30, 444 },
247 { 0x0330, 460 },
248 { 0x0b30, 476 },
249 { 0x0160, 492 },
250 { 0x0960, 508 },
251 { 0x0560, 524 },
252 { 0x0d60, 540 },
253 { 0x04b0, 556 },
254 { 0x0cb0, 572 },
255 { 0x02b0, 588 },
256 { 0x0ab0, 604 },
257 { 0x06b0, 620 },
258 { 0x0eb0, 636 },
259 { 0x0360, 652 },
260 { 0x0b60, 668 },
261 { 0x05b0, 684 },
262 { 0x0db0, 700 },
263 { 0x02a0, 716 },
264 { 0x0aa0, 732 },
265 { 0x06a0, 748 },
266 { 0x0ea0, 764 },
267 { 0x0260, 780 },
268 { 0x0a60, 796 },
269 { 0x04a0, 812 },
270 { 0x0ca0, 828 },
271 { 0x0240, 844 },
272 { 0x0ec0, 860 },
273 { 0x01c0, 876 },
274 { 0x0e40, 892 },
275 { 0x0140, 908 },
276 { 0x01a0, 924 },
277 { 0x09a0, 940 },
278 { 0x0d40, 956 },
279 { 0x0340, 972 },
280 { 0x05a0, 988 },
281 { 0x0660, 1004 },
282 { 0x0e60, 1020 },
283 { 0, 0 }
284 };
285
286 static struct proto ExtH[] = {
287 { 0x0100, 9 },
288 { 0, 0 }
289 };
290
291 static struct proto EOLH[] = {
292 { 0x0000, 11 },
293 { 0, 0 }
294 };
295
296 static void
297 FillTable(struct tabent *T, int Size, struct proto *P, int State)
298 {
299 int limit = 1 << Size;
300
301 while (P->val) {
302 int width = P->val & 15;
303 int param = P->val >> 4;
304 int incr = 1 << width;
305 int code;
306 for (code = P->code; code < limit; code += incr) {
307 struct tabent *E = T+code;
308 E->State = State;
309 E->Width = width;
310 E->Param = param;
311 }
312 P++;
313 }
314 }
315
316 /* initialise the huffman code tables */
317 void
318 faxinit(void)
319 {
320 FillTable(MainTable, 7, Pass, S_Pass);
321 FillTable(MainTable, 7, Horiz, S_Horiz);
322 FillTable(MainTable, 7, V0, S_V0);
323 FillTable(MainTable, 7, VR, S_VR);
324 FillTable(MainTable, 7, VL, S_VL);
325 FillTable(MainTable, 7, ExtV, S_Ext);
326 FillTable(MainTable, 7, EOLV, S_EOL);
327 FillTable(WhiteTable, 12, MakeUpW, S_MakeUpW);
328 FillTable(WhiteTable, 12, MakeUp, S_MakeUp);
329 FillTable(WhiteTable, 12, TermW, S_TermW);
330 FillTable(WhiteTable, 12, ExtH, S_Ext);
331 FillTable(WhiteTable, 12, EOLH, S_EOL);
332 FillTable(BlackTable, 13, MakeUpB, S_MakeUpB);
333 FillTable(BlackTable, 13, MakeUp, S_MakeUp);
334 FillTable(BlackTable, 13, TermB, S_TermB);
335 FillTable(BlackTable, 13, ExtH, S_Ext);
336 FillTable(BlackTable, 13, EOLH, S_EOL);
337 }