Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/resource/Compressor.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 1 мар. 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_ICOMPRESSOR_H_
23 #define LSP_PLUG_IN_RESOURCE_ICOMPRESSOR_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/io/OutMemoryStream.h>
27 #include <lsp-plug.in/io/IOutSequence.h>
28 #include <lsp-plug.in/io/IOutStream.h>
29 #include <lsp-plug.in/io/OutBitStream.h>
30 #include <lsp-plug.in/lltl/darray.h>
31 #include <lsp-plug.in/lltl/parray.h>
32 #include <lsp-plug.in/resource/ILoader.h>
33 #include <lsp-plug.in/resource/buffer.h>
34 #include <lsp-plug.in/resource/OutProxyStream.h>
35
36 namespace lsp
37 {
38 namespace resource
39 {
40 /**
41 * Interface for resource compressor
42 */
43 class Compressor
44 {
45 protected:
46 lltl::darray<raw_resource_t> vEntries;
47 io::OutMemoryStream sTemp; // Temporary buffer
48 OutProxyStream sOS; // Output stream
49 io::OutBitStream sOut; // Output bit stream
50 size_t nSegment; // Start of data segment
51 size_t nOffset; // Current offset in segment
52 cbuffer_t sBuffer; // Buffer for caching
53
54 protected:
55 status_t alloc_entry(raw_resource_t **r, io::Path *path, resource_type_t type);
56 wssize_t write_entry(raw_resource_t *r, io::IInStream *is);
57 static size_t calc_repeats(const uint8_t *head, const uint8_t *tail);
58 status_t emit_uint(size_t value, size_t initial, size_t stepping);
59 static size_t est_uint(size_t value, size_t initial, size_t stepping);
60
61 public:
62 explicit Compressor();
63 Compressor(const Compressor &) = delete;
64 Compressor(Compressor &&) = delete;
65 ~Compressor();
66
67 Compressor & operator = (const Compressor &) = delete;
68 Compressor & operator = (Compressor &&) = delete;
69
70 public:
71 /**
72 * Close the compressor
73 * @return status of operation
74 */
75 status_t close();
76
77 /**
78 * Initialize compressor
79 * @param log_buf_size logarithmic buffer size
80 * @param os output stream
81 * @param flags flags
82 * @return status of operation
83 */
84 status_t init(size_t log_buf_size, io::IOutStream *os, size_t flags = WRAP_NONE);
85
86 public:
87 /**
88 * Get all resource entries
89 * @return all resource entries
90 */
91 inline const raw_resource_t *entries() const { return vEntries.array(); }
92
93 /**
94 * Get number of resource entries
95 * @return number of resource entries
96 */
97 inline size_t num_entires() const { return vEntries.size(); }
98
99 /**
100 * Start a new segment of data. May be useful for sorting data by different types
101 * @return status of operation
102 */
103 status_t flush();
104
105 /**
106 * Create resource entry and start it's writing
107 * @param name resource entry name
108 * @param is input stream to read entry from
109 * @return number of bytes read from original stream or negative error code
110 */
111 wssize_t create_file(const char *name, io::IInStream *is);
112 wssize_t create_file(const LSPString *name, io::IInStream *is);
113 wssize_t create_file(const io::Path *name, io::IInStream *is);
114
115 /**
116 * Create directory
117 * @param name name of the directory
118 * @return status of operation
119 */
120 status_t create_dir(const char *name);
121 status_t create_dir(const LSPString *name);
122 status_t create_dir(const io::Path *name);
123 };
124
125 } /* namespace resource */
126 } /* namespace lsp */
127
128
129
130 #endif /* LSP_PLUG_IN_RESOURCE_ICOMPRESSOR_H_ */