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*/ )
33 np = 1 << (MAX_DICBIT - 7);
36 np = 1 << (MAX_DICBIT - 6);
41 /* ------------------------------------------------------------------------ */
49 putcode(pt_len[i], pt_code[i]);
53 /* ------------------------------------------------------------------------ */
59 unsigned int code, weight;
64 weight = 1 << (16 - j);
66 for (i = 0; i < np; i++) {
78 /* ------------------------------------------------------------------------ */
81 encode_start_fix( /*void*/ )
92 /* ------------------------------------------------------------------------ */
94 read_tree_c( /*void*/ )
95 { /* read tree from file */
101 c_len[i] = getbits(LENFIELD) + 1;
104 if (++i == 3 && c_len[0] == 1 && c_len[1] == 1 && c_len[2] == 1) {
106 for (i = 0; i < N1; i++)
108 for (i = 0; i < 4096; i++)
113 make_table(N1, c_len, 12, c_table);
116 /* ------------------------------------------------------------------------ */
118 read_tree_p(/*void*/)
119 { /* read tree from file */
124 pt_len[i] = getbits(LENFIELD);
125 if (++i == 3 && pt_len[0] == 1 && pt_len[1] == 1 && pt_len[2] == 1) {
126 c = getbits(LZHUFF3_DICBIT - 6);
127 for (i = 0; i < NP; i++)
129 for (i = 0; i < 256; i++)
136 /* ------------------------------------------------------------------------ */
139 decode_start_fix(/*void*/)
145 np = 1 << (LZHUFF1_DICBIT - 6);
148 make_table(np, pt_len, 8, pt_table);
151 /* ------------------------------------------------------------------------ */
154 decode_c_st0(/*void*/)
157 static unsigned short blocksize = 0;
159 if (blocksize == 0) { /* read block head */
160 blocksize = getbits(BUFBITS); /* read block blocksize */
168 make_table(NP, pt_len, 8, pt_table);
171 j = c_table[peekbits(12)];
184 fillbuf(c_len[j] - 12);
187 j += getbits(EXTRABITS);
191 /* ------------------------------------------------------------------------ */
194 decode_p_st0(/*void*/)
198 j = pt_table[peekbits(8)];
212 fillbuf(pt_len[j] - 8);
214 return (j << 6) + getbits(6);