Implements the pseudocode of page 98 of the IS
(final LameInternalFlags gfc, final int tableindex, final int start, final int end, final GrInfo gi)
| 473 | * Implements the pseudocode of page 98 of the IS |
| 474 | */ |
| 475 | private int Huffmancode(final LameInternalFlags gfc, final int tableindex, |
| 476 | final int start, final int end, final GrInfo gi) { |
| 477 | final HuffCodeTab h = Tables.ht[tableindex]; |
| 478 | int bits = 0; |
| 479 | |
| 480 | assert (tableindex < 32); |
| 481 | if (0 == tableindex) |
| 482 | return bits; |
| 483 | |
| 484 | for (int i = start; i < end; i += 2) { |
| 485 | int cbits = 0; |
| 486 | int xbits = 0; |
| 487 | final int linbits = h.xlen; |
| 488 | int xlen = h.xlen; |
| 489 | int ext = 0; |
| 490 | int x1 = gi.l3_enc[i]; |
| 491 | int x2 = gi.l3_enc[i + 1]; |
| 492 | |
| 493 | if (x1 != 0) { |
| 494 | if (gi.xr[i] < 0) |
| 495 | ext++; |
| 496 | cbits--; |
| 497 | } |
| 498 | |
| 499 | if (tableindex > 15) { |
| 500 | /* use ESC-words */ |
| 501 | if (x1 > 14) { |
| 502 | final int linbits_x1 = x1 - 15; |
| 503 | assert (linbits_x1 <= h.linmax); |
| 504 | ext |= linbits_x1 << 1; |
| 505 | xbits = linbits; |
| 506 | x1 = 15; |
| 507 | } |
| 508 | |
| 509 | if (x2 > 14) { |
| 510 | final int linbits_x2 = x2 - 15; |
| 511 | assert (linbits_x2 <= h.linmax); |
| 512 | ext <<= linbits; |
| 513 | ext |= linbits_x2; |
| 514 | xbits += linbits; |
| 515 | x2 = 15; |
| 516 | } |
| 517 | xlen = 16; |
| 518 | } |
| 519 | |
| 520 | if (x2 != 0) { |
| 521 | ext <<= 1; |
| 522 | if (gi.xr[i + 1] < 0) |
| 523 | ext++; |
| 524 | cbits--; |
| 525 | } |
| 526 | |
| 527 | assert ((x1 | x2) < 16); |
| 528 | |
| 529 | x1 = x1 * xlen + x2; |
| 530 | xbits -= cbits; |
| 531 | cbits += h.hlen[x1]; |
| 532 |
no test coverage detected