diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2023-08-17 00:40:00 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2023-08-17 00:40:00 -0600 |
| commit | 1c5b3de55c72dca9a16c58a0f4dba3eee9b1f8e6 (patch) | |
| tree | b6d3cdb0411b0e0ef8e802516fd6f65462d79c1b /src/utils/MIODecoder.cpp | |
| parent | 6fd8e5ee43dd0f87eb4e57b86e84770fcd95db25 (diff) | |
Starting CUBE-OS v0.1...
Diffstat (limited to 'src/utils/MIODecoder.cpp')
| -rw-r--r-- | src/utils/MIODecoder.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/utils/MIODecoder.cpp b/src/utils/MIODecoder.cpp new file mode 100644 index 0000000..aed5eba --- /dev/null +++ b/src/utils/MIODecoder.cpp @@ -0,0 +1,27 @@ +#include "MIODecoder.h" + +extern "C" { +#include <libmio0/mio0.h> +} + +std::unordered_map<uint32_t, std::vector<char>> MIO0Decoder::gCachedChunks; + +std::vector<char>& MIO0Decoder::Decode(std::vector<uint8_t>& buffer, uint32_t offset) { + const unsigned char* in_buf = buffer.data() + offset; + + mio0_header_t head; + if(!mio0_decode_header(in_buf, &head)){ + throw std::runtime_error("Invalid MIO0 header"); + } + + uint8_t* decompressed = new uint8_t[head.dest_size]; + mio0_decode(in_buf, decompressed, nullptr); + gCachedChunks[offset] = std::vector<char>(decompressed, decompressed + head.dest_size); + + delete[] decompressed; + return gCachedChunks[offset]; +} + +void MIO0Decoder::ClearCache() { + gCachedChunks.clear(); +}
\ No newline at end of file |
