Skip to content

Commit f0ddda8

Browse files
committed
uncompressed: unit tests for cmpC
1 parent c324f73 commit f0ddda8

File tree

5 files changed

+109
-23
lines changed

5 files changed

+109
-23
lines changed

libheif/codecs/uncompressed_box.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ std::string Box_cmpC::dump(Indent& indent) const
369369
std::ostringstream sstr;
370370
sstr << Box::dump(indent);
371371
sstr << indent << "compression_type: " << to_fourcc(compression_type) << "\n";
372-
sstr << indent << "can_compress_contiguous_ranges: " << can_decompress_contiguous_ranges << "\n";
373-
sstr << indent << "compressed_range_type: " << (int)compressed_range_type << "\n";
372+
sstr << indent << "can_decompress_contiguous_ranges: " << can_decompress_contiguous_ranges << "\n";
373+
sstr << indent << "compressed_entity_type: " << (int)compressed_range_type << "\n";
374374
return sstr.str();
375375
}
376376

libheif/codecs/uncompressed_box.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ class Box_cmpC : public FullBox
237237
std::string dump(Indent&) const override;
238238

239239
uint32_t get_compression_type() const { return compression_type; }
240+
bool get_can_decompress_contiguous_ranges() const { return can_decompress_contiguous_ranges; }
241+
uint8_t get_compressed_range_type() const { return compressed_range_type; }
242+
240243
Error write(StreamWriter& writer) const override;
241244

242245
protected:

libheif/codecs/uncompressed_image.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,6 @@ Error UncompressedImageCodec::decode_uncompressed_image(const std::shared_ptr<co
943943
if (!cmpd) {
944944
printf("No cmpd\n");
945945
}
946-
printf("uncC version: %d\n", uncC->get_version());
947946
if (!cmpd && (uncC->get_version() !=1)) {
948947
return Error(heif_error_Unsupported_feature,
949948
heif_suberror_Unsupported_data_version,

libheif/file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ int HeifFile::get_luma_bits_per_pixel_from_configuration(heif_item_id imageID) c
632632
#if WITH_UNCOMPRESSED_CODEC
633633
// Uncompressed
634634

635-
if (image_type == "unci") {
635+
if ((image_type == "unci") || (image_type == "gnci")) {
636636
int bpp = UncompressedImageCodec::get_luma_bits_per_pixel_from_configuration_unci(*this, imageID);
637637
return bpp;
638638
}

tests/uncompressed_box.cc

Lines changed: 103 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,110 @@ TEST_CASE( "uncC" )
219219

220220

221221
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);
227244

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);
230250

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 -----\nsize: 17 (header size: 12)\ncompression_type: defl\ncan_decompress_contiguous_ranges: 0\ncompressed_entity_type: 0\n");
236254

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 -----\nsize: 17 (header size: 12)\ncompression_type: zlib\ncan_decompress_contiguous_ranges: 1\ncompressed_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 -----\nsize: 17 (header size: 12)\ncompression_type: brot\ncan_decompress_contiguous_ranges: 1\ncompressed_entity_type: 1\n");
243327

244-
}
328+
}

0 commit comments

Comments
 (0)