comparison src/com/jcraft/jzlib/InfTree.java @ 357:46c2115ae1c8

update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
author Carl Byington <carl@five-ten-sg.com>
date Fri, 01 Aug 2014 13:34:58 -0700
parents 0ce5cc452d02
children
comparison
equal deleted inserted replaced
356:5e91b559b5fe 357:46c2115ae1c8
6 modification, are permitted provided that the following conditions are met: 6 modification, are permitted provided that the following conditions are met:
7 7
8 1. Redistributions of source code must retain the above copyright notice, 8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
10 10
11 2. Redistributions in binary form must reproduce the above copyright 11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in 12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the distribution. 13 the documentation and/or other materials provided with the distribution.
14 14
15 3. The names of the authors may not be used to endorse or promote products 15 3. The names of the authors may not be used to endorse or promote products
16 derived from this software without specific prior written permission. 16 derived from this software without specific prior written permission.
17 17
32 * and contributors of zlib. 32 * and contributors of zlib.
33 */ 33 */
34 34
35 package com.jcraft.jzlib; 35 package com.jcraft.jzlib;
36 36
37 final class InfTree { 37 final class InfTree{
38 38
39 static final private int MANY = 1440; 39 static final private int MANY=1440;
40 40
41 static final private int Z_OK = 0; 41 static final private int Z_OK=0;
42 static final private int Z_STREAM_END = 1; 42 static final private int Z_STREAM_END=1;
43 static final private int Z_NEED_DICT = 2; 43 static final private int Z_NEED_DICT=2;
44 static final private int Z_ERRNO = -1; 44 static final private int Z_ERRNO=-1;
45 static final private int Z_STREAM_ERROR = -2; 45 static final private int Z_STREAM_ERROR=-2;
46 static final private int Z_DATA_ERROR = -3; 46 static final private int Z_DATA_ERROR=-3;
47 static final private int Z_MEM_ERROR = -4; 47 static final private int Z_MEM_ERROR=-4;
48 static final private int Z_BUF_ERROR = -5; 48 static final private int Z_BUF_ERROR=-5;
49 static final private int Z_VERSION_ERROR = -6; 49 static final private int Z_VERSION_ERROR=-6;
50 50
51 static final int fixed_bl = 9; 51 static final int fixed_bl = 9;
52 static final int fixed_bd = 5; 52 static final int fixed_bd = 5;
53 53
54 static final int[] fixed_tl = { 54 static final int[] fixed_tl = {
55 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 55 96,7,256, 0,8,80, 0,8,16, 84,8,115,
56 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 56 82,7,31, 0,8,112, 0,8,48, 0,9,192,
57 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 57 80,7,10, 0,8,96, 0,8,32, 0,9,160,
58 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 224, 58 0,8,0, 0,8,128, 0,8,64, 0,9,224,
59 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 59 80,7,6, 0,8,88, 0,8,24, 0,9,144,
60 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 60 83,7,59, 0,8,120, 0,8,56, 0,9,208,
61 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 176, 61 81,7,17, 0,8,104, 0,8,40, 0,9,176,
62 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 62 0,8,8, 0,8,136, 0,8,72, 0,9,240,
63 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 63 80,7,4, 0,8,84, 0,8,20, 85,8,227,
64 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 64 83,7,43, 0,8,116, 0,8,52, 0,9,200,
65 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 168, 65 81,7,13, 0,8,100, 0,8,36, 0,9,168,
66 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 66 0,8,4, 0,8,132, 0,8,68, 0,9,232,
67 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 67 80,7,8, 0,8,92, 0,8,28, 0,9,152,
68 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 216, 68 84,7,83, 0,8,124, 0,8,60, 0,9,216,
69 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 69 82,7,23, 0,8,108, 0,8,44, 0,9,184,
70 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 70 0,8,12, 0,8,140, 0,8,76, 0,9,248,
71 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 71 80,7,3, 0,8,82, 0,8,18, 85,8,163,
72 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 72 83,7,35, 0,8,114, 0,8,50, 0,9,196,
73 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 73 81,7,11, 0,8,98, 0,8,34, 0,9,164,
74 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 74 0,8,2, 0,8,130, 0,8,66, 0,9,228,
75 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 148, 75 80,7,7, 0,8,90, 0,8,26, 0,9,148,
76 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 76 84,7,67, 0,8,122, 0,8,58, 0,9,212,
77 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 77 82,7,19, 0,8,106, 0,8,42, 0,9,180,
78 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 78 0,8,10, 0,8,138, 0,8,74, 0,9,244,
79 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 79 80,7,5, 0,8,86, 0,8,22, 192,8,0,
80 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 80 83,7,51, 0,8,118, 0,8,54, 0,9,204,
81 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 81 81,7,15, 0,8,102, 0,8,38, 0,9,172,
82 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 236, 82 0,8,6, 0,8,134, 0,8,70, 0,9,236,
83 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 83 80,7,9, 0,8,94, 0,8,30, 0,9,156,
84 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 84 84,7,99, 0,8,126, 0,8,62, 0,9,220,
85 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 85 82,7,27, 0,8,110, 0,8,46, 0,9,188,
86 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 86 0,8,14, 0,8,142, 0,8,78, 0,9,252,
87 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 87 96,7,256, 0,8,81, 0,8,17, 85,8,131,
88 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 88 82,7,31, 0,8,113, 0,8,49, 0,9,194,
89 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 162, 89 80,7,10, 0,8,97, 0,8,33, 0,9,162,
90 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 90 0,8,1, 0,8,129, 0,8,65, 0,9,226,
91 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 91 80,7,6, 0,8,89, 0,8,25, 0,9,146,
92 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210, 92 83,7,59, 0,8,121, 0,8,57, 0,9,210,
93 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 93 81,7,17, 0,8,105, 0,8,41, 0,9,178,
94 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 94 0,8,9, 0,8,137, 0,8,73, 0,9,242,
95 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 95 80,7,4, 0,8,85, 0,8,21, 80,8,258,
96 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 202, 96 83,7,43, 0,8,117, 0,8,53, 0,9,202,
97 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 97 81,7,13, 0,8,101, 0,8,37, 0,9,170,
98 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 98 0,8,5, 0,8,133, 0,8,69, 0,9,234,
99 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154, 99 80,7,8, 0,8,93, 0,8,29, 0,9,154,
100 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 100 84,7,83, 0,8,125, 0,8,61, 0,9,218,
101 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 101 82,7,23, 0,8,109, 0,8,45, 0,9,186,
102 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 102 0,8,13, 0,8,141, 0,8,77, 0,9,250,
103 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 103 80,7,3, 0,8,83, 0,8,19, 85,8,195,
104 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 104 83,7,35, 0,8,115, 0,8,51, 0,9,198,
105 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 105 81,7,11, 0,8,99, 0,8,35, 0,9,166,
106 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230, 106 0,8,3, 0,8,131, 0,8,67, 0,9,230,
107 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 107 80,7,7, 0,8,91, 0,8,27, 0,9,150,
108 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 108 84,7,67, 0,8,123, 0,8,59, 0,9,214,
109 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 109 82,7,19, 0,8,107, 0,8,43, 0,9,182,
110 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 246, 110 0,8,11, 0,8,139, 0,8,75, 0,9,246,
111 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 111 80,7,5, 0,8,87, 0,8,23, 192,8,0,
112 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 112 83,7,51, 0,8,119, 0,8,55, 0,9,206,
113 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174, 113 81,7,15, 0,8,103, 0,8,39, 0,9,174,
114 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 114 0,8,7, 0,8,135, 0,8,71, 0,9,238,
115 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 115 80,7,9, 0,8,95, 0,8,31, 0,9,158,
116 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 116 84,7,99, 0,8,127, 0,8,63, 0,9,222,
117 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 190, 117 82,7,27, 0,8,111, 0,8,47, 0,9,190,
118 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 118 0,8,15, 0,8,143, 0,8,79, 0,9,254,
119 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 119 96,7,256, 0,8,80, 0,8,16, 84,8,115,
120 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 193, 120 82,7,31, 0,8,112, 0,8,48, 0,9,193,
121 121
122 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 122 80,7,10, 0,8,96, 0,8,32, 0,9,161,
123 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 123 0,8,0, 0,8,128, 0,8,64, 0,9,225,
124 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 124 80,7,6, 0,8,88, 0,8,24, 0,9,145,
125 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 209, 125 83,7,59, 0,8,120, 0,8,56, 0,9,209,
126 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 126 81,7,17, 0,8,104, 0,8,40, 0,9,177,
127 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 127 0,8,8, 0,8,136, 0,8,72, 0,9,241,
128 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 128 80,7,4, 0,8,84, 0,8,20, 85,8,227,
129 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 129 83,7,43, 0,8,116, 0,8,52, 0,9,201,
130 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 130 81,7,13, 0,8,100, 0,8,36, 0,9,169,
131 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 131 0,8,4, 0,8,132, 0,8,68, 0,9,233,
132 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 153, 132 80,7,8, 0,8,92, 0,8,28, 0,9,153,
133 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 133 84,7,83, 0,8,124, 0,8,60, 0,9,217,
134 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 134 82,7,23, 0,8,108, 0,8,44, 0,9,185,
135 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 249, 135 0,8,12, 0,8,140, 0,8,76, 0,9,249,
136 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 136 80,7,3, 0,8,82, 0,8,18, 85,8,163,
137 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 137 83,7,35, 0,8,114, 0,8,50, 0,9,197,
138 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 138 81,7,11, 0,8,98, 0,8,34, 0,9,165,
139 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 229, 139 0,8,2, 0,8,130, 0,8,66, 0,9,229,
140 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 140 80,7,7, 0,8,90, 0,8,26, 0,9,149,
141 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 141 84,7,67, 0,8,122, 0,8,58, 0,9,213,
142 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 181, 142 82,7,19, 0,8,106, 0,8,42, 0,9,181,
143 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 143 0,8,10, 0,8,138, 0,8,74, 0,9,245,
144 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 144 80,7,5, 0,8,86, 0,8,22, 192,8,0,
145 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 145 83,7,51, 0,8,118, 0,8,54, 0,9,205,
146 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 173, 146 81,7,15, 0,8,102, 0,8,38, 0,9,173,
147 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 147 0,8,6, 0,8,134, 0,8,70, 0,9,237,
148 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 148 80,7,9, 0,8,94, 0,8,30, 0,9,157,
149 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 221, 149 84,7,99, 0,8,126, 0,8,62, 0,9,221,
150 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 150 82,7,27, 0,8,110, 0,8,46, 0,9,189,
151 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 151 0,8,14, 0,8,142, 0,8,78, 0,9,253,
152 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 152 96,7,256, 0,8,81, 0,8,17, 85,8,131,
153 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 195, 153 82,7,31, 0,8,113, 0,8,49, 0,9,195,
154 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 154 80,7,10, 0,8,97, 0,8,33, 0,9,163,
155 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 155 0,8,1, 0,8,129, 0,8,65, 0,9,227,
156 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 147, 156 80,7,6, 0,8,89, 0,8,25, 0,9,147,
157 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 157 83,7,59, 0,8,121, 0,8,57, 0,9,211,
158 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 158 81,7,17, 0,8,105, 0,8,41, 0,9,179,
159 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 159 0,8,9, 0,8,137, 0,8,73, 0,9,243,
160 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 160 80,7,4, 0,8,85, 0,8,21, 80,8,258,
161 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 161 83,7,43, 0,8,117, 0,8,53, 0,9,203,
162 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 162 81,7,13, 0,8,101, 0,8,37, 0,9,171,
163 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 235, 163 0,8,5, 0,8,133, 0,8,69, 0,9,235,
164 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 164 80,7,8, 0,8,93, 0,8,29, 0,9,155,
165 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 165 84,7,83, 0,8,125, 0,8,61, 0,9,219,
166 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 166 82,7,23, 0,8,109, 0,8,45, 0,9,187,
167 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 251, 167 0,8,13, 0,8,141, 0,8,77, 0,9,251,
168 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 168 80,7,3, 0,8,83, 0,8,19, 85,8,195,
169 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 169 83,7,35, 0,8,115, 0,8,51, 0,9,199,
170 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 167, 170 81,7,11, 0,8,99, 0,8,35, 0,9,167,
171 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 171 0,8,3, 0,8,131, 0,8,67, 0,9,231,
172 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 172 80,7,7, 0,8,91, 0,8,27, 0,9,151,
173 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 173 84,7,67, 0,8,123, 0,8,59, 0,9,215,
174 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 183, 174 82,7,19, 0,8,107, 0,8,43, 0,9,183,
175 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 175 0,8,11, 0,8,139, 0,8,75, 0,9,247,
176 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 176 80,7,5, 0,8,87, 0,8,23, 192,8,0,
177 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 207, 177 83,7,51, 0,8,119, 0,8,55, 0,9,207,
178 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 178 81,7,15, 0,8,103, 0,8,39, 0,9,175,
179 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 179 0,8,7, 0,8,135, 0,8,71, 0,9,239,
180 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 180 80,7,9, 0,8,95, 0,8,31, 0,9,159,
181 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 223, 181 84,7,99, 0,8,127, 0,8,63, 0,9,223,
182 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 182 82,7,27, 0,8,111, 0,8,47, 0,9,191,
183 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255 183 0,8,15, 0,8,143, 0,8,79, 0,9,255
184 }; 184 };
185 static final int[] fixed_td = { 185 static final int[] fixed_td = {
186 80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 186 80,5,1, 87,5,257, 83,5,17, 91,5,4097,
187 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 187 81,5,5, 89,5,1025, 85,5,65, 93,5,16385,
188 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5, 8193, 188 80,5,3, 88,5,513, 84,5,33, 92,5,8193,
189 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 189 82,5,9, 90,5,2049, 86,5,129, 192,5,24577,
190 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 190 80,5,2, 87,5,385, 83,5,25, 91,5,6145,
191 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5, 24577, 191 81,5,7, 89,5,1537, 85,5,97, 93,5,24577,
192 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 192 80,5,4, 88,5,769, 84,5,49, 92,5,12289,
193 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577 193 82,5,13, 90,5,3073, 86,5,193, 192,5,24577
194 }; 194 };
195 195
196 // Tables for deflate from PKZIP's appnote.txt. 196 // Tables for deflate from PKZIP's appnote.txt.
197 static final int[] cplens = { // Copy lengths for literal codes 257..285 197 static final int[] cplens = { // Copy lengths for literal codes 257..285
198 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 198 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
199 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 199 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
200 }; 200 };
201 201
202 // see note #13 above about 258 202 // see note #13 above about 258
203 static final int[] cplext = { // Extra bits for literal codes 257..285 203 static final int[] cplext = { // Extra bits for literal codes 257..285
204 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 204 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
205 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid 205 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid
206 }; 206 };
207 207
208 static final int[] cpdist = { // Copy offsets for distance codes 0..29 208 static final int[] cpdist = { // Copy offsets for distance codes 0..29
209 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 209 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
210 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 210 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
211 8193, 12289, 16385, 24577 211 8193, 12289, 16385, 24577
212 }; 212 };
213 213
214 static final int[] cpdext = { // Extra bits for distance codes 214 static final int[] cpdext = { // Extra bits for distance codes
215 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 215 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
216 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 216 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
217 12, 12, 13, 13 217 12, 12, 13, 13};
218 }; 218
219 219 // If BMAX needs to be larger than 16, then h and x[] should be uLong.
220 // If BMAX needs to be larger than 16, then h and x[] should be uLong. 220 static final int BMAX=15; // maximum bit length of any code
221 static final int BMAX = 15; // maximum bit length of any code 221
222 222 int[] hn = null; // hufts used in space
223 int[] hn = null; // hufts used in space 223 int[] v = null; // work area for huft_build
224 int[] v = null; // work area for huft_build 224 int[] c = null; // bit length count table
225 int[] c = null; // bit length count table 225 int[] r = null; // table entry for structure assignment
226 int[] r = null; // table entry for structure assignment 226 int[] u = null; // table stack
227 int[] u = null; // table stack 227 int[] x = null; // bit offsets, then code stack
228 int[] x = null; // bit offsets, then code stack 228
229 229 private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
230 private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX) 230 int bindex,
231 int bindex, 231 int n, // number of codes (assumed <= 288)
232 int n, // number of codes (assumed <= 288) 232 int s, // number of simple-valued codes (0..s-1)
233 int s, // number of simple-valued codes (0..s-1) 233 int[] d, // list of base values for non-simple codes
234 int[] d, // list of base values for non-simple codes 234 int[] e, // list of extra bits for non-simple codes
235 int[] e, // list of extra bits for non-simple codes 235 int[] t, // result: starting table
236 int[] t, // result: starting table 236 int[] m, // maximum lookup bits, returns actual
237 int[] m, // maximum lookup bits, returns actual 237 int[] hp,// space for trees
238 int[] hp,// space for trees 238 int[] hn,// hufts used in space
239 int[] hn,// hufts used in space 239 int[] v // working area: values in order of bit length
240 int[] v // working area: values in order of bit length 240 ){
241 ) { 241 // Given a list of code lengths and a maximum table size, make a set of
242 // Given a list of code lengths and a maximum table size, make a set of 242 // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
243 // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR 243 // if the given code set is incomplete (the tables are still built in this
244 // if the given code set is incomplete (the tables are still built in this 244 // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
245 // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of 245 // lengths), or Z_MEM_ERROR if not enough memory.
246 // lengths), or Z_MEM_ERROR if not enough memory. 246
247 int a; // counter for codes of length k 247 int a; // counter for codes of length k
248 int f; // i repeats in table every f entries 248 int f; // i repeats in table every f entries
249 int g; // maximum code length 249 int g; // maximum code length
250 int h; // table level 250 int h; // table level
251 int i; // counter, current code 251 int i; // counter, current code
252 int j; // counter 252 int j; // counter
253 int k; // number of bits in current code 253 int k; // number of bits in current code
254 int l; // bits per table (returned in m) 254 int l; // bits per table (returned in m)
255 int mask; // (1 << w) - 1, to avoid cc -O bug on HP 255 int mask; // (1 << w) - 1, to avoid cc -O bug on HP
256 int p; // pointer into c[], b[], or v[] 256 int p; // pointer into c[], b[], or v[]
257 int q; // points to current table 257 int q; // points to current table
258 int w; // bits before this table == (l * h) 258 int w; // bits before this table == (l * h)
259 int xp; // pointer into x 259 int xp; // pointer into x
260 int y; // number of dummy codes added 260 int y; // number of dummy codes added
261 int z; // number of entries in current table 261 int z; // number of entries in current table
262 // Generate counts for each bit length 262
263 p = 0; i = n; 263 // Generate counts for each bit length
264 264
265 do { 265 p = 0; i = n;
266 c[b[bindex + p]]++; p++; i--; // assume all entries <= BMAX 266 do {
267 c[b[bindex+p]]++; p++; i--; // assume all entries <= BMAX
268 }while(i!=0);
269
270 if(c[0] == n){ // null input--all zero length codes
271 t[0] = -1;
272 m[0] = 0;
273 return Z_OK;
274 }
275
276 // Find minimum and maximum length, bound *m by those
277 l = m[0];
278 for (j = 1; j <= BMAX; j++)
279 if(c[j]!=0) break;
280 k = j; // minimum code length
281 if(l < j){
282 l = j;
283 }
284 for (i = BMAX; i!=0; i--){
285 if(c[i]!=0) break;
286 }
287 g = i; // maximum code length
288 if(l > i){
289 l = i;
290 }
291 m[0] = l;
292
293 // Adjust last length count to fill out codes, if needed
294 for (y = 1 << j; j < i; j++, y <<= 1){
295 if ((y -= c[j]) < 0){
296 return Z_DATA_ERROR;
297 }
298 }
299 if ((y -= c[i]) < 0){
300 return Z_DATA_ERROR;
301 }
302 c[i] += y;
303
304 // Generate starting offsets into the value table for each length
305 x[1] = j = 0;
306 p = 1; xp = 2;
307 while (--i!=0) { // note that i == g from above
308 x[xp] = (j += c[p]);
309 xp++;
310 p++;
311 }
312
313 // Make a table of values in order of bit lengths
314 i = 0; p = 0;
315 do {
316 if ((j = b[bindex+p]) != 0){
317 v[x[j]++] = i;
318 }
319 p++;
320 }
321 while (++i < n);
322 n = x[g]; // set n to length of v
323
324 // Generate the Huffman codes and for each, make the table entries
325 x[0] = i = 0; // first Huffman code is zero
326 p = 0; // grab values in bit order
327 h = -1; // no tables yet--level -1
328 w = -l; // bits decoded == (l * h)
329 u[0] = 0; // just to keep compilers happy
330 q = 0; // ditto
331 z = 0; // ditto
332
333 // go through the bit lengths (k already is bits in shortest code)
334 for (; k <= g; k++){
335 a = c[k];
336 while (a--!=0){
337 // here i is the Huffman code of length k bits for value *p
338 // make tables up to required level
339 while (k > w + l){
340 h++;
341 w += l; // previous table always l bits
342 // compute minimum size table less than or equal to l bits
343 z = g - w;
344 z = (z > l) ? l : z; // table size upper limit
345 if((f=1<<(j=k-w))>a+1){ // try a k-w bit table
346 // too few codes for k-w bit table
347 f -= a + 1; // deduct codes from patterns left
348 xp = k;
349 if(j < z){
350 while (++j < z){ // try smaller tables up to z bits
351 if((f <<= 1) <= c[++xp])
352 break; // enough codes to use up j bits
353 f -= c[xp]; // else deduct codes from patterns
354 }
355 }
356 }
357 z = 1 << j; // table entries for j-bit table
358
359 // allocate new table
360 if (hn[0] + z > MANY){ // (note: doesn't matter for fixed)
361 return Z_DATA_ERROR; // overflow of MANY
362 }
363 u[h] = q = /*hp+*/ hn[0]; // DEBUG
364 hn[0] += z;
365
366 // connect to last table, if there is one
367 if(h!=0){
368 x[h]=i; // save pattern for backing up
369 r[0]=(byte)j; // bits in this table
370 r[1]=(byte)l; // bits to dump before this table
371 j=i>>>(w - l);
372 r[2] = (int)(q - u[h-1] - j); // offset to this table
373 System.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table
374 }
375 else{
376 t[0] = q; // first table is returned result
377 }
267 } 378 }
268 while (i != 0); 379
269 380 // set up table entry in r
270 if (c[0] == n) { // null input--all zero length codes 381 r[1] = (byte)(k - w);
271 t[0] = -1; 382 if (p >= n){
272 m[0] = 0; 383 r[0] = 128 + 64; // out of values--invalid code
273 return Z_OK; 384 }
385 else if (v[p] < s){
386 r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
387 r[2] = v[p++]; // simple code is just the value
274 } 388 }
275 389 else{
276 // Find minimum and maximum length, bound *m by those 390 r[0]=(byte)(e[v[p]-s]+16+64); // non-simple--look up in lists
277 l = m[0]; 391 r[2]=d[v[p++] - s];
278
279 for (j = 1; j <= BMAX; j++)
280 if (c[j] != 0) break;
281
282 k = j; // minimum code length
283
284 if (l < j) {
285 l = j;
286 } 392 }
287 393
288 for (i = BMAX; i != 0; i--) { 394 // fill code-like entries with r
289 if (c[i] != 0) break; 395 f=1<<(k-w);
396 for (j=i>>>w;j<z;j+=f){
397 System.arraycopy(r, 0, hp, (q+j)*3, 3);
398 }
399
400 // backwards increment the k-bit code i
401 for (j = 1 << (k - 1); (i & j)!=0; j >>>= 1){
402 i ^= j;
403 }
404 i ^= j;
405
406 // backup over finished tables
407 mask = (1 << w) - 1; // needed on HP, cc -O bug
408 while ((i & mask) != x[h]){
409 h--; // don't need to update q
410 w -= l;
411 mask = (1 << w) - 1;
290 } 412 }
291 413 }
292 g = i; // maximum code length 414 }
293 415 // Return Z_BUF_ERROR if we were given an incomplete table
294 if (l > i) { 416 return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
295 l = i; 417 }
296 } 418
297 419 int inflate_trees_bits(int[] c, // 19 code lengths
298 m[0] = l; 420 int[] bb, // bits tree desired/actual depth
299 421 int[] tb, // bits tree result
300 // Adjust last length count to fill out codes, if needed 422 int[] hp, // space for trees
301 for (y = 1 << j; j < i; j++, y <<= 1) { 423 ZStream z // for messages
302 if ((y -= c[j]) < 0) { 424 ){
303 return Z_DATA_ERROR; 425 int result;
304 } 426 initWorkArea(19);
305 } 427 hn[0]=0;
306 428 result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
307 if ((y -= c[i]) < 0) { 429
308 return Z_DATA_ERROR; 430 if(result == Z_DATA_ERROR){
309 } 431 z.msg = "oversubscribed dynamic bit lengths tree";
310 432 }
311 c[i] += y; 433 else if(result == Z_BUF_ERROR || bb[0] == 0){
312 // Generate starting offsets into the value table for each length 434 z.msg = "incomplete dynamic bit lengths tree";
313 x[1] = j = 0; 435 result = Z_DATA_ERROR;
314 p = 1; xp = 2; 436 }
315 437 return result;
316 while (--i != 0) { // note that i == g from above 438 }
317 x[xp] = (j += c[p]); 439
318 xp++; 440 int inflate_trees_dynamic(int nl, // number of literal/length codes
319 p++; 441 int nd, // number of distance codes
320 } 442 int[] c, // that many (total) code lengths
321 443 int[] bl, // literal desired/actual bit depth
322 // Make a table of values in order of bit lengths 444 int[] bd, // distance desired/actual bit depth
323 i = 0; p = 0; 445 int[] tl, // literal/length tree result
324 446 int[] td, // distance tree result
325 do { 447 int[] hp, // space for trees
326 if ((j = b[bindex + p]) != 0) { 448 ZStream z // for messages
327 v[x[j]++] = i; 449 ){
328 } 450 int result;
329 451
330 p++; 452 // build literal/length tree
331 } 453 initWorkArea(288);
332 while (++i < n); 454 hn[0]=0;
333 455 result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
334 n = x[g]; // set n to length of v 456 if (result != Z_OK || bl[0] == 0){
335 // Generate the Huffman codes and for each, make the table entries 457 if(result == Z_DATA_ERROR){
336 x[0] = i = 0; // first Huffman code is zero 458 z.msg = "oversubscribed literal/length tree";
337 p = 0; // grab values in bit order 459 }
338 h = -1; // no tables yet--level -1 460 else if (result != Z_MEM_ERROR){
339 w = -l; // bits decoded == (l * h) 461 z.msg = "incomplete literal/length tree";
340 u[0] = 0; // just to keep compilers happy 462 result = Z_DATA_ERROR;
341 q = 0; // ditto 463 }
342 z = 0; // ditto 464 return result;
343 465 }
344 // go through the bit lengths (k already is bits in shortest code) 466
345 for (; k <= g; k++) { 467 // build distance tree
346 a = c[k]; 468 initWorkArea(288);
347 469 result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
348 while (a-- != 0) { 470
349 // here i is the Huffman code of length k bits for value *p 471 if (result != Z_OK || (bd[0] == 0 && nl > 257)){
350 // make tables up to required level 472 if (result == Z_DATA_ERROR){
351 while (k > w + l) { 473 z.msg = "oversubscribed distance tree";
352 h++; 474 }
353 w += l; // previous table always l bits 475 else if (result == Z_BUF_ERROR) {
354 // compute minimum size table less than or equal to l bits 476 z.msg = "incomplete distance tree";
355 z = g - w; 477 result = Z_DATA_ERROR;
356 z = (z > l) ? l : z; // table size upper limit 478 }
357 479 else if (result != Z_MEM_ERROR){
358 if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table 480 z.msg = "empty distance tree with lengths";
359 // too few codes for k-w bit table 481 result = Z_DATA_ERROR;
360 f -= a + 1; // deduct codes from patterns left 482 }
361 xp = k; 483 return result;
362 484 }
363 if (j < z) { 485
364 while (++j < z) { // try smaller tables up to z bits 486 return Z_OK;
365 if ((f <<= 1) <= c[++xp]) 487 }
366 break; // enough codes to use up j bits 488
367 489 static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
368 f -= c[xp]; // else deduct codes from patterns 490 int[] bd, //distance desired/actual bit depth
369 } 491 int[][] tl,//literal/length tree result
370 } 492 int[][] td,//distance tree result
371 } 493 ZStream z //for memory allocation
372 494 ){
373 z = 1 << j; // table entries for j-bit table 495 bl[0]=fixed_bl;
374 496 bd[0]=fixed_bd;
375 // allocate new table 497 tl[0]=fixed_tl;
376 if (hn[0] + z > MANY) { // (note: doesn't matter for fixed) 498 td[0]=fixed_td;
377 return Z_DATA_ERROR; // overflow of MANY 499 return Z_OK;
378 } 500 }
379 501
380 u[h] = q = /*hp+*/ hn[0]; // DEBUG 502 private void initWorkArea(int vsize){
381 hn[0] += z; 503 if(hn==null){
382 504 hn=new int[1];
383 // connect to last table, if there is one 505 v=new int[vsize];
384 if (h != 0) { 506 c=new int[BMAX+1];
385 x[h] = i; // save pattern for backing up 507 r=new int[3];
386 r[0] = (byte)j; // bits in this table 508 u=new int[BMAX];
387 r[1] = (byte)l; // bits to dump before this table 509 x=new int[BMAX+1];
388 j = i >>> (w - l); 510 }
389 r[2] = (int)(q - u[h - 1] - j); // offset to this table 511 if(v.length<vsize){ v=new int[vsize]; }
390 System.arraycopy(r, 0, hp, (u[h - 1] + j) * 3, 3); // connect to last table 512 for(int i=0; i<vsize; i++){v[i]=0;}
391 } 513 for(int i=0; i<BMAX+1; i++){c[i]=0;}
392 else { 514 for(int i=0; i<3; i++){r[i]=0;}
393 t[0] = q; // first table is returned result 515 System.arraycopy(c, 0, u, 0, BMAX);
394 } 516 System.arraycopy(c, 0, x, 0, BMAX+1);
395 } 517 }
396
397 // set up table entry in r
398 r[1] = (byte)(k - w);
399
400 if (p >= n) {
401 r[0] = 128 + 64; // out of values--invalid code
402 }
403 else if (v[p] < s) {
404 r[0] = (byte)(v[p] < 256 ? 0 : 32 + 64); // 256 is end-of-block
405 r[2] = v[p++]; // simple code is just the value
406 }
407 else {
408 r[0] = (byte)(e[v[p] - s] + 16 + 64); // non-simple--look up in lists
409 r[2] = d[v[p++] - s];
410 }
411
412 // fill code-like entries with r
413 f = 1 << (k - w);
414
415 for (j = i >>> w; j < z; j += f) {
416 System.arraycopy(r, 0, hp, (q + j) * 3, 3);
417 }
418
419 // backwards increment the k-bit code i
420 for (j = 1 << (k - 1); (i & j) != 0; j >>>= 1) {
421 i ^= j;
422 }
423
424 i ^= j;
425 // backup over finished tables
426 mask = (1 << w) - 1; // needed on HP, cc -O bug
427
428 while ((i & mask) != x[h]) {
429 h--; // don't need to update q
430 w -= l;
431 mask = (1 << w) - 1;
432 }
433 }
434 }
435
436 // Return Z_BUF_ERROR if we were given an incomplete table
437 return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
438 }
439
440 int inflate_trees_bits(int[] c, // 19 code lengths
441 int[] bb, // bits tree desired/actual depth
442 int[] tb, // bits tree result
443 int[] hp, // space for trees
444 ZStream z // for messages
445 ) {
446 int result;
447 initWorkArea(19);
448 hn[0] = 0;
449 result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
450
451 if (result == Z_DATA_ERROR) {
452 z.msg = "oversubscribed dynamic bit lengths tree";
453 }
454 else if (result == Z_BUF_ERROR || bb[0] == 0) {
455 z.msg = "incomplete dynamic bit lengths tree";
456 result = Z_DATA_ERROR;
457 }
458
459 return result;
460 }
461
462 int inflate_trees_dynamic(int nl, // number of literal/length codes
463 int nd, // number of distance codes
464 int[] c, // that many (total) code lengths
465 int[] bl, // literal desired/actual bit depth
466 int[] bd, // distance desired/actual bit depth
467 int[] tl, // literal/length tree result
468 int[] td, // distance tree result
469 int[] hp, // space for trees
470 ZStream z // for messages
471 ) {
472 int result;
473 // build literal/length tree
474 initWorkArea(288);
475 hn[0] = 0;
476 result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
477
478 if (result != Z_OK || bl[0] == 0) {
479 if (result == Z_DATA_ERROR) {
480 z.msg = "oversubscribed literal/length tree";
481 }
482 else if (result != Z_MEM_ERROR) {
483 z.msg = "incomplete literal/length tree";
484 result = Z_DATA_ERROR;
485 }
486
487 return result;
488 }
489
490 // build distance tree
491 initWorkArea(288);
492 result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
493
494 if (result != Z_OK || (bd[0] == 0 && nl > 257)) {
495 if (result == Z_DATA_ERROR) {
496 z.msg = "oversubscribed distance tree";
497 }
498 else if (result == Z_BUF_ERROR) {
499 z.msg = "incomplete distance tree";
500 result = Z_DATA_ERROR;
501 }
502 else if (result != Z_MEM_ERROR) {
503 z.msg = "empty distance tree with lengths";
504 result = Z_DATA_ERROR;
505 }
506
507 return result;
508 }
509
510 return Z_OK;
511 }
512
513 static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
514 int[] bd, //distance desired/actual bit depth
515 int[][] tl,//literal/length tree result
516 int[][] td,//distance tree result
517 ZStream z //for memory allocation
518 ) {
519 bl[0] = fixed_bl;
520 bd[0] = fixed_bd;
521 tl[0] = fixed_tl;
522 td[0] = fixed_td;
523 return Z_OK;
524 }
525
526 private void initWorkArea(int vsize) {
527 if (hn == null) {
528 hn = new int[1];
529 v = new int[vsize];
530 c = new int[BMAX + 1];
531 r = new int[3];
532 u = new int[BMAX];
533 x = new int[BMAX + 1];
534 }
535
536 if (v.length < vsize) { v = new int[vsize]; }
537
538 for (int i = 0; i < vsize; i++) {v[i] = 0;}
539
540 for (int i = 0; i < BMAX + 1; i++) {c[i] = 0;}
541
542 for (int i = 0; i < 3; i++) {r[i] = 0;}
543
544 // for(int i=0; i<BMAX; i++){u[i]=0;}
545 System.arraycopy(c, 0, u, 0, BMAX);
546 // for(int i=0; i<BMAX+1; i++){x[i]=0;}
547 System.arraycopy(c, 0, x, 0, BMAX + 1);
548 }
549 } 518 }