1 /* ------------------------------------------------------------------------ */
3 /* shuf.c -- extract static Huffman coding */
5 /* Modified Nobutaka Watazaki */
7 /* Ver. 1.14 Source All chagned 1995.01.14 N.Watazaki */
8 /* ------------------------------------------------------------------------ */
11 /* ------------------------------------------------------------------------ */
15 #define NP (8 * 1024 / 64)
16 #define NP2 (NP * 2 - 1)
17 /* ------------------------------------------------------------------------ */
18 static unsigned int np;
20 {3, 0x01, 0x04, 0x0c, 0x18, 0x30, 0}, /* old compatible */
21 {2, 0x01, 0x01, 0x03, 0x06, 0x0D, 0x1F, 0x4E, 0} /* 8K buf */
23 /* ------------------------------------------------------------------------ */
26 decode_start_st0( /*void*/ )
32 np = 1 << (LZHUFF3_DICBIT - 6);
35 /* ------------------------------------------------------------------------ */
43 putcode(pt_len[i], pt_code[i]);
47 /* ------------------------------------------------------------------------ */
53 unsigned int code, weight;
58 weight = 1 << (16 - j);
60 for (i = 0; i < np; i++) {
72 /* ------------------------------------------------------------------------ */
75 encode_start_fix( /*void*/ )
86 /* ------------------------------------------------------------------------ */
88 read_tree_c( /*void*/ )
89 { /* read tree from file */
95 c_len[i] = getbits(LENFIELD) + 1;
98 if (++i == 3 && c_len[0] == 1 && c_len[1] == 1 && c_len[2] == 1) {
100 for (i = 0; i < N1; i++)
102 for (i = 0; i < 4096; i++)
107 make_table(N1, c_len, 12, c_table);
110 /* ------------------------------------------------------------------------ */
112 read_tree_p(/*void*/)
113 { /* read tree from file */
118 pt_len[i] = getbits(LENFIELD);
119 if (++i == 3 && pt_len[0] == 1 && pt_len[1] == 1 && pt_len[2] == 1) {
120 c = getbits(LZHUFF3_DICBIT - 6);
121 for (i = 0; i < NP; i++)
123 for (i = 0; i < 256; i++)
130 /* ------------------------------------------------------------------------ */
133 decode_start_fix(/*void*/)
139 np = 1 << (LZHUFF1_DICBIT - 6);
142 make_table(np, pt_len, 8, pt_table);
145 /* ------------------------------------------------------------------------ */
148 decode_c_st0(/*void*/)
151 static unsigned short blocksize = 0;
153 if (blocksize == 0) { /* read block head */
154 blocksize = getbits(BUFBITS); /* read block blocksize */
162 make_table(NP, pt_len, 8, pt_table);
165 j = c_table[peekbits(12)];
178 fillbuf(c_len[j] - 12);
181 j += getbits(EXTRABITS);
185 /* ------------------------------------------------------------------------ */
188 decode_p_st0(/*void*/)
192 j = pt_table[peekbits(8)];
206 fillbuf(pt_len[j] - 8);
208 return (j << 6) + getbits(6);