| 270 | }; |
| 271 | |
| 272 | function CreateTree(currentTree, numval, lengths, show) { |
| 273 | var i; |
| 274 | /* Create the Huffman decode tree/table */ |
| 275 | //document.write("<br>createtree<br>"); |
| 276 | if (debug) |
| 277 | util.debug("currentTree " + currentTree + " numval " + numval + " lengths " + lengths + " show " + show); |
| 278 | Places = currentTree; |
| 279 | treepos=0; |
| 280 | flens = lengths; |
| 281 | fmax = numval; |
| 282 | for (i=0;i<17;i++) |
| 283 | fpos[i] = 0; |
| 284 | len = 0; |
| 285 | if(Rec()) { |
| 286 | //fprintf(stderr, "invalid huffman tree\n"); |
| 287 | if (debug) |
| 288 | util.debug("invalid huffman tree"); |
| 289 | return -1; |
| 290 | } |
| 291 | if (debug){ |
| 292 | util.debug("Tree: " + Places.length); |
| 293 | for (var a=0;a<32;a++){ |
| 294 | util.debug("Places[" + a + "].b0=" + Places[a].b0); |
| 295 | util.debug("Places[" + a + "].b1=" + Places[a].b1); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /*if(show) { |
| 300 | var tmp; |
| 301 | for(tmp=currentTree;tmp<Places;tmp++) { |
| 302 | fprintf(stdout, "0x%03x 0x%03x (0x%04x)",tmp-currentTree, tmp->jump?tmp->jump-currentTree:0,(tmp->jump?tmp->jump-currentTree:0)*6+0xcf0); |
| 303 | if(!(tmp.b0 & 0x8000)) { |
| 304 | //fprintf(stdout, " 0x%03x (%c)", tmp->b0,(tmp->b0<256 && isprint(tmp->b0))?tmp->b0:'�'); |
| 305 | } |
| 306 | if(!(tmp.b1 & 0x8000)) { |
| 307 | if((tmp.b0 & 0x8000)) |
| 308 | fprintf(stdout, " "); |
| 309 | fprintf(stdout, " 0x%03x (%c)", tmp->b1,(tmp->b1<256 && isprint(tmp->b1))?tmp->b1:'�'); |
| 310 | } |
| 311 | fprintf(stdout, "\n"); |
| 312 | } |
| 313 | }*/ |
| 314 | return 0; |
| 315 | }; |
| 316 | |
| 317 | function DecodeValue(currentTree) { |
| 318 | var len, i, |