Debian Codegraph @

tests/uncompressed_box.cc

raw
1 /*
2 libheif uncompressed box unit tests
3
4 MIT License
5
6 Copyright (c) 2023 Brad Hards <[email protected]>
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25 */
26
27 #include "catch_amalgamated.hpp"
28 #include "box.h"
29 #include "libheif/heif.h"
30 #include "codecs/uncompressed/unc_types.h"
31 #include "codecs/uncompressed/unc_boxes.h"
32 #include <cstdint>
33 #include <iostream>
34
35
36 TEST_CASE( "cmpd" )
37 {
38 std::shared_ptr<Box_cmpd> cmpd = std::make_shared<Box_cmpd>();
39 REQUIRE(cmpd->get_components().size() == 0);
40 Box_cmpd::Component component;
41 component.component_type = 1;
42 cmpd->add_component(component);
43 REQUIRE(cmpd->get_components().size() == 1);
44 REQUIRE(cmpd->get_components()[0].component_type == 1);
45 REQUIRE(cmpd->get_components()[0].component_type_uri == "");
46 REQUIRE(cmpd->get_components()[0].get_component_type_name() == "Y\n");
47
48 StreamWriter writer;
49 Error err = cmpd->write(writer);
50 REQUIRE(err.error_code == heif_error_Ok);
51 const std::vector<uint8_t> bytes = writer.get_data();
52 std::vector<uint8_t> expected = {0x00, 0x00, 0x00, 0x0e, 'c', 'm', 'p', 'd', 0x00, 0x00, 0x00, 0x01, 0x00, 0x01};
53 REQUIRE(bytes == expected);
54
55 Indent indent;
56 std::string dump_output = cmpd->dump(indent);
57 REQUIRE(dump_output == "Box: cmpd -----\nsize: 0 (header size: 0)\ncomponent_type: Y\n");
58 }
59
60 TEST_CASE( "cmpd_multi" )
61 {
62 std::shared_ptr<Box_cmpd> cmpd = std::make_shared<Box_cmpd>();
63 REQUIRE(cmpd->get_components().size() == 0);
64
65 Box_cmpd::Component red_component;
66 red_component.component_type = 4;
67 cmpd->add_component(red_component);
68
69 Box_cmpd::Component green_component;
70 green_component.component_type = 5;
71 cmpd->add_component(green_component);
72
73 Box_cmpd::Component blue_component;
74 blue_component.component_type = 6;
75 cmpd->add_component(blue_component);
76 REQUIRE(cmpd->get_components().size() == 3);
77 REQUIRE(cmpd->get_components()[0].component_type == 4);
78 REQUIRE(cmpd->get_components()[0].component_type_uri == "");
79 REQUIRE(cmpd->get_components()[0].get_component_type_name() == "red\n");
80 REQUIRE(cmpd->get_components()[1].component_type == 5);
81 REQUIRE(cmpd->get_components()[1].component_type_uri == "");
82 REQUIRE(cmpd->get_components()[1].get_component_type_name() == "green\n");
83 REQUIRE(cmpd->get_components()[2].component_type == 6);
84 REQUIRE(cmpd->get_components()[2].component_type_uri == "");
85 REQUIRE(cmpd->get_components()[2].get_component_type_name() == "blue\n");
86
87 StreamWriter writer;
88 Error err = cmpd->write(writer);
89 REQUIRE(err.error_code == heif_error_Ok);
90 const std::vector<uint8_t> bytes = writer.get_data();
91 std::vector<uint8_t> expected = {0x00, 0x00, 0x00, 0x12, 'c', 'm', 'p', 'd', 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06};
92 REQUIRE(bytes == expected);
93
94 Indent indent;
95 std::string dump_output = cmpd->dump(indent);
96 REQUIRE(dump_output == "Box: cmpd -----\nsize: 0 (header size: 0)\ncomponent_type: red\ncomponent_type: green\ncomponent_type: blue\n");
97 }
98
99 TEST_CASE( "cmpd_custom" )
100 {
101 std::shared_ptr<Box_cmpd> cmpd = std::make_shared<Box_cmpd>();
102 REQUIRE(cmpd->get_components().size() == 0);
103
104 Box_cmpd::Component component0;
105 component0.component_type = 0x8000;
106 component0.component_type_uri = "http://example.com/custom_component_uri";
107 cmpd->add_component(component0);
108
109 Box_cmpd::Component component1;
110 component1.component_type = 0x8002;
111 component1.component_type_uri = "http://example.com/another_custom_component_uri";
112 cmpd->add_component(component1);
113
114 REQUIRE(cmpd->get_components().size() == 2);
115 REQUIRE(cmpd->get_components()[0].component_type == 0x8000);
116 REQUIRE(cmpd->get_components()[0].component_type_uri == "http://example.com/custom_component_uri");
117 REQUIRE(cmpd->get_components()[0].get_component_type_name() == "0x8000\n");
118 REQUIRE(cmpd->get_components()[1].component_type == 0x8002);
119 REQUIRE(cmpd->get_components()[1].component_type_uri == "http://example.com/another_custom_component_uri");
120 REQUIRE(cmpd->get_components()[1].get_component_type_name() == "0x8002\n");
121 StreamWriter writer;
122 Error err = cmpd->write(writer);
123 REQUIRE(err.error_code == heif_error_Ok);
124 const std::vector<uint8_t> bytes = writer.get_data();
125 std::vector<uint8_t> expected = {0x00, 0x00, 0x00, 0x68, 'c', 'm', 'p', 'd', 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 'h', 't', 't', 'p', ':', '/', '/', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', '/', 'c', 'u', 's', 't', 'o', 'm', '_', 'c', 'o', 'm', 'p', 'o', 'n', 'e', 'n', 't', '_', 'u', 'r', 'i', 0x00, 0x80, 0x02, 'h', 't', 't', 'p', ':', '/', '/', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', '/', 'a', 'n', 'o', 't', 'h', 'e', 'r', '_', 'c', 'u', 's', 't', 'o', 'm', '_', 'c', 'o', 'm', 'p', 'o', 'n', 'e', 'n', 't', '_', 'u', 'r', 'i', 0x00};
126 REQUIRE(bytes == expected);
127
128 Indent indent;
129 std::string dump_output = cmpd->dump(indent);
130 REQUIRE(dump_output == "Box: cmpd -----\nsize: 0 (header size: 0)\ncomponent_type: 0x8000\n| component_type_uri: http://example.com/custom_component_uri\ncomponent_type: 0x8002\n| component_type_uri: http://example.com/another_custom_component_uri\n");
131 }
132
133 TEST_CASE( "uncC" )
134 {
135 std::shared_ptr<Box_uncC> uncC = std::make_shared<Box_uncC>();
136 uncC->set_profile(fourcc("rgba"));
137 REQUIRE(uncC->get_components().size() == 0);
138 Box_uncC::Component r;
139 r.component_index = 0;
140 r.component_bit_depth = 8;
141 r.component_format = component_format_unsigned;
142 r.component_align_size = 0;
143 uncC->add_component(r);
144 Box_uncC::Component g;
145 g.component_index = 1;
146 g.component_bit_depth = 8;
147 g.component_format = component_format_unsigned;
148 g.component_align_size = 0;
149 uncC->add_component(g);
150 Box_uncC::Component b;
151 b.component_index = 2;
152 b.component_bit_depth = 8;
153 b.component_format = component_format_unsigned;
154 b.component_align_size = 0;
155 uncC->add_component(b);
156 Box_uncC::Component a;
157 a.component_index = 3;
158 a.component_bit_depth = 8;
159 a.component_format = component_format_unsigned;
160 a.component_align_size = 0;
161 uncC->add_component(a);
162 uncC->set_sampling_type(sampling_mode_no_subsampling);
163 uncC->set_interleave_type(interleave_mode_pixel);
164
165 REQUIRE(uncC->get_components().size() == 4);
166 Box_uncC::Component component0 = uncC->get_components()[0];
167 REQUIRE(component0.component_index == 0);
168 REQUIRE(component0.component_bit_depth == 8);
169 REQUIRE(component0.component_format == 0);
170 REQUIRE(component0.component_align_size == 0);
171 Box_uncC::Component component1 = uncC->get_components()[1];
172 REQUIRE(component1.component_index == 1);
173 REQUIRE(component1.component_bit_depth == 8);
174 REQUIRE(component1.component_format == 0);
175 REQUIRE(component1.component_align_size == 0);
176 Box_uncC::Component component2 = uncC->get_components()[2];
177 REQUIRE(component2.component_index == 2);
178 REQUIRE(component2.component_bit_depth == 8);
179 REQUIRE(component2.component_format == 0);
180 REQUIRE(component2.component_align_size == 0);
181 Box_uncC::Component component3 = uncC->get_components()[3];
182 REQUIRE(component3.component_index == 3);
183 REQUIRE(component3.component_bit_depth == 8);
184 REQUIRE(component3.component_format == 0);
185 REQUIRE(component3.component_align_size == 0);
186 REQUIRE(uncC->get_sampling_type() == 0);
187 REQUIRE(uncC->get_interleave_type() == 1);
188 REQUIRE(uncC->get_block_size() == 0);
189 REQUIRE(uncC->is_components_little_endian() == false);
190 REQUIRE(uncC->is_block_pad_lsb() == false);
191 REQUIRE(uncC->is_block_little_endian() == false);
192 REQUIRE(uncC->is_pad_unknown() == false);
193 REQUIRE(uncC->get_pixel_size() == 0);
194 REQUIRE(uncC->get_row_align_size() == 0);
195 REQUIRE(uncC->get_tile_align_size() == 0);
196 REQUIRE(uncC->get_number_of_tile_columns() == 1);
197 REQUIRE(uncC->get_number_of_tile_rows() == 1);
198
199 StreamWriter writer;
200 Error err = uncC->write(writer);
201 REQUIRE(err.error_code == heif_error_Ok);
202 const std::vector<uint8_t> bytes = writer.get_data();
203 std::vector<uint8_t> expected = {
204 0x00, 0x00, 0x00, 0x40, 'u', 'n', 'c', 'C',
205 0x00, 0x00, 0x00, 0x00, 'r', 'g', 'b', 'a',
206 0x00, 0x00, 0x00, 0x04, 0, 0, 7, 0x00,
207 0x00, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x02,
208 0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00,
209 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
212 };
213 REQUIRE(bytes == expected);
214
215 Indent indent;
216 std::string dump_output = uncC->dump(indent);
217 REQUIRE(dump_output == "Box: uncC -----\nsize: 0 (header size: 0)\nprofile: 1919378017 (rgba)\ncomponent_index: 0\n| component_bit_depth: 8\n| component_format: unsigned\n| component_align_size: 0\ncomponent_index: 1\n| component_bit_depth: 8\n| component_format: unsigned\n| component_align_size: 0\ncomponent_index: 2\n| component_bit_depth: 8\n| component_format: unsigned\n| component_align_size: 0\ncomponent_index: 3\n| component_bit_depth: 8\n| component_format: unsigned\n| component_align_size: 0\nsampling_type: no subsampling\ninterleave_type: pixel\nblock_size: 0\ncomponents_little_endian: 0\nblock_pad_lsb: 0\nblock_little_endian: 0\nblock_reversed: 0\npad_unknown: 0\npixel_size: 0\nrow_align_size: 0\ntile_align_size: 0\nnum_tile_cols: 1\nnum_tile_rows: 1\n");
218 }
219
220 TEST_CASE("uncC_parse") {
221 std::vector<uint8_t> byteArray{
222 0x00, 0x00, 0x00, 0x40, 'u', 'n', 'c', 'C',
223 0x00, 0x00, 0x00, 0x00, 'r', 'g', 'b', 'a',
224 0x00, 0x00, 0x00, 0x04, 0, 0, 7, 0x00,
225 0x00, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x02,
226 0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00,
227 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
229 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02
230 };
231
232 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
233 byteArray.size(), false);
234
235 BitstreamRange range(reader, byteArray.size());
236 std::shared_ptr<Box> box;
237 Error error = Box::read(range, &box, heif_get_global_security_limits());
238 REQUIRE(error == Error::Ok);
239 REQUIRE(range.error() == 0);
240
241 REQUIRE(box->get_short_type() == fourcc("uncC"));
242 REQUIRE(box->get_type_string() == "uncC");
243 std::shared_ptr<Box_uncC> uncC = std::dynamic_pointer_cast<Box_uncC>(box);
244 REQUIRE(uncC->get_number_of_tile_columns() == 2);
245 REQUIRE(uncC->get_number_of_tile_rows() == 3);
246 Indent indent;
247 std::string dumpResult = box->dump(indent);
248 REQUIRE(dumpResult == "Box: uncC -----\n"
249 "size: 64 (header size: 12)\n"
250 "profile: 1919378017 (rgba)\n"
251 "component_index: 0\n"
252 "| component_bit_depth: 8\n"
253 "| component_format: unsigned\n"
254 "| component_align_size: 0\n"
255 "component_index: 1\n"
256 "| component_bit_depth: 8\n"
257 "| component_format: unsigned\n"
258 "| component_align_size: 0\n"
259 "component_index: 2\n"
260 "| component_bit_depth: 8\n"
261 "| component_format: unsigned\n"
262 "| component_align_size: 0\n"
263 "component_index: 3\n"
264 "| component_bit_depth: 8\n"
265 "| component_format: unsigned\n"
266 "| component_align_size: 0\n"
267 "sampling_type: no subsampling\n"
268 "interleave_type: pixel\n"
269 "block_size: 0\n"
270 "components_little_endian: 0\n"
271 "block_pad_lsb: 0\n"
272 "block_little_endian: 0\n"
273 "block_reversed: 0\n"
274 "pad_unknown: 0\n"
275 "pixel_size: 0\n"
276 "row_align_size: 0\n"
277 "tile_align_size: 0\n"
278 "num_tile_cols: 2\n"
279 "num_tile_rows: 3\n");
280 }
281
282 TEST_CASE("uncC_parse_no_overflow") {
283 std::vector<uint8_t> byteArray{
284 0x00, 0x00, 0x00, 0x40, 'u', 'n', 'c', 'C',
285 0x00, 0x00, 0x00, 0x00, 'r', 'g', 'b', 'a',
286 0x00, 0x00, 0x00, 0x04, 0, 0, 7, 0x00,
287 0x00, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x02,
288 0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00,
289 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfe
292 };
293
294 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
295 byteArray.size(), false);
296
297 BitstreamRange range(reader, byteArray.size());
298 std::shared_ptr<Box> box;
299 Error error = Box::read(range, &box, heif_get_disabled_security_limits());
300 REQUIRE(error == Error::Ok);
301 REQUIRE(range.error() == 0);
302
303 REQUIRE(box->get_short_type() == fourcc("uncC"));
304 REQUIRE(box->get_type_string() == "uncC");
305 std::shared_ptr<Box_uncC> uncC = std::dynamic_pointer_cast<Box_uncC>(box);
306 REQUIRE(uncC->get_number_of_tile_columns() == 4294967295);
307 REQUIRE(uncC->get_number_of_tile_rows() == 4294967295);
308 }
309
310 TEST_CASE("uncC_parse_excess_tile_cols") {
311 std::vector<uint8_t> byteArray{
312 0x00, 0x00, 0x00, 0x40, 'u', 'n', 'c', 'C',
313 0x00, 0x00, 0x00, 0x00, 'r', 'g', 'b', 'a',
314 0x00, 0x00, 0x00, 0x04, 0, 0, 7, 0x00,
315 0x00, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x02,
316 0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00,
317 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xff
320 };
321
322 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
323 byteArray.size(), false);
324 BitstreamRange range(reader, byteArray.size());
325 std::shared_ptr<Box> box;
326 Error error = Box::read(range, &box, heif_get_global_security_limits());
327 REQUIRE(range.error() == 0);
328 REQUIRE(error.error_code == 6);
329 REQUIRE(error.sub_error_code == 1000);
330 }
331
332 TEST_CASE("uncC_parse_excess_tile_rows") {
333 std::vector<uint8_t> byteArray{
334 0x00, 0x00, 0x00, 0x40, 'u', 'n', 'c', 'C',
335 0x00, 0x00, 0x00, 0x00, 'r', 'g', 'b', 'a',
336 0x00, 0x00, 0x00, 0x04, 0, 0, 7, 0x00,
337 0x00, 0x00, 0x01, 0x07, 0x00, 0x00, 0x00, 0x02,
338 0x07, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00,
339 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff
342 };
343
344 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
345 byteArray.size(), false);
346 BitstreamRange range(reader, byteArray.size());
347 std::shared_ptr<Box> box;
348 Error error = Box::read(range, &box, heif_get_global_security_limits());
349 REQUIRE(range.error() == 0);
350 REQUIRE(error.error_code == 6);
351 REQUIRE(error.sub_error_code == 1000);
352 }
353
354 TEST_CASE("cmpC_defl") {
355 std::vector<uint8_t> byteArray{
356 0x00, 0x00, 0x00, 0x11, 'c', 'm', 'p', 'C',
357 0x00, 0x00, 0x00, 0x00, 'd', 'e', 'f', 'l',
358 0x00
359 };
360
361 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
362 byteArray.size(), false);
363
364 BitstreamRange range(reader, byteArray.size());
365 std::shared_ptr<Box> box;
366 Error error = Box::read(range, &box, heif_get_global_security_limits());
367 REQUIRE(error == Error::Ok);
368 REQUIRE(range.error() == 0);
369
370 REQUIRE(box->get_short_type() == fourcc("cmpC"));
371 REQUIRE(box->get_type_string() == "cmpC");
372 std::shared_ptr<Box_cmpC> cmpC = std::dynamic_pointer_cast<Box_cmpC>(box);
373 REQUIRE(cmpC != nullptr);
374 REQUIRE(cmpC->get_compression_type() == fourcc("defl"));
375 REQUIRE(cmpC->get_compressed_unit_type() == 0);
376
377 StreamWriter writer;
378 Error err = cmpC->write(writer);
379 REQUIRE(err.error_code == heif_error_Ok);
380 const std::vector<uint8_t> written = writer.get_data();
381 REQUIRE(written == byteArray);
382
383 Indent indent;
384 std::string dump_output = cmpC->dump(indent);
385 REQUIRE(dump_output == "Box: cmpC -----\nsize: 17 (header size: 12)\ncompression_type: defl\ncompressed_entity_type: 0\n");
386
387 }
388
389
390 TEST_CASE("cmpC_zlib") {
391 std::vector<uint8_t> byteArray{
392 0x00, 0x00, 0x00, 0x11, 'c', 'm', 'p', 'C',
393 0x00, 0x00, 0x00, 0x00, 'z', 'l', 'i', 'b',
394 0x02
395 };
396
397 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
398 byteArray.size(), false);
399
400 BitstreamRange range(reader, byteArray.size());
401 std::shared_ptr<Box> box;
402 Error error = Box::read(range, &box, heif_get_global_security_limits());
403 REQUIRE(error == Error::Ok);
404 REQUIRE(range.error() == 0);
405
406 REQUIRE(box->get_short_type() == fourcc("cmpC"));
407 REQUIRE(box->get_type_string() == "cmpC");
408 std::shared_ptr<Box_cmpC> cmpC = std::dynamic_pointer_cast<Box_cmpC>(box);
409 REQUIRE(cmpC != nullptr);
410 REQUIRE(cmpC->get_compression_type() == fourcc("zlib"));
411 REQUIRE(cmpC->get_compressed_unit_type() == 2);
412
413 StreamWriter writer;
414 Error err = cmpC->write(writer);
415 REQUIRE(err.error_code == heif_error_Ok);
416 const std::vector<uint8_t> written = writer.get_data();
417 REQUIRE(written == byteArray);
418
419 Indent indent;
420 std::string dump_output = cmpC->dump(indent);
421 REQUIRE(dump_output == "Box: cmpC -----\nsize: 17 (header size: 12)\ncompression_type: zlib\ncompressed_entity_type: 2\n");
422
423 }
424
425 TEST_CASE("cmpC_brot") {
426 std::vector<uint8_t> byteArray{
427 0x00, 0x00, 0x00, 0x11, 'c', 'm', 'p', 'C',
428 0x00, 0x00, 0x00, 0x00, 'b', 'r', 'o', 't',
429 0x01
430 };
431
432 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
433 byteArray.size(), false);
434
435 BitstreamRange range(reader, byteArray.size());
436 std::shared_ptr<Box> box;
437 Error error = Box::read(range, &box, heif_get_global_security_limits());
438 REQUIRE(error == Error::Ok);
439 REQUIRE(range.error() == 0);
440
441 REQUIRE(box->get_short_type() == fourcc("cmpC"));
442 REQUIRE(box->get_type_string() == "cmpC");
443 std::shared_ptr<Box_cmpC> cmpC = std::dynamic_pointer_cast<Box_cmpC>(box);
444 REQUIRE(cmpC != nullptr);
445 REQUIRE(cmpC->get_compression_type() == fourcc("brot"));
446 REQUIRE(cmpC->get_compressed_unit_type() == 1);
447
448 StreamWriter writer;
449 Error err = cmpC->write(writer);
450 REQUIRE(err.error_code == heif_error_Ok);
451 const std::vector<uint8_t> written = writer.get_data();
452 REQUIRE(written == byteArray);
453
454 Indent indent;
455 std::string dump_output = cmpC->dump(indent);
456 REQUIRE(dump_output == "Box: cmpC -----\nsize: 17 (header size: 12)\ncompression_type: brot\ncompressed_entity_type: 1\n");
457
458 }
459
460
461 TEST_CASE("icef_24_8_bit") {
462 std::vector<uint8_t> byteArray{
463 0x00, 0x00, 0x00, 0x19, 'i', 'c', 'e', 'f',
464 0x00, 0x00, 0x00, 0x00,
465 0b01000000,
466 0x00, 0x00, 0x00, 0x02,
467 0x00, 0x0a, 0x03, 0x03,
468 0x02, 0x03, 0x0a, 0x07
469 };
470
471 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
472 byteArray.size(), false);
473
474 BitstreamRange range(reader, byteArray.size());
475 std::shared_ptr<Box> box;
476 Error error = Box::read(range, &box, heif_get_global_security_limits());
477 REQUIRE(error == Error::Ok);
478 REQUIRE(range.error() == 0);
479
480 REQUIRE(box->get_short_type() == fourcc("icef"));
481 REQUIRE(box->get_type_string() == "icef");
482 std::shared_ptr<Box_icef> icef = std::dynamic_pointer_cast<Box_icef>(box);
483 REQUIRE(icef != nullptr);
484 REQUIRE(icef->get_units().size() == 2);
485 REQUIRE(icef->get_version() == 0);
486
487 StreamWriter writer;
488 Error err = icef->write(writer);
489 REQUIRE(err.error_code == heif_error_Ok);
490 const std::vector<uint8_t> written = writer.get_data();
491 REQUIRE(written == byteArray);
492
493 Indent indent;
494 std::string dump_output = icef->dump(indent);
495 REQUIRE(dump_output == "Box: icef -----\nsize: 25 (header size: 12)\nnum_compressed_units: 2\nunit_offset: 2563, unit_size: 3\nunit_offset: 131850, unit_size: 7\n");
496 }
497
498
499 TEST_CASE("icef_0_16_bit") {
500 std::vector<uint8_t> byteArray{
501 0x00, 0x00, 0x00, 0x15, 'i', 'c', 'e', 'f',
502 0x00, 0x00, 0x00, 0x00,
503 0b00000100,
504 0x00, 0x00, 0x00, 0x02,
505 0x40, 0x03,
506 0x0a, 0x07
507 };
508
509 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
510 byteArray.size(), false);
511
512 BitstreamRange range(reader, byteArray.size());
513 std::shared_ptr<Box> box;
514 Error error = Box::read(range, &box, heif_get_global_security_limits());
515 REQUIRE(error == Error::Ok);
516 REQUIRE(range.error() == 0);
517
518 REQUIRE(box->get_short_type() == fourcc("icef"));
519 REQUIRE(box->get_type_string() == "icef");
520 std::shared_ptr<Box_icef> icef = std::dynamic_pointer_cast<Box_icef>(box);
521 REQUIRE(icef != nullptr);
522 REQUIRE(icef->get_units().size() == 2);
523 REQUIRE(icef->get_units()[0].unit_offset == 0);
524 REQUIRE(icef->get_units()[0].unit_size == 16387);
525 REQUIRE(icef->get_units()[1].unit_offset == 16387);
526 REQUIRE(icef->get_units()[1].unit_size == 2567);
527 REQUIRE(icef->get_version() == 0);
528
529 StreamWriter writer;
530 Error err = icef->write(writer);
531 REQUIRE(err.error_code == heif_error_Ok);
532 const std::vector<uint8_t> written = writer.get_data();
533 REQUIRE(written == byteArray);
534
535 Indent indent;
536 std::string dump_output = icef->dump(indent);
537 REQUIRE(dump_output == "Box: icef -----\nsize: 21 (header size: 12)\nnum_compressed_units: 2\nunit_offset: 0, unit_size: 16387\nunit_offset: 16387, unit_size: 2567\n");
538 }
539
540
541 TEST_CASE("icef_32bit") {
542 std::vector<uint8_t> byteArray{
543 0x00, 0x00, 0x00, 0x21, 'i', 'c', 'e', 'f',
544 0x00, 0x00, 0x00, 0x00,
545 0b01101100,
546 0x00, 0x00, 0x00, 0x02,
547 0x00, 0x00, 0x03, 0x04, 0x01, 0x01, 0x02, 0x03,
548 0x01, 0x02, 0x03, 0x0a, 0x00, 0x04, 0x05, 0x07
549 };
550
551 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
552 byteArray.size(), false);
553
554 BitstreamRange range(reader, byteArray.size());
555 std::shared_ptr<Box> box;
556 Error error = Box::read(range, &box, heif_get_global_security_limits());
557 REQUIRE(error == Error::Ok);
558 REQUIRE(range.error() == 0);
559
560 REQUIRE(box->get_short_type() == fourcc("icef"));
561 REQUIRE(box->get_type_string() == "icef");
562 std::shared_ptr<Box_icef> icef = std::dynamic_pointer_cast<Box_icef>(box);
563 REQUIRE(icef != nullptr);
564 REQUIRE(icef->get_units().size() == 2);
565 REQUIRE(icef->get_units()[0].unit_offset == 772);
566 REQUIRE(icef->get_units()[0].unit_size == 16843267);
567 REQUIRE(icef->get_units()[1].unit_offset == 16909066);
568 REQUIRE(icef->get_units()[1].unit_size == 263431);
569 REQUIRE(icef->get_version() == 0);
570
571 StreamWriter writer;
572 Error err = icef->write(writer);
573 REQUIRE(err.error_code == heif_error_Ok);
574 const std::vector<uint8_t> written = writer.get_data();
575 REQUIRE(written == byteArray);
576
577 Indent indent;
578 std::string dump_output = icef->dump(indent);
579 REQUIRE(dump_output == "Box: icef -----\nsize: 33 (header size: 12)\nnum_compressed_units: 2\nunit_offset: 772, unit_size: 16843267\nunit_offset: 16909066, unit_size: 263431\n");
580 }
581
582
583 TEST_CASE("icef_uint64") {
584 std::vector<uint8_t> byteArray{
585 0x00, 0x00, 0x00, 0x31, 'i', 'c', 'e', 'f',
586 0x00, 0x00, 0x00, 0x00,
587 0b10010000,
588 0x00, 0x00, 0x00, 0x02,
589 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x03,
590 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x02, 0x03,
591 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x03, 0x0a,
592 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x05, 0x07
593 };
594
595 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
596 byteArray.size(), false);
597
598 BitstreamRange range(reader, byteArray.size());
599 std::shared_ptr<Box> box;
600 Error error = Box::read(range, &box, heif_get_global_security_limits());
601 REQUIRE(error == Error::Ok);
602 REQUIRE(range.error() == 0);
603
604 REQUIRE(box->get_short_type() == fourcc("icef"));
605 REQUIRE(box->get_type_string() == "icef");
606 std::shared_ptr<Box_icef> icef = std::dynamic_pointer_cast<Box_icef>(box);
607 REQUIRE(icef != nullptr);
608 REQUIRE(icef->get_units().size() == 2);
609 REQUIRE(icef->get_units()[0].unit_offset == 4294969859L);
610 REQUIRE(icef->get_units()[0].unit_size == 8590000643L);
611 REQUIRE(icef->get_units()[1].unit_offset == 8590066442L);
612 REQUIRE(icef->get_units()[1].unit_size == 12885165319L);
613 REQUIRE(icef->get_version() == 0);
614
615 StreamWriter writer;
616 Error err = icef->write(writer);
617 REQUIRE(err.error_code == heif_error_Ok);
618 const std::vector<uint8_t> written = writer.get_data();
619 REQUIRE(written == byteArray);
620
621 Indent indent;
622 std::string dump_output = icef->dump(indent);
623 REQUIRE(dump_output == "Box: icef -----\nsize: 49 (header size: 12)\nnum_compressed_units: 2\nunit_offset: 4294969859, unit_size: 8590000643\nunit_offset: 8590066442, unit_size: 12885165319\n");
624 }
625
626
627 TEST_CASE("icef_bad_version") {
628 std::vector<uint8_t> byteArray{
629 0x00, 0x00, 0x00, 0x19, 'i', 'c', 'e', 'f',
630 0x01, 0x00, 0x00, 0x00,
631 0b01000000,
632 0x00, 0x00, 0x00, 0x02,
633 0x00, 0x0a, 0x03, 0x03,
634 0x02, 0x03, 0x0a, 0x07
635 };
636
637 auto reader = std::make_shared<StreamReader_memory>(byteArray.data(),
638 byteArray.size(), false);
639
640 BitstreamRange range(reader, byteArray.size());
641 std::shared_ptr<Box> box;
642 Error error = Box::read(range, &box, heif_get_global_security_limits());
643 REQUIRE(error.error_code == heif_error_Unsupported_feature);
644 REQUIRE(error.sub_error_code == heif_suberror_Unsupported_data_version);
645 REQUIRE(error.message == std::string("icef box data version 1 is not implemented yet"));
646 }