/src/libheif/libheif/mdat_data.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2024 Dirk Farin <dirk.farin@gmail.com> |
4 | | * |
5 | | * This file is part of libheif. |
6 | | * |
7 | | * libheif is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libheif is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libheif. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #ifndef LIBHEIF_MDAT_DATA_H |
22 | | #define LIBHEIF_MDAT_DATA_H |
23 | | |
24 | | #include <cstdint> |
25 | | #include <vector> |
26 | | #include <cassert> |
27 | | #include <algorithm> |
28 | | |
29 | | |
30 | | class MdatData |
31 | | { |
32 | | public: |
33 | 0 | virtual ~MdatData() = default; |
34 | | |
35 | | // returns the start position of the appended data |
36 | | virtual size_t append_data(const std::vector<uint8_t>& data) = 0; |
37 | | |
38 | | virtual size_t get_data_size() const = 0; |
39 | | |
40 | | virtual Error write(StreamWriter&) = 0; |
41 | | }; |
42 | | |
43 | | |
44 | | class MdatData_Memory : public MdatData |
45 | | { |
46 | | public: |
47 | 0 | size_t append_data(const std::vector<uint8_t>& data) override { |
48 | 0 | size_t startPos = m_data.size(); |
49 | 0 | m_data.insert(m_data.end(), data.begin(), data.end()); |
50 | 0 | return startPos; |
51 | 0 | } |
52 | | |
53 | 0 | size_t get_data_size() const override { return m_data.size(); } |
54 | | |
55 | | Error write(StreamWriter& writer) override |
56 | 0 | { |
57 | 0 | writer.write(m_data); |
58 | 0 | return Error::Ok; |
59 | 0 | } |
60 | | |
61 | | private: |
62 | | std::vector<uint8_t> m_data; |
63 | | }; |
64 | | |
65 | | #endif //LIBHEIF_MDAT_DATA_H |