| 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: 23 июл. 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_COMPRESSOR_H_ |
| 23 |
#define LSP_PLUG_IN_FMT_OBJ_COMPRESSOR_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/io/File.h> |
| 27 |
#include <lsp-plug.in/io/IOutStream.h> |
| 28 |
#include <lsp-plug.in/io/OutBitStream.h> |
| 29 |
|
| 30 |
#include <lsp-plug.in/fmt/obj/const.h> |
| 31 |
#include <lsp-plug.in/fmt/obj/IObjHandler.h> |
| 32 |
|
| 33 |
namespace lsp |
| 34 |
{ |
| 35 |
namespace obj |
| 36 |
{ |
| 37 |
/** |
| 38 |
* OBJ format compressor |
| 39 |
*/ |
| 40 |
class Compressor: public IObjHandler |
| 41 |
{ |
| 42 |
protected: |
| 43 |
io::OutBitStream *pOut; |
| 44 |
|
| 45 |
union |
| 46 |
{ |
| 47 |
float *vFloatBuf; |
| 48 |
uint32_t *vIntBuf; |
| 49 |
}; |
| 50 |
|
| 51 |
uint32_t nFloatHead; |
| 52 |
uint32_t nFloatSize; |
| 53 |
uint32_t nFloatCap; |
| 54 |
uint32_t nFloatBits; |
| 55 |
|
| 56 |
uint32_t nLastEvent; |
| 57 |
|
| 58 |
size_t nWFlags; |
| 59 |
|
| 60 |
protected: |
| 61 |
status_t do_wrap(io::OutBitStream * & obs, size_t flags = WRAP_CLOSE | WRAP_DELETE); |
| 62 |
status_t write_varint(size_t value); |
| 63 |
status_t write_varint_icount(size_t value); |
| 64 |
status_t write_float(float value); |
| 65 |
inline status_t write_indices(const index_t *value, size_t count); |
| 66 |
inline status_t write_event(uint32_t event); |
| 67 |
inline status_t write_utf8(const char *text); |
| 68 |
static bool has_nonempty_index(const index_t *v, size_t count); |
| 69 |
static bool has_equal_indices(const index_t *v, size_t count); |
| 70 |
|
| 71 |
public: |
| 72 |
Compressor(); |
| 73 |
Compressor(const Compressor &) = delete; |
| 74 |
Compressor(Compressor &&) = delete; |
| 75 |
virtual ~Compressor() override; |
| 76 |
|
| 77 |
Compressor & operator = (const Compressor &) = delete; |
| 78 |
Compressor & operator = (Compressor &&) = delete; |
| 79 |
|
| 80 |
public: |
| 81 |
status_t open(const char *path, size_t mode); |
| 82 |
status_t open(const LSPString *path, size_t mode); |
| 83 |
status_t open(const io::Path *path, size_t mode); |
| 84 |
|
| 85 |
status_t wrap(FILE *fd, bool close); |
| 86 |
status_t wrap_native(fhandle_t fd, bool close); |
| 87 |
status_t wrap(io::File *fd, size_t flags = 0); |
| 88 |
status_t wrap(io::IOutStream *os, size_t flags = 0); |
| 89 |
status_t wrap(io::OutBitStream *obs, size_t flags = 0); |
| 90 |
|
| 91 |
status_t close(); |
| 92 |
|
| 93 |
public: |
| 94 |
/** |
| 95 |
* Set buffer size |
| 96 |
* @param float_bits number of bits to encode floating-point number (and logarithm of the buffer size) |
| 97 |
* @return status of operation |
| 98 |
*/ |
| 99 |
status_t set_buffer_size(size_t float_bits); |
| 100 |
|
| 101 |
public: |
| 102 |
virtual status_t begin_object(const char *name) override; |
| 103 |
virtual status_t begin_object(const LSPString *name) override; |
| 104 |
virtual status_t end_object() override; |
| 105 |
virtual status_t end_of_data() override; |
| 106 |
virtual ssize_t add_vertex(float x, float y, float z, float w) override; |
| 107 |
virtual ssize_t add_param_vertex(float x, float y, float z, float w) override; |
| 108 |
virtual ssize_t add_normal(float nx, float ny, float nz, float nw) override; |
| 109 |
virtual ssize_t add_texture_vertex(float u, float v, float w) override; |
| 110 |
virtual ssize_t add_face(const index_t *vv, const index_t *vn, const index_t *vt, size_t n) override; |
| 111 |
virtual ssize_t add_points(const index_t *vv, size_t n) override; |
| 112 |
virtual ssize_t add_line(const index_t *vv, const index_t *vt, size_t n) override; |
| 113 |
}; |
| 114 |
|
| 115 |
} /* namespace obj */ |
| 116 |
} /* namespace lsp */ |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
#endif /* LSP_PLUG_IN_FMT_OBJ_COMPRESSOR_H_ */ |