/src/libheif/libheif/codecs/uncompressed/unc_boxes.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
22 | | #ifndef LIBHEIF_UNC_BOXES_H |
23 | | #define LIBHEIF_UNC_BOXES_H |
24 | | |
25 | | #include "box.h" |
26 | | #include "bitstream.h" |
27 | | #include "unc_types.h" |
28 | | #include "sequences/seq_boxes.h" |
29 | | |
30 | | #include <cstdint> |
31 | | #include <string> |
32 | | #include <vector> |
33 | | #include <memory> |
34 | | |
35 | | |
36 | | /** |
37 | | * Component definition (cmpd) box. |
38 | | */ |
39 | | class Box_cmpd : public Box |
40 | | { |
41 | | public: |
42 | | Box_cmpd() |
43 | 153 | { |
44 | 153 | set_short_type(fourcc("cmpd")); |
45 | 153 | } |
46 | | |
47 | | std::string dump(Indent&) const override; |
48 | | |
49 | | Error write(StreamWriter& writer) const override; |
50 | | |
51 | | struct Component |
52 | | { |
53 | | uint16_t component_type; |
54 | | std::string component_type_uri; |
55 | | |
56 | 0 | std::string get_component_type_name() const { return get_component_type_name(component_type); } |
57 | | |
58 | | static std::string get_component_type_name(uint16_t type); |
59 | | }; |
60 | | |
61 | 0 | const std::vector<Component>& get_components() const { return m_components; } |
62 | | |
63 | | void add_component(const Component& component) |
64 | 0 | { |
65 | 0 | m_components.push_back(component); |
66 | 0 | } |
67 | | |
68 | | protected: |
69 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
70 | | |
71 | | std::vector<Component> m_components; |
72 | | }; |
73 | | |
74 | | /** |
75 | | * Uncompressed Frame Configuration Box |
76 | | */ |
77 | | class Box_uncC : public FullBox |
78 | | { |
79 | | public: |
80 | 71 | Box_uncC() { |
81 | 71 | set_short_type(fourcc("uncC")); |
82 | 71 | } |
83 | | |
84 | 0 | bool is_essential() const override { return true; } |
85 | | |
86 | 0 | void derive_box_version() override {}; |
87 | | |
88 | | std::string dump(Indent&) const override; |
89 | | |
90 | | Error write(StreamWriter& writer) const override; |
91 | | |
92 | | struct Component |
93 | | { |
94 | | uint16_t component_index; |
95 | | uint16_t component_bit_depth; // range [1..256] |
96 | | uint8_t component_format; |
97 | | uint8_t component_align_size; |
98 | | }; |
99 | | |
100 | 0 | const std::vector<Component>& get_components() const { return m_components; } |
101 | | |
102 | | void add_component(Component component) |
103 | 0 | { |
104 | 0 | m_components.push_back(component); |
105 | 0 | } |
106 | | |
107 | 0 | uint32_t get_profile() const { return m_profile; } |
108 | | |
109 | | void set_profile(const uint32_t profile) |
110 | 0 | { |
111 | 0 | m_profile = profile; |
112 | 0 | } |
113 | | |
114 | 0 | uint8_t get_sampling_type() const { return m_sampling_type; } |
115 | | |
116 | | void set_sampling_type(const uint8_t sampling_type) |
117 | 0 | { |
118 | 0 | m_sampling_type = sampling_type; |
119 | 0 | } |
120 | | |
121 | 0 | uint8_t get_interleave_type() const { return m_interleave_type; } |
122 | | |
123 | | void set_interleave_type(const uint8_t interleave_type) |
124 | 0 | { |
125 | 0 | m_interleave_type = interleave_type; |
126 | 0 | } |
127 | | |
128 | 0 | uint8_t get_block_size() const { return m_block_size; } |
129 | | |
130 | | void set_block_size(const uint8_t block_size) |
131 | 0 | { |
132 | 0 | m_block_size = block_size; |
133 | 0 | } |
134 | | |
135 | 0 | bool is_components_little_endian() const { return m_components_little_endian; } |
136 | | |
137 | | void set_components_little_endian (const bool components_little_endian) |
138 | 0 | { |
139 | 0 | m_components_little_endian = components_little_endian; |
140 | 0 | } |
141 | | |
142 | 0 | bool is_block_pad_lsb() const { return m_block_pad_lsb; } |
143 | | |
144 | | void set_block_pad_lsb(const bool block_pad_lsb) |
145 | 0 | { |
146 | 0 | m_block_pad_lsb = block_pad_lsb; |
147 | 0 | } |
148 | | |
149 | 0 | bool is_block_little_endian() const { return m_block_little_endian; } |
150 | | |
151 | | void set_block_little_endian(const bool block_little_endian) |
152 | 0 | { |
153 | 0 | m_block_little_endian = block_little_endian; |
154 | 0 | } |
155 | | |
156 | 0 | bool is_block_reversed() const { return m_block_reversed; } |
157 | | |
158 | | void set_block_reversed(const bool block_reversed) |
159 | 0 | { |
160 | 0 | m_block_reversed = block_reversed; |
161 | 0 | } |
162 | | |
163 | 0 | bool is_pad_unknown() const { return m_pad_unknown; } |
164 | | |
165 | | void set_pad_unknown(const bool pad_unknown) |
166 | 0 | { |
167 | 0 | m_pad_unknown = pad_unknown; |
168 | 0 | } |
169 | | |
170 | 0 | uint32_t get_pixel_size() const { return m_pixel_size; } |
171 | | |
172 | | void set_pixel_size(const uint32_t pixel_size) |
173 | 0 | { |
174 | 0 | m_pixel_size = pixel_size; |
175 | 0 | } |
176 | | |
177 | 0 | uint32_t get_row_align_size() const { return m_row_align_size; } |
178 | | |
179 | | void set_row_align_size(const uint32_t row_align_size) |
180 | 0 | { |
181 | 0 | m_row_align_size = row_align_size; |
182 | 0 | } |
183 | | |
184 | 0 | uint32_t get_tile_align_size() const { return m_tile_align_size; } |
185 | | |
186 | | void set_tile_align_size(const uint32_t tile_align_size) |
187 | 0 | { |
188 | 0 | m_tile_align_size = tile_align_size; |
189 | 0 | } |
190 | | |
191 | 0 | uint32_t get_number_of_tile_columns() const { return m_num_tile_cols; } |
192 | | |
193 | | void set_number_of_tile_columns(const uint32_t num_tile_cols) |
194 | 0 | { |
195 | 0 | m_num_tile_cols = num_tile_cols; |
196 | 0 | } |
197 | | |
198 | 0 | uint32_t get_number_of_tile_rows() const { return m_num_tile_rows; } |
199 | | |
200 | | void set_number_of_tile_rows(const uint32_t num_tile_rows) |
201 | 0 | { |
202 | 0 | m_num_tile_rows = num_tile_rows; |
203 | 0 | } |
204 | | |
205 | 0 | uint32_t get_number_of_tiles() const { return m_num_tile_rows * m_num_tile_rows; } |
206 | | |
207 | | uint64_t compute_tile_data_size_bytes(uint32_t tile_width, uint32_t tile_height) const; |
208 | | |
209 | | protected: |
210 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
211 | | |
212 | | uint32_t m_profile = 0; // 0 = not compliant to any profile |
213 | | |
214 | | std::vector<Component> m_components; |
215 | | uint8_t m_sampling_type = sampling_mode_no_subsampling; // no subsampling |
216 | | uint8_t m_interleave_type = interleave_mode_pixel; // component interleaving |
217 | | uint8_t m_block_size = 0; |
218 | | bool m_components_little_endian = false; |
219 | | bool m_block_pad_lsb = false; |
220 | | bool m_block_little_endian = false; |
221 | | bool m_block_reversed = false; |
222 | | bool m_pad_unknown = false; |
223 | | uint32_t m_pixel_size = 0; |
224 | | uint32_t m_row_align_size = 0; |
225 | | uint32_t m_tile_align_size = 0; |
226 | | uint32_t m_num_tile_cols = 1; |
227 | | uint32_t m_num_tile_rows = 1; |
228 | | }; |
229 | | |
230 | | |
231 | | enum heif_cmpC_compressed_unit_type { |
232 | | heif_cmpC_compressed_unit_type_full_item = 0, |
233 | | heif_cmpC_compressed_unit_type_image = 1, |
234 | | heif_cmpC_compressed_unit_type_image_tile = 2, |
235 | | heif_cmpC_compressed_unit_type_image_row = 3, |
236 | | heif_cmpC_compressed_unit_type_image_pixel = 4 |
237 | | }; |
238 | | |
239 | | /** |
240 | | * Generic compression configuration box (cmpC). |
241 | | * |
242 | | * This is from ISO/IEC 23001-17 Amd 2. |
243 | | */ |
244 | | class Box_cmpC : public FullBox |
245 | | { |
246 | | public: |
247 | | Box_cmpC() |
248 | 15 | { |
249 | 15 | set_short_type(fourcc("cmpC")); |
250 | 15 | } |
251 | | |
252 | | std::string dump(Indent&) const override; |
253 | | |
254 | 0 | uint32_t get_compression_type() const { return m_compression_type; } |
255 | | |
256 | 0 | heif_cmpC_compressed_unit_type get_compressed_unit_type() const { return m_compressed_unit_type; } |
257 | | |
258 | 0 | void set_compression_type(uint32_t type) { m_compression_type = type; } |
259 | | |
260 | 0 | void set_compressed_unit_type(heif_cmpC_compressed_unit_type type) { m_compressed_unit_type = type; } |
261 | | |
262 | | Error write(StreamWriter& writer) const override; |
263 | | |
264 | | protected: |
265 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
266 | | |
267 | | uint32_t m_compression_type = 0; |
268 | | heif_cmpC_compressed_unit_type m_compressed_unit_type = heif_cmpC_compressed_unit_type_full_item; |
269 | | }; |
270 | | |
271 | | /** |
272 | | * Generically compressed units item info (icef). |
273 | | * |
274 | | * This describes the units of compressed data for an item. |
275 | | * |
276 | | * The box is from ISO/IEC 23001-17 Amd 2. |
277 | | */ |
278 | | class Box_icef : public FullBox |
279 | | { |
280 | | public: |
281 | | Box_icef() |
282 | 276 | { |
283 | 276 | set_short_type(fourcc("icef")); |
284 | 276 | } |
285 | | |
286 | | struct CompressedUnitInfo |
287 | | { |
288 | | uint64_t unit_offset = 0; |
289 | | uint64_t unit_size = 0; |
290 | | }; |
291 | | |
292 | 0 | const std::vector<CompressedUnitInfo>& get_units() const { return m_unit_infos; } |
293 | | |
294 | | void add_component(const CompressedUnitInfo& unit_info) |
295 | 0 | { |
296 | 0 | m_unit_infos.push_back(unit_info); |
297 | 0 | } |
298 | | |
299 | | void set_component(uint32_t tile_idx, const CompressedUnitInfo& unit_info) |
300 | 0 | { |
301 | 0 | if (tile_idx >= m_unit_infos.size()) { |
302 | 0 | m_unit_infos.resize(tile_idx+1); |
303 | 0 | } |
304 | |
|
305 | 0 | m_unit_infos[tile_idx] = unit_info; |
306 | 0 | } |
307 | | |
308 | | std::string dump(Indent&) const override; |
309 | | |
310 | | Error write(StreamWriter& writer) const override; |
311 | | |
312 | | protected: |
313 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
314 | | |
315 | | std::vector<CompressedUnitInfo> m_unit_infos; |
316 | | |
317 | | private: |
318 | | const uint8_t get_required_offset_code(uint64_t offset) const; |
319 | | const uint8_t get_required_size_code(uint64_t size) const; |
320 | | }; |
321 | | |
322 | | |
323 | | /** |
324 | | * Component pattern definition box (cpat). |
325 | | * |
326 | | * The component pattern is used when representing filter array |
327 | | * data, such as Bayer. It defines the filter mask in the raw |
328 | | * data. |
329 | | * |
330 | | * This is from ISO/IEC 23001-17 Section 6.1.3. |
331 | | */ |
332 | | class Box_cpat : public FullBox |
333 | | { |
334 | | public: |
335 | | Box_cpat() |
336 | 73 | { |
337 | 73 | set_short_type(fourcc("cpat")); |
338 | 73 | } |
339 | | |
340 | | struct PatternComponent |
341 | | { |
342 | | uint32_t component_index; |
343 | | float component_gain; |
344 | | }; |
345 | | |
346 | | uint16_t get_pattern_width() const |
347 | 0 | { |
348 | 0 | return m_pattern_width; |
349 | 0 | } |
350 | | |
351 | | uint16_t get_pattern_height() const |
352 | 0 | { |
353 | 0 | return m_pattern_height; |
354 | 0 | } |
355 | | |
356 | | std::string dump(Indent&) const override; |
357 | | |
358 | | Error write(StreamWriter& writer) const override; |
359 | | |
360 | | protected: |
361 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
362 | | |
363 | | uint16_t m_pattern_width = 0; |
364 | | uint16_t m_pattern_height = 0; |
365 | | std::vector<PatternComponent> m_components; |
366 | | }; |
367 | | |
368 | | |
369 | | class Box_uncv : public Box_VisualSampleEntry |
370 | | { |
371 | | public: |
372 | | Box_uncv() |
373 | 3 | { |
374 | 3 | set_short_type(fourcc("uncv")); |
375 | 3 | } |
376 | | }; |
377 | | |
378 | | |
379 | | #endif //LIBHEIF_UNC_BOXES_H |