libnedit
Lightweight C++ library for Nintendo DS(i) formats
Loading...
Searching...
No Matches
util_Compression.hpp
1
2#pragma once
3#include <ntr/ntr_Include.hpp>
4
5namespace ntr::util {
6
7 enum class LzVersion : u8 {
8 Invalid = 0,
9 LZ10 = 0x10,
10 LZ11 = 0x11
11 };
12
13 // LZ10 size is encoded in 3 bytes...
14 constexpr size_t MaximumLZ10CompressSize = 1ul << static_cast<size_t>(3 * CHAR_BIT);
15
16 // ...while LZ11 size is encoded in 4 bytes
17 constexpr u64 MaximumLZ11CompressSize = 1ull << static_cast<u64>(4 * CHAR_BIT);
18
19 constexpr u32 LZ10RepeatSize = 18;
20 constexpr u32 MaximumLZ11RepeatSize = 65809;
21 constexpr u32 DefaultRepeatSize = LZ10RepeatSize;
22
23 Result LzValidateCompressed(const u32 lz_header, LzVersion &out_ver);
24
25 Result LzCompress(const u8 *data, const size_t data_size, const LzVersion ver, const u32 repeat_size, u8 *&out_data, size_t &out_size);
26
27 inline Result LzCompressDefault(const u8 *data, const size_t data_size, const LzVersion ver, u8 *&out_data, size_t &out_size) {
28 return LzCompress(data, data_size, ver, DefaultRepeatSize, out_data, out_size);
29 }
30
31 Result LzDecompress(const u8 *data, u8 *&out_data, size_t &out_size, LzVersion &out_ver, size_t &out_used_data_size);
32
33}