/src/libheif/libheif/codecs/uncompressed/unc_decoder.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2023 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_UNC_DECODER_H |
22 | | #define LIBHEIF_UNC_DECODER_H |
23 | | |
24 | | #include <cstdint> |
25 | | #include <memory> |
26 | | #include <vector> |
27 | | |
28 | | #include "error.h" |
29 | | #include "unc_codec.h" |
30 | | #include "unc_boxes.h" |
31 | | |
32 | | class HeifPixelImage; |
33 | | struct DataExtent; |
34 | | struct heif_security_limits; |
35 | | |
36 | | |
37 | | class unc_decoder |
38 | | { |
39 | | public: |
40 | 866 | virtual ~unc_decoder() = default; |
41 | | |
42 | 693 | virtual void ensure_channel_list(std::shared_ptr<HeifPixelImage>& img) {} |
43 | | |
44 | | Error fetch_tile_data(const DataExtent& dataExtent, |
45 | | const UncompressedImageCodec::unci_properties& properties, |
46 | | uint32_t tile_x, uint32_t tile_y, |
47 | | std::vector<uint8_t>& tile_data); |
48 | | |
49 | | virtual Error decode_tile(const std::vector<uint8_t>& tile_data, |
50 | | std::shared_ptr<HeifPixelImage>& img, |
51 | | uint32_t out_x0, uint32_t out_y0) = 0; |
52 | | |
53 | | Error decode_image(const DataExtent& extent, |
54 | | const UncompressedImageCodec::unci_properties& properties, |
55 | | std::shared_ptr<HeifPixelImage>& img); |
56 | | |
57 | | static Result<std::shared_ptr<HeifPixelImage>> decode_full_image( |
58 | | const UncompressedImageCodec::unci_properties& properties, |
59 | | const DataExtent& extent, |
60 | | const heif_security_limits* limits); |
61 | | |
62 | | protected: |
63 | | unc_decoder(uint32_t width, uint32_t height, |
64 | | const std::shared_ptr<const Box_cmpd>& cmpd, |
65 | | const std::shared_ptr<const Box_uncC>& uncC, |
66 | | const std::vector<uint32_t>& uncC_index_to_comp_ids); |
67 | | |
68 | | virtual Result<std::vector<uint64_t>> get_tile_data_sizes() const = 0; |
69 | | |
70 | | const Error get_compressed_image_data_uncompressed(const DataExtent& dataExtent, |
71 | | const UncompressedImageCodec::unci_properties& properties, |
72 | | std::vector<uint8_t>* data, |
73 | | uint64_t range_start_offset, uint64_t range_size, |
74 | | uint32_t tile_idx, |
75 | | const Box_iloc::Item* item) const; |
76 | | |
77 | | Result<std::vector<uint8_t>> do_decompress_data(std::shared_ptr<const Box_cmpC>& cmpC_box, |
78 | | std::vector<uint8_t> compressed_data) const; |
79 | | |
80 | | const uint32_t m_width; |
81 | | const uint32_t m_height; |
82 | | const std::shared_ptr<const Box_cmpd> m_cmpd; |
83 | | const std::shared_ptr<const Box_uncC> m_uncC; |
84 | | const std::vector<uint32_t> m_uncC_index_to_comp_ids; |
85 | | uint32_t m_tile_height; |
86 | | uint32_t m_tile_width; |
87 | | }; |
88 | | |
89 | | |
90 | | class unc_decoder_factory |
91 | | { |
92 | | public: |
93 | 0 | virtual ~unc_decoder_factory() = default; |
94 | | |
95 | | static Result<std::unique_ptr<unc_decoder>> get_unc_decoder( |
96 | | uint32_t width, uint32_t height, |
97 | | const std::shared_ptr<const Box_cmpd>& cmpd, |
98 | | const std::shared_ptr<const Box_uncC>& uncC, |
99 | | const std::vector<uint32_t>& uncC_index_to_comp_ids); |
100 | | |
101 | | protected: |
102 | | static bool check_common_requirements(const std::shared_ptr<const Box_uncC>& uncC); |
103 | | |
104 | | static bool has_any_multi_byte_components(const std::shared_ptr<const Box_uncC>& uncC); |
105 | | |
106 | | virtual bool can_decode(const std::shared_ptr<const Box_uncC>& uncC) const = 0; |
107 | | |
108 | | virtual std::unique_ptr<unc_decoder> create( |
109 | | uint32_t width, uint32_t height, |
110 | | const std::shared_ptr<const Box_cmpd>& cmpd, |
111 | | const std::shared_ptr<const Box_uncC>& uncC, |
112 | | const std::vector<uint32_t>& uncC_index_to_comp_ids) const = 0; |
113 | | }; |
114 | | |
115 | | #endif |