8#include "../container/container.hpp"
9#include "../parser/parser.hpp"
10#include "../macros.hpp"
15hi_export_module(hikogui.codec.zlib);
17hi_export
namespace hi {
inline namespace v1 {
19[[nodiscard]]
inline bstring zlib_decompress(std::span<std::byte const> bytes,
std::size_t max_size)
28 auto const header = make_placement_ptr<zlib_header>(bytes, offset);
30 auto const header_chksum = header->CMF * 256 + header->FLG;
31 hi_check(header_chksum % 31 == 0,
"zlib header checksum failed.");
33 hi_check((header->CMF & 0xf) == 8,
"zlib compression method must be 8");
34 hi_check(((header->CMF >> 4) & 0xf) <= 7,
"zlib LZ77 window too large");
35 hi_check((header->FLG & 0x20) == 0,
"zlib must not use a preset dictionary");
37 if (header->FLG & 0x20) {
38 [[maybe_unused]]
auto FDICT = make_placement_ptr<big_uint32_buf_t>(bytes, offset);
41 auto r =
inflate(bytes, offset, max_size);
43 [[maybe_unused]]
auto ADLER32 = make_placement_ptr<big_uint32_buf_t>(bytes, offset);
48[[nodiscard]]
inline bstring zlib_decompress(std::filesystem::path
const& path,
std::size_t max_size = 0x01000000)
50 return zlib_decompress(as_span<std::byte const>(file_view(path)), max_size);
The HikoGUI namespace.
Definition array_generic.hpp:20
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
DOXYGEN BUG.
Definition algorithm_misc.hpp:20