(int contextMapSize, byte[] contextMap, State s)
| 664 | } |
| 665 | |
| 666 | private static int decodeContextMap(int contextMapSize, byte[] contextMap, State s) { |
| 667 | int result; |
| 668 | if (s.halfOffset > BitReader.HALF_WATERLINE) { |
| 669 | result = BitReader.readMoreInput(s); |
| 670 | if (result < BROTLI_OK) { |
| 671 | return result; |
| 672 | } |
| 673 | } |
| 674 | final int numTrees = decodeVarLenUnsignedByte(s) + 1; |
| 675 | |
| 676 | if (numTrees == 1) { |
| 677 | Utils.fillBytesWithZeroes(contextMap, 0, contextMapSize); |
| 678 | return numTrees; |
| 679 | } |
| 680 | |
| 681 | BitReader.fillBitWindow(s); |
| 682 | final int useRleForZeros = BitReader.readFewBits(s, 1); |
| 683 | int maxRunLengthPrefix = 0; |
| 684 | if (useRleForZeros != 0) { |
| 685 | maxRunLengthPrefix = BitReader.readFewBits(s, 4) + 1; |
| 686 | } |
| 687 | final int alphabetSize = numTrees + maxRunLengthPrefix; |
| 688 | final int tableSize = MAX_HUFFMAN_TABLE_SIZE[(alphabetSize + 31) >> 5]; |
| 689 | /* Speculative single entry table group. */ |
| 690 | final int[] table = new int[tableSize + 1]; |
| 691 | final int tableIdx = table.length - 1; |
| 692 | result = readHuffmanCode(alphabetSize, alphabetSize, table, tableIdx, s); |
| 693 | if (result < BROTLI_OK) { |
| 694 | return result; |
| 695 | } |
| 696 | int i = 0; |
| 697 | while (i < contextMapSize) { |
| 698 | if (s.halfOffset > BitReader.HALF_WATERLINE) { |
| 699 | result = BitReader.readMoreInput(s); |
| 700 | if (result < BROTLI_OK) { |
| 701 | return result; |
| 702 | } |
| 703 | } |
| 704 | BitReader.fillBitWindow(s); |
| 705 | final int code = readSymbol(table, tableIdx, s); |
| 706 | if (code == 0) { |
| 707 | contextMap[i] = 0; |
| 708 | i++; |
| 709 | } else if (code <= maxRunLengthPrefix) { |
| 710 | BitReader.fillBitWindow(s); |
| 711 | int reps = (1 << code) + BitReader.readFewBits(s, code); |
| 712 | while (reps != 0) { |
| 713 | if (i >= contextMapSize) { |
| 714 | return Utils.makeError(s, BROTLI_ERROR_CORRUPTED_CONTEXT_MAP); |
| 715 | } |
| 716 | contextMap[i] = 0; |
| 717 | i++; |
| 718 | reps--; |
| 719 | } |
| 720 | } else { |
| 721 | contextMap[i] = (byte) (code - maxRunLengthPrefix); |
| 722 | i++; |
| 723 | } |
no test coverage detected