@@ -219,26 +219,110 @@ TEST_CASE( "uncC" )
219
219
220
220
221
221
TEST_CASE (" cmpC_defl" ) {
222
- std::vector<uint8_t > byteArray{
223
- 0x00 , 0x00 , 0x00 , 0x11 , ' c' , ' m' , ' p' , ' C' ,
224
- 0x00 , 0x00 , 0x00 , 0x00 , ' d' , ' e' , ' f' , ' l' ,
225
- 0x00
226
- };
222
+ std::vector<uint8_t > byteArray{
223
+ 0x00 , 0x00 , 0x00 , 0x11 , ' c' , ' m' , ' p' , ' C' ,
224
+ 0x00 , 0x00 , 0x00 , 0x00 , ' d' , ' e' , ' f' , ' l' ,
225
+ 0x00
226
+ };
227
+
228
+ auto reader = std::make_shared<StreamReader_memory>(byteArray.data (),
229
+ byteArray.size (), false );
230
+
231
+ BitstreamRange range (reader, byteArray.size ());
232
+ std::shared_ptr<Box> box;
233
+ Error error = Box::read (range, &box);
234
+ REQUIRE (error == Error::Ok);
235
+ REQUIRE (range.error () == 0 );
236
+
237
+ REQUIRE (box->get_short_type () == fourcc (" cmpC" ));
238
+ REQUIRE (box->get_type_string () == " cmpC" );
239
+ std::shared_ptr<Box_cmpC> cmpC = std::dynamic_pointer_cast<Box_cmpC>(box);
240
+ REQUIRE (cmpC != nullptr );
241
+ REQUIRE (cmpC->get_compression_type () == fourcc (" defl" ));
242
+ REQUIRE (cmpC->get_can_decompress_contiguous_ranges () == false );
243
+ REQUIRE (cmpC->get_compressed_range_type () == 0 );
227
244
228
- auto reader = std::make_shared<StreamReader_memory>(byteArray.data (),
229
- byteArray.size (), false );
245
+ StreamWriter writer;
246
+ Error err = cmpC->write (writer);
247
+ REQUIRE (err.error_code == heif_error_Ok);
248
+ const std::vector<uint8_t > written = writer.get_data ();
249
+ REQUIRE (written == byteArray);
230
250
231
- BitstreamRange range (reader, byteArray.size ());
232
- std::shared_ptr<Box> box;
233
- Error error = Box::read (range, &box);
234
- REQUIRE (error == Error::Ok);
235
- REQUIRE (range.error () == 0 );
251
+ Indent indent;
252
+ std::string dump_output = cmpC->dump (indent);
253
+ REQUIRE (dump_output == " Box: cmpC -----\n size: 17 (header size: 12)\n compression_type: defl\n can_decompress_contiguous_ranges: 0\n compressed_entity_type: 0\n " );
236
254
237
- REQUIRE (box->get_short_type () == fourcc (" cmpC" ));
238
- REQUIRE (box->get_type_string () == " cmpC" );
239
- std::shared_ptr<Box_cmpC> cmpC = std::dynamic_pointer_cast<Box_cmpC>(box);
240
- REQUIRE (cmpC != nullptr );
241
- REQUIRE (cmpC->get_compression_type () == fourcc (" defl" ));
242
- // rest
255
+ }
256
+
257
+
258
+ TEST_CASE (" cmpC_zlib" ) {
259
+ std::vector<uint8_t > byteArray{
260
+ 0x00 , 0x00 , 0x00 , 0x11 , ' c' , ' m' , ' p' , ' C' ,
261
+ 0x00 , 0x00 , 0x00 , 0x00 , ' z' , ' l' , ' i' , ' b' ,
262
+ 0x82
263
+ };
264
+
265
+ auto reader = std::make_shared<StreamReader_memory>(byteArray.data (),
266
+ byteArray.size (), false );
267
+
268
+ BitstreamRange range (reader, byteArray.size ());
269
+ std::shared_ptr<Box> box;
270
+ Error error = Box::read (range, &box);
271
+ REQUIRE (error == Error::Ok);
272
+ REQUIRE (range.error () == 0 );
273
+
274
+ REQUIRE (box->get_short_type () == fourcc (" cmpC" ));
275
+ REQUIRE (box->get_type_string () == " cmpC" );
276
+ std::shared_ptr<Box_cmpC> cmpC = std::dynamic_pointer_cast<Box_cmpC>(box);
277
+ REQUIRE (cmpC != nullptr );
278
+ REQUIRE (cmpC->get_compression_type () == fourcc (" zlib" ));
279
+ REQUIRE (cmpC->get_can_decompress_contiguous_ranges () == true );
280
+ REQUIRE (cmpC->get_compressed_range_type () == 2 );
281
+
282
+ StreamWriter writer;
283
+ Error err = cmpC->write (writer);
284
+ REQUIRE (err.error_code == heif_error_Ok);
285
+ const std::vector<uint8_t > written = writer.get_data ();
286
+ REQUIRE (written == byteArray);
287
+
288
+ Indent indent;
289
+ std::string dump_output = cmpC->dump (indent);
290
+ REQUIRE (dump_output == " Box: cmpC -----\n size: 17 (header size: 12)\n compression_type: zlib\n can_decompress_contiguous_ranges: 1\n compressed_entity_type: 2\n " );
291
+
292
+ }
293
+
294
+ TEST_CASE (" cmpC_brot" ) {
295
+ std::vector<uint8_t > byteArray{
296
+ 0x00 , 0x00 , 0x00 , 0x11 , ' c' , ' m' , ' p' , ' C' ,
297
+ 0x00 , 0x00 , 0x00 , 0x00 , ' b' , ' r' , ' o' , ' t' ,
298
+ 0x81
299
+ };
300
+
301
+ auto reader = std::make_shared<StreamReader_memory>(byteArray.data (),
302
+ byteArray.size (), false );
303
+
304
+ BitstreamRange range (reader, byteArray.size ());
305
+ std::shared_ptr<Box> box;
306
+ Error error = Box::read (range, &box);
307
+ REQUIRE (error == Error::Ok);
308
+ REQUIRE (range.error () == 0 );
309
+
310
+ REQUIRE (box->get_short_type () == fourcc (" cmpC" ));
311
+ REQUIRE (box->get_type_string () == " cmpC" );
312
+ std::shared_ptr<Box_cmpC> cmpC = std::dynamic_pointer_cast<Box_cmpC>(box);
313
+ REQUIRE (cmpC != nullptr );
314
+ REQUIRE (cmpC->get_compression_type () == fourcc (" brot" ));
315
+ REQUIRE (cmpC->get_can_decompress_contiguous_ranges () == true );
316
+ REQUIRE (cmpC->get_compressed_range_type () == 1 );
317
+
318
+ StreamWriter writer;
319
+ Error err = cmpC->write (writer);
320
+ REQUIRE (err.error_code == heif_error_Ok);
321
+ const std::vector<uint8_t > written = writer.get_data ();
322
+ REQUIRE (written == byteArray);
323
+
324
+ Indent indent;
325
+ std::string dump_output = cmpC->dump (indent);
326
+ REQUIRE (dump_output == " Box: cmpC -----\n size: 17 (header size: 12)\n compression_type: brot\n can_decompress_contiguous_ranges: 1\n compressed_entity_type: 1\n " );
243
327
244
- }
328
+ }
0 commit comments