|
| 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 | + * @param charset character set encoding of the file |
| 87 | + * @return status of operation |
| 88 | + */ |
| 89 | + status_t parse_file(IObjHandler *handler, const char *path); |
| 90 | + |
| 91 | + /** |
| 92 | + * Parse compressed OBJ file |
| 93 | + * @param handler Wavefront Object file handler |
| 94 | + * @param path path to the file |
| 95 | + * @param charset character set encoding of the file |
| 96 | + * @return status of operation |
| 97 | + */ |
| 98 | + status_t parse_file(IObjHandler *handler, const LSPString *path); |
| 99 | + |
| 100 | + /** |
| 101 | + * Parse compressed OBJ file |
| 102 | + * @param handler Wavefront Object file handler |
| 103 | + * @param path path to the file |
| 104 | + * @param charset character set encoding of the file |
| 105 | + * @return status of operation |
| 106 | + */ |
| 107 | + status_t parse_file(IObjHandler *handler, const io::Path *path); |
| 108 | + |
| 109 | + /** |
| 110 | + * Parse compressed OBJ data from input stream |
| 111 | + * @param handler Wavefront Object file handler |
| 112 | + * @param is input stream |
| 113 | + * @param flags wrap flags |
| 114 | + * @param charset character set |
| 115 | + * @return status of operation |
| 116 | + */ |
| 117 | + status_t parse_data(IObjHandler *handler, io::IInStream *is, size_t flags = WRAP_NONE); |
| 118 | + |
| 119 | + /** |
| 120 | + * Parse compressed OBJ data from memory |
| 121 | + * @param handler Wavefront Object file handler |
| 122 | + * @param data byte buffer |
| 123 | + * @param size size of byte buffer |
| 124 | + * @return status of operation |
| 125 | + */ |
| 126 | + status_t parse_data(IObjHandler *handler, const void *data, size_t size); |
| 127 | + }; |
| 128 | + |
| 129 | + } /* namespace obj */ |
| 130 | +} /* namespace lsp */ |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | +#endif /* LSP_PLUG_IN_FMT_OBJ_DECOMPRESSOR_H_ */ |
0 commit comments