See header for documentation. */
| 649 | |
| 650 | /* See header for documentation. */ |
| 651 | void decode_ise( |
| 652 | quant_method quant_level, |
| 653 | unsigned int character_count, |
| 654 | const uint8_t* input_data, |
| 655 | uint8_t* output_data, |
| 656 | unsigned int bit_offset |
| 657 | ) { |
| 658 | promise(character_count > 0); |
| 659 | |
| 660 | // Note: due to how the trit/quint-block unpacking is done in this function, we may write more |
| 661 | // temporary results than the number of outputs. The maximum actual number of results is 64 bit, |
| 662 | // but we keep 4 additional character_count of padding. |
| 663 | uint8_t results[68]; |
| 664 | uint8_t tq_blocks[22] { 0 }; // Trit-blocks or quint-blocks, must be zeroed |
| 665 | |
| 666 | unsigned int bits = btq_counts[quant_level].bits; |
| 667 | unsigned int trits = btq_counts[quant_level].trits; |
| 668 | unsigned int quints = btq_counts[quant_level].quints; |
| 669 | |
| 670 | unsigned int lcounter = 0; |
| 671 | unsigned int hcounter = 0; |
| 672 | |
| 673 | // Collect bits for each element, as well as bits for any trit-blocks and quint-blocks. |
| 674 | for (unsigned int i = 0; i < character_count; i++) |
| 675 | { |
| 676 | results[i] = static_cast<uint8_t>(read_bits(bits, bit_offset, input_data)); |
| 677 | bit_offset += bits; |
| 678 | |
| 679 | if (trits) |
| 680 | { |
| 681 | static const uint8_t bits_to_read[5] { 2, 2, 1, 2, 1 }; |
| 682 | static const uint8_t block_shift[5] { 0, 2, 4, 5, 7 }; |
| 683 | static const uint8_t next_lcounter[5] { 1, 2, 3, 4, 0 }; |
| 684 | static const uint8_t hcounter_incr[5] { 0, 0, 0, 0, 1 }; |
| 685 | unsigned int tdata = read_bits(bits_to_read[lcounter], bit_offset, input_data); |
| 686 | bit_offset += bits_to_read[lcounter]; |
| 687 | tq_blocks[hcounter] |= tdata << block_shift[lcounter]; |
| 688 | hcounter += hcounter_incr[lcounter]; |
| 689 | lcounter = next_lcounter[lcounter]; |
| 690 | } |
| 691 | |
| 692 | if (quints) |
| 693 | { |
| 694 | static const uint8_t bits_to_read[3] { 3, 2, 2 }; |
| 695 | static const uint8_t block_shift[3] { 0, 3, 5 }; |
| 696 | static const uint8_t next_lcounter[3] { 1, 2, 0 }; |
| 697 | static const uint8_t hcounter_incr[3] { 0, 0, 1 }; |
| 698 | unsigned int tdata = read_bits(bits_to_read[lcounter], bit_offset, input_data); |
| 699 | bit_offset += bits_to_read[lcounter]; |
| 700 | tq_blocks[hcounter] |= tdata << block_shift[lcounter]; |
| 701 | hcounter += hcounter_incr[lcounter]; |
| 702 | lcounter = next_lcounter[lcounter]; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | // Unpack trit-blocks or quint-blocks as needed |
| 707 | if (trits) |
| 708 | { |
no test coverage detected