/src/libheif/libheif/text.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2023 Dirk Farin <dirk.farin@gmail.com> |
4 | | * Copyright (c) 2025 Brad Hards <bradh@frogmouth.net> |
5 | | * |
6 | | * This file is part of libheif. |
7 | | * |
8 | | * libheif is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as |
10 | | * published by the Free Software Foundation, either version 3 of |
11 | | * the License, or (at your option) any later version. |
12 | | * |
13 | | * libheif 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 libheif. If not, see <http://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #ifndef LIBHEIF_TEXT_H |
23 | | #define LIBHEIF_TEXT_H |
24 | | |
25 | | #include <cstring> |
26 | | #include <memory> |
27 | | #include <mutex> |
28 | | #include <string_view> |
29 | | #include <utility> |
30 | | #include <vector> |
31 | | #include "error.h" |
32 | | #include "libheif/heif_text.h" |
33 | | #include "security_limits.h" |
34 | | |
35 | | class HeifFile; |
36 | | |
37 | | class TextItem |
38 | | { |
39 | | public: |
40 | | TextItem() = default; |
41 | | |
42 | 0 | TextItem(heif_item_id itemId, const char *text) : m_item_id(itemId) |
43 | 0 | { |
44 | 0 | m_data.assign(text, text + std::strlen(text)); |
45 | 0 | } |
46 | | |
47 | | TextItem(heif_item_id itemId, std::shared_ptr<HeifFile> file) |
48 | 0 | : m_item_id(itemId), m_source(std::move(file)) {} |
49 | | |
50 | | Error parse(std::vector<uint8_t>&& data, const heif_security_limits* limits); |
51 | | |
52 | | Result<std::vector<uint8_t>> encode() const; |
53 | | |
54 | 0 | heif_item_id get_item_id() const { |
55 | 0 | return m_item_id; |
56 | 0 | } |
57 | | |
58 | 0 | void set_item_id(heif_item_id id) { |
59 | 0 | m_item_id = id; |
60 | 0 | } |
61 | | |
62 | | Result<std::string_view> get_item_text(size_t max_output_size = SIZE_MAX); |
63 | | |
64 | | private: |
65 | | heif_item_id m_item_id = 0; |
66 | | MemoryHandle m_memory_handle; |
67 | | std::vector<uint8_t> m_data; |
68 | | std::shared_ptr<HeifFile> m_source; |
69 | | std::mutex m_load_mutex; |
70 | | }; |
71 | | |
72 | | #endif // LIBHEIF_TEXT_H |