1
/* #ident "@(#)g3.c 3.1 95/08/30 Copyright (c) Gert Doering" */
10
#include <sys/types.h>
15
struct g3code t_white[66] = {
80
{ 0, -1, 0, 11 }, /* 11 0-bits == EOL, special handling */
81
{ 0, -1, 0, 0 }}; /* end of table */
83
/* make-up codes white */
84
struct g3code m_white[28] = {
100
{ 0,1024, 0x156, 9 },
101
{ 0,1088, 0x0d6, 9 },
102
{ 0,1152, 0x1d6, 9 },
103
{ 0,1216, 0x036, 9 },
104
{ 0,1280, 0x136, 9 },
105
{ 0,1344, 0x0b6, 9 },
106
{ 0,1408, 0x1b6, 9 },
107
{ 0,1472, 0x032, 9 },
108
{ 0,1536, 0x132, 9 },
109
{ 0,1600, 0x0b2, 9 },
110
{ 0,1664, 0x006, 6 },
111
{ 0,1728, 0x1b2, 9 },
115
struct g3code t_black[66] = {
132
{ 0, 16, 0x3a0, 10 },
133
{ 0, 17, 0x060, 10 },
134
{ 0, 18, 0x040, 10 },
135
{ 0, 19, 0x730, 11 },
136
{ 0, 20, 0x0b0, 11 },
137
{ 0, 21, 0x1b0, 11 },
138
{ 0, 22, 0x760, 11 },
139
{ 0, 23, 0x0a0, 11 },
140
{ 0, 24, 0x740, 11 },
141
{ 0, 25, 0x0c0, 11 },
142
{ 0, 26, 0x530, 12 },
143
{ 0, 27, 0xd30, 12 },
144
{ 0, 28, 0x330, 12 },
145
{ 0, 29, 0xb30, 12 },
146
{ 0, 30, 0x160, 12 },
147
{ 0, 31, 0x960, 12 },
148
{ 0, 32, 0x560, 12 },
149
{ 0, 33, 0xd60, 12 },
150
{ 0, 34, 0x4b0, 12 },
151
{ 0, 35, 0xcb0, 12 },
152
{ 0, 36, 0x2b0, 12 },
153
{ 0, 37, 0xab0, 12 },
154
{ 0, 38, 0x6b0, 12 },
155
{ 0, 39, 0xeb0, 12 },
156
{ 0, 40, 0x360, 12 },
157
{ 0, 41, 0xb60, 12 },
158
{ 0, 42, 0x5b0, 12 },
159
{ 0, 43, 0xdb0, 12 },
160
{ 0, 44, 0x2a0, 12 },
161
{ 0, 45, 0xaa0, 12 },
162
{ 0, 46, 0x6a0, 12 },
163
{ 0, 47, 0xea0, 12 },
164
{ 0, 48, 0x260, 12 },
165
{ 0, 49, 0xa60, 12 },
166
{ 0, 50, 0x4a0, 12 },
167
{ 0, 51, 0xca0, 12 },
168
{ 0, 52, 0x240, 12 },
169
{ 0, 53, 0xec0, 12 },
170
{ 0, 54, 0x1c0, 12 },
171
{ 0, 55, 0xe40, 12 },
172
{ 0, 56, 0x140, 12 },
173
{ 0, 57, 0x1a0, 12 },
174
{ 0, 58, 0x9a0, 12 },
175
{ 0, 59, 0xd40, 12 },
176
{ 0, 60, 0x340, 12 },
177
{ 0, 61, 0x5a0, 12 },
178
{ 0, 62, 0x660, 12 },
179
{ 0, 63, 0xe60, 12 },
180
{ 0, -1, 0x000, 11 },
183
struct g3code m_black[28] = {
184
{ 0, 64, 0x3c0, 10 },
185
{ 0, 128, 0x130, 12 },
186
{ 0, 192, 0x930, 12 },
187
{ 0, 256, 0xda0, 12 },
188
{ 0, 320, 0xcc0, 12 },
189
{ 0, 384, 0x2c0, 12 },
190
{ 0, 448, 0xac0, 12 },
191
{ 0, 512, 0x6c0, 13 },
192
{ 0, 576,0x16c0, 13 },
193
{ 0, 640, 0xa40, 13 },
194
{ 0, 704,0x1a40, 13 },
195
{ 0, 768, 0x640, 13 },
196
{ 0, 832,0x1640, 13 },
197
{ 0, 896, 0x9c0, 13 },
198
{ 0, 960,0x19c0, 13 },
199
{ 0,1024, 0x5c0, 13 },
200
{ 0,1088,0x15c0, 13 },
201
{ 0,1152, 0xdc0, 13 },
202
{ 0,1216,0x1dc0, 13 },
203
{ 0,1280, 0x940, 13 },
204
{ 0,1344,0x1940, 13 },
205
{ 0,1408, 0x540, 13 },
206
{ 0,1472,0x1540, 13 },
207
{ 0,1536, 0xb40, 13 },
208
{ 0,1600,0x1b40, 13 },
209
{ 0,1664, 0x4c0, 13 },
210
{ 0,1728,0x14c0, 13 },
213
void tree_add_node( struct g3_tree *p, struct g3code * g3c,
214
int bit_code, int bit_length )
218
if ( bit_length <= FBITS ) /* leaf (multiple bits) */
220
g3c->nr_bits = bit_length; /* leaf tag */
222
if ( bit_length == FBITS ) /* full width */
224
p->nextb[ bit_code ] = (struct g3_tree *) g3c;
227
for ( i=0; i< ( 1 << (FBITS-bit_length)); i++ )
229
p->nextb[ bit_code + ( i << bit_length ) ] = (struct g3_tree *) g3c;
236
p2 = p->nextb[ bit_code & BITM ];
237
if ( p2 == 0 ) /* no sub-node exists */
239
p2 = p->nextb[ bit_code & BITM ] =
240
( struct g3_tree * ) calloc( 1, sizeof( struct g3_tree ));
241
if ( p2 == NULL ) { perror( "malloc 3" ); exit(11); }
242
p2->nr_bits = 0; /* node tag */
245
if ( p2->nr_bits != 0 )
247
fprintf( stderr, "internal table setup error\n" ); exit(6);
249
tree_add_node( p2, g3c, bit_code >> FBITS, bit_length - FBITS );
253
void build_tree (struct g3_tree ** p, struct g3code * c )
257
(*p) = (struct g3_tree *) calloc( 1, sizeof(struct g3_tree) );
258
if ( *p == NULL ) { perror( "malloc(1)" ); exit(10); }
263
while ( c->bit_length != 0 )
265
tree_add_node( *p, c, c->bit_code, c->bit_length );
270
void init_byte_tab (int reverse, int byte_tab[] )
273
if ( reverse ) for ( i=0; i<256; i++ ) byte_tab[i] = i;
275
for ( i=0; i<256; i++ )
276
byte_tab[i] = ( ((i & 0x01) << 7) | ((i & 0x02) << 5) |
277
((i & 0x04) << 3) | ((i & 0x08) << 1) |
278
((i & 0x10) >> 1) | ((i & 0x20) >> 3) |
279
((i & 0x40) >> 5) | ((i & 0x80) >> 7) );