7#include "../utility/utility.hpp"
8#include "../container/module.hpp"
9#include "../parser/parser.hpp"
10#include "../macros.hpp"
14hi_export_module(hikogui.codec.inflate);
16namespace hi {
inline namespace v1 {
26 hi_check((offset +
LEN) <=
bytes.size(),
"input buffer overrun");
27 hi_check((r.size() +
LEN) <= max_size,
"output buffer overrun");
96 throw parse_error(std::format(
"Literal/Length symbol out of range {}",
symbol));
165 throw parse_error(std::format(
"Distance symbol out of range {}",
symbol));
169inline void inflate_block(
170 std::span<std::byte const>
bytes,
182 hi_check(((
bit_offset + 27) >> 3) <=
bytes.size(),
"Input buffer overrun");
187 hi_check(r.size() < max_size,
"Output buffer overrun");
196 hi_check(r.size() + length <= max_size,
"Output buffer overrun");
201 hi_check(((
bit_offset + 22) >> 3) <=
bytes.size(),
"Input buffer overrun");
207 hi_check(((
bit_offset + 20) >> 3) <=
bytes.size(),
"Input buffer overrun");
210 hi_check(distance <= r.size(),
"Distance beyond start of decompressed data");
212 for (
auto i = 0; i != length; ++i) {
213 r.push_back(r[
src_i++]);
222 for (
int i = 0; i <= 143; ++i) {
225 for (
int i = 144; i <= 255; ++i) {
228 for (
int i = 256; i <= 279; ++i) {
231 for (
int i = 280; i <= 287; ++i) {
241 for (
int i = 0; i <= 31; ++i) {
250 inflate_block(
bytes,
bit_offset, max_size, deflate_fixed_literal_tree, deflate_fixed_distance_tree, r);
257 constexpr auto symbols =
std::array<int16_t, 19>{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
270 std::span<std::byte const>
bytes,
284 hi_check(((
bit_offset + 21) >> 3) <=
bytes.size(),
"Input buffer overrun");
325 hi_check(((
bit_offset + 21) >> 3) <=
bytes.size(),
"Input buffer overrun");
333 hi_check(
lengths[256] != 0,
"The end-of-block symbol must be in the table");
369 hi_check(((
bit_offset + 10) >> 3) <=
bytes.size(),
"Input buffer overrun");
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
std::size_t get_bits(std::span< std::byte const > buffer, std::size_t &index, std::size_t length) noexcept
Read a bits from of span of bytes Bits are ordered LSB first.
Definition bits.hpp:55
bool get_bit(std::span< std::byte const > buffer, std::size_t &index) noexcept
Read a single bit from span of bytes Bits are ordered LSB first.
Definition bits.hpp:27
hi_export bstring inflate(std::span< std::byte const > bytes, std::size_t &offset, std::size_t max_size=0x0100 '0000)
Inflate compressed data using the deflate algorithm bytes should include at least 32 bit of trailer,...
Definition inflate.hpp:358
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
static huffman_tree from_lengths(uint8_t const *lengths, std::size_t nr_symbols)
Build a canonical-huffman table from a set of lengths.
Definition huffman.hpp:122
Exception thrown during parsing on an error.
Definition exception_intf.hpp:47