(
int[] codeLengthCodeLengths, int numSymbols, int[] codeLengths, State s)
| 460 | } |
| 461 | |
| 462 | private static int readHuffmanCodeLengths( |
| 463 | int[] codeLengthCodeLengths, int numSymbols, int[] codeLengths, State s) { |
| 464 | int symbol = 0; |
| 465 | int prevCodeLen = DEFAULT_CODE_LENGTH; |
| 466 | int repeat = 0; |
| 467 | int repeatCodeLen = 0; |
| 468 | int space = 32768; |
| 469 | final int[] table = new int[32 + 1]; /* Speculative single entry table group. */ |
| 470 | final int tableIdx = table.length - 1; |
| 471 | Huffman.buildHuffmanTable(table, tableIdx, 5, codeLengthCodeLengths, CODE_LENGTH_CODES); |
| 472 | |
| 473 | while (symbol < numSymbols && space > 0) { |
| 474 | if (s.halfOffset > BitReader.HALF_WATERLINE) { |
| 475 | final int result = BitReader.readMoreInput(s); |
| 476 | if (result < BROTLI_OK) { |
| 477 | return result; |
| 478 | } |
| 479 | } |
| 480 | BitReader.fillBitWindow(s); |
| 481 | final int p = BitReader.peekBits(s) & 31; |
| 482 | s.bitOffset += table[p] >> 16; |
| 483 | final int codeLen = table[p] & 0xFFFF; |
| 484 | if (codeLen < CODE_LENGTH_REPEAT_CODE) { |
| 485 | repeat = 0; |
| 486 | codeLengths[symbol++] = codeLen; |
| 487 | if (codeLen != 0) { |
| 488 | prevCodeLen = codeLen; |
| 489 | space -= 32768 >> codeLen; |
| 490 | } |
| 491 | } else { |
| 492 | final int extraBits = codeLen - 14; |
| 493 | int newLen = 0; |
| 494 | if (codeLen == CODE_LENGTH_REPEAT_CODE) { |
| 495 | newLen = prevCodeLen; |
| 496 | } |
| 497 | if (repeatCodeLen != newLen) { |
| 498 | repeat = 0; |
| 499 | repeatCodeLen = newLen; |
| 500 | } |
| 501 | final int oldRepeat = repeat; |
| 502 | if (repeat > 0) { |
| 503 | repeat -= 2; |
| 504 | repeat = repeat << extraBits; |
| 505 | } |
| 506 | BitReader.fillBitWindow(s); |
| 507 | repeat += BitReader.readFewBits(s, extraBits) + 3; |
| 508 | final int repeatDelta = repeat - oldRepeat; |
| 509 | if (symbol + repeatDelta > numSymbols) { |
| 510 | return Utils.makeError(s, BROTLI_ERROR_CORRUPTED_CODE_LENGTH_TABLE); |
| 511 | } |
| 512 | for (int i = 0; i < repeatDelta; ++i) { |
| 513 | codeLengths[symbol++] = repeatCodeLen; |
| 514 | } |
| 515 | if (repeatCodeLen != 0) { |
| 516 | space -= repeatDelta << (15 - repeatCodeLen); |
| 517 | } |
| 518 | } |
| 519 | } |
no test coverage detected