| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 16 мар. 2021 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_RESOURCE_DECOMPRESSOR_H_ |
| 23 |
#define LSP_PLUG_IN_RESOURCE_DECOMPRESSOR_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/io/IInStream.h> |
| 27 |
#include <lsp-plug.in/io/InBitStream.h> |
| 28 |
#include <lsp-plug.in/resource/buffer.h> |
| 29 |
|
| 30 |
namespace lsp |
| 31 |
{ |
| 32 |
namespace resource |
| 33 |
{ |
| 34 |
class Decompressor: public io::IInStream |
| 35 |
{ |
| 36 |
protected: |
| 37 |
typedef struct cbuf_t |
| 38 |
{ |
| 39 |
uint8_t *data; // Data |
| 40 |
size_t off; // Offset |
| 41 |
size_t size; // Size of buffer |
| 42 |
size_t cap; // Capacity of buffer |
| 43 |
size_t rep; // Number of repeats |
| 44 |
} cbuf_t; |
| 45 |
|
| 46 |
protected: |
| 47 |
io::InBitStream sIn; // Input stream |
| 48 |
dbuffer_t sBuffer; // Buffer for caching |
| 49 |
cbuf_t sReplay; // Replay buffer |
| 50 |
|
| 51 |
size_t nOffset; // Offset |
| 52 |
size_t nSize; // Decompressed size |
| 53 |
|
| 54 |
protected: |
| 55 |
status_t read_uint(size_t *out, size_t initial, size_t stepping); |
| 56 |
size_t get_buf(uint8_t *dst, size_t count); |
| 57 |
ssize_t get_bufc(); |
| 58 |
status_t set_buf(size_t off, size_t count, size_t rep); |
| 59 |
status_t set_bufc(uint8_t c, size_t rep); |
| 60 |
status_t fill_buf(); |
| 61 |
status_t do_close(); |
| 62 |
|
| 63 |
public: |
| 64 |
explicit Decompressor(); |
| 65 |
Decompressor(const Decompressor &) = delete; |
| 66 |
Decompressor(Decompressor &&) = delete; |
| 67 |
Decompressor & operator = (const Decompressor &) = delete; |
| 68 |
Decompressor & operator = (Decompressor &&) = delete; |
| 69 |
|
| 70 |
virtual ~Decompressor() override; |
| 71 |
|
| 72 |
public: |
| 73 |
/** |
| 74 |
* Initialize decompressor |
| 75 |
* @param data binary data |
| 76 |
* @param data_size the size of the binary data |
| 77 |
* @param decompressed_size the size of the decompressed data |
| 78 |
* @param buf_sz I/O buffer size (the exponent for power-of-two value) |
| 79 |
* @return status of operation |
| 80 |
*/ |
| 81 |
status_t init(const void *data, size_t data_size, size_t decompressed_size, size_t log_buf_sz); |
| 82 |
|
| 83 |
public: // io::IInStream |
| 84 |
virtual wssize_t position() override; |
| 85 |
virtual ssize_t read_byte() override; |
| 86 |
virtual ssize_t read(void *dst, size_t count) override; |
| 87 |
virtual status_t close() override; |
| 88 |
}; |
| 89 |
} /* namespace resource */ |
| 90 |
} /* namespace lsp */ |
| 91 |
|
| 92 |
#endif /* LSP_PLUG_IN_RESOURCE_DECOMPRESSOR_H_ */ |