Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/obj/Decompressor.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: 26 июл. 2025 г.
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_FMT_OBJ_DECOMPRESSOR_H_
23 #define LSP_PLUG_IN_FMT_OBJ_DECOMPRESSOR_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/fmt/obj/const.h>
27 #include <lsp-plug.in/fmt/obj/PullParser.h>
28 #include <lsp-plug.in/fmt/obj/IObjHandler.h>
29 #include <lsp-plug.in/io/InBitStream.h>
30
31 namespace lsp
32 {
33 namespace obj
34 {
35
36 class Decompressor
37 {
38 protected:
39 io::InBitStream sStream;
40 union
41 {
42 float *vFloatBuf;
43 uint32_t *vIntBuf;
44 };
45
46 uint32_t nFloatHead;
47 uint32_t nFloatSize;
48 uint32_t nFloatCap;
49 uint32_t nFloatBits;
50
51 compressed_event_type_t nLastEvent;
52
53 protected:
54 status_t parse_data(IObjHandler *handler);
55 status_t parse_header();
56 void clear_state();
57 status_t read_event(compressed_event_type_t *event);
58 status_t parse_vertex(IObjHandler *handler, size_t coords);
59 status_t parse_pvertex(IObjHandler *handler, size_t coords);
60 status_t parse_normal(IObjHandler *handler, size_t coords);
61 status_t parse_texcoord(IObjHandler *handler, size_t coords);
62 status_t parse_face(IObjHandler *handler, bool texcoords, bool normals, bool fill);
63 status_t parse_line(IObjHandler *handler, bool texcoords);
64 status_t parse_points(IObjHandler *handler);
65 status_t parse_object(IObjHandler *handler);
66 status_t read_float(float *dst);
67 status_t read_varint(size_t *dst);
68 status_t read_varint_icount(size_t *dst);
69 status_t read_indices(index_t *dst, size_t count, bool read);
70 status_t read_utf8(LSPString *dst);
71
72 public:
73 explicit Decompressor();
74 Decompressor(const Decompressor &) = delete;
75 Decompressor(Decompressor &&) = delete;
76 virtual ~Decompressor();
77
78 Decompressor & operator = (const Decompressor &) = delete;
79 Decompressor & operator = (Decompressor &&) = delete;
80
81 public:
82 /**
83 * Parse compressed OBJ file
84 * @param handler Wavefront Object file handler
85 * @param path UTF-8 path to the file
86 * @return status of operation
87 */
88 status_t parse_file(IObjHandler *handler, const char *path);
89
90 /**
91 * Parse compressed OBJ file
92 * @param handler Wavefront Object file handler
93 * @param path path to the file
94 * @return status of operation
95 */
96 status_t parse_file(IObjHandler *handler, const LSPString *path);
97
98 /**
99 * Parse compressed OBJ file
100 * @param handler Wavefront Object file handler
101 * @param path path to the file
102 * @return status of operation
103 */
104 status_t parse_file(IObjHandler *handler, const io::Path *path);
105
106 /**
107 * Parse compressed OBJ data from input stream
108 * @param handler Wavefront Object file handler
109 * @param is input stream
110 * @param flags wrap flags
111 * @return status of operation
112 */
113 status_t parse_data(IObjHandler *handler, io::IInStream *is, size_t flags = WRAP_NONE);
114
115 /**
116 * Parse compressed OBJ data from memory
117 * @param handler Wavefront Object file handler
118 * @param data byte buffer
119 * @param size size of byte buffer
120 * @return status of operation
121 */
122 status_t parse_data(IObjHandler *handler, const void *data, size_t size);
123 };
124
125 } /* namespace obj */
126 } /* namespace lsp */
127
128
129
130 #endif /* LSP_PLUG_IN_FMT_OBJ_DECOMPRESSOR_H_ */