/bundles/plugins-trunk/FTP/com/jcraft/jzlib/InfTree.java

# · Java · 520 lines · 418 code · 39 blank · 63 comment · 68 complexity · 0b73513df56a1dac18c3a5de2cf88af7 MD5 · raw file

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