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 /* ------------------------------------------------------------------------ */
25 decode_start_st0( /*void*/ )
32 np = 1 << (MAX_DICBIT - 7);
35 np = 1 << (MAX_DICBIT - 6);
40 /* ------------------------------------------------------------------------ */
48 putcode(pt_len[i], pt_code[i]);
52 /* ------------------------------------------------------------------------ */
58 unsigned int code, weight;
63 weight = 1 << (16 - j);
65 for (i = 0; i < np; i++) {
77 /* ------------------------------------------------------------------------ */
79 encode_start_fix( /*void*/ )
90 /* ------------------------------------------------------------------------ */
92 read_tree_c( /*void*/ )
93 { /* read tree from file */
99 c_len[i] = getbits(LENFIELD) + 1;
102 if (++i == 3 && c_len[0] == 1 && c_len[1] == 1 && c_len[2] == 1) {
104 for (i = 0; i < N1; i++)
106 for (i = 0; i < 4096; i++)
111 make_table(N1, c_len, 12, c_table);
114 /* ------------------------------------------------------------------------ */
116 read_tree_p(/*void*/)
117 { /* read tree from file */
122 pt_len[i] = getbits(LENFIELD);
123 if (++i == 3 && pt_len[0] == 1 && pt_len[1] == 1 && pt_len[2] == 1) {
124 c = getbits(LZHUFF3_DICBIT - 6);
125 for (i = 0; i < NP; i++)
127 for (i = 0; i < 256; i++)
134 /* ------------------------------------------------------------------------ */
136 decode_start_fix(/*void*/)
142 np = 1 << (LZHUFF1_DICBIT - 6);
145 make_table(np, pt_len, 8, pt_table);
148 /* ------------------------------------------------------------------------ */
150 decode_c_st0(/*void*/)
153 static unsigned short blocksize = 0;
155 if (blocksize == 0) { /* read block head */
156 blocksize = getbits(BUFBITS); /* read block blocksize */
164 make_table(NP, pt_len, 8, pt_table);
167 j = c_table[bitbuf >> 4];
180 fillbuf(c_len[j] - 12);
183 j += getbits(EXTRABITS);
187 /* ------------------------------------------------------------------------ */
189 decode_p_st0(/*void*/)
193 j = pt_table[bitbuf >> 8];
207 fillbuf(pt_len[j] - 8);
209 return (j << 6) + getbits(6);
212 /* Local Variables: */
216 /* vi: set tabstop=4: */