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*/ )
31 np = 1 << (MAX_DICBIT - 7);
34 np = 1 << (MAX_DICBIT - 6);
39 /* ------------------------------------------------------------------------ */
47 putcode(pt_len[i], pt_code[i]);
51 /* ------------------------------------------------------------------------ */
57 unsigned int code, weight;
62 weight = 1 << (16 - j);
64 for (i = 0; i < np; i++) {
76 /* ------------------------------------------------------------------------ */
78 encode_start_fix( /*void*/ )
88 /* ------------------------------------------------------------------------ */
90 read_tree_c( /*void*/ )
91 { /* read tree from file */
97 c_len[i] = getbits(LENFIELD) + 1;
100 if (++i == 3 && c_len[0] == 1 && c_len[1] == 1 && c_len[2] == 1) {
102 for (i = 0; i < N1; i++)
104 for (i = 0; i < 4096; i++)
109 make_table(N1, c_len, 12, c_table);
112 /* ------------------------------------------------------------------------ */
114 read_tree_p(/*void*/)
115 { /* read tree from file */
120 pt_len[i] = getbits(LENFIELD);
121 if (++i == 3 && pt_len[0] == 1 && pt_len[1] == 1 && pt_len[2] == 1) {
123 c = getbits(MAX_DICBIT - 7);
125 c = getbits(MAX_DICBIT - 6);
127 for (i = 0; i < NP; i++)
129 for (i = 0; i < 256; i++)
136 /* ------------------------------------------------------------------------ */
138 decode_start_fix(/*void*/)
146 make_table(np, pt_len, 8, pt_table);
149 /* ------------------------------------------------------------------------ */
151 decode_c_st0(/*void*/)
154 static unsigned short blocksize = 0;
156 if (blocksize == 0) { /* read block head */
157 blocksize = getbits(BUFBITS); /* read block blocksize */
165 make_table(NP, pt_len, 8, pt_table);
168 j = c_table[bitbuf >> 4];
181 fillbuf(c_len[j] - 12);
184 j += getbits(EXTRABITS);
188 /* ------------------------------------------------------------------------ */
190 decode_p_st0(/*void*/)
194 j = pt_table[bitbuf >> 8];
208 fillbuf(pt_len[j] - 8);
210 return (j << 6) + getbits(6);
213 /* Local Variables: */