Skip to content

Commit

Permalink
heif-dec: show parsing warnings (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Sep 17, 2024
1 parent c20e179 commit 858d8a0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,11 @@ std::string Box_Error::dump(Indent& indent) const
return sstr.str();
}

parse_error_fatality Box_Error::get_parse_error_fatality() const
{
return m_fatality;
}


Error Box_ftyp::parse(BitstreamRange& range)
{
Expand Down
4 changes: 4 additions & 0 deletions libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ class Box_Error : public Box

std::string dump(Indent&) const override;

[[nodiscard]] parse_error_fatality get_parse_error_fatality() const override;

[[nodiscard]] Error get_error() const { return m_error; }

protected:
Error parse(BitstreamRange& range) override { assert(false); return Error::Ok; }

Expand Down
6 changes: 6 additions & 0 deletions libheif/codecs/image_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ class ImageItem : public ErrorBuffer
const std::vector<heif_item_id>& get_region_item_ids() const { return m_region_item_ids; }


void add_decoding_warning(Error err) { m_decoding_warnings.emplace_back(std::move(err)); }

const std::vector<Error>& get_decoding_warnings() const { return m_decoding_warnings; }

private:
HeifContext* m_heif_context;

Expand Down Expand Up @@ -382,6 +386,8 @@ class ImageItem : public ErrorBuffer
bool m_has_extrinsic_matrix = false;
Box_cmex::ExtrinsicMatrix m_extrinsic_matrix{};

std::vector<Error> m_decoding_warnings;

protected:
static Result<std::shared_ptr<HeifPixelImage>> decode_from_compressed_data(heif_compression_format compression_format,
const struct heif_decoding_options& options,
Expand Down
14 changes: 13 additions & 1 deletion libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ Error HeifContext::interpret_heif_file()

// --- are there any 'essential' properties that we did not parse?


for (const auto& prop : properties) {
if (std::dynamic_pointer_cast<Box_other>(prop) &&
get_heif_file()->get_ipco_box()->is_property_essential_for_item(pair.first, prop, get_heif_file()->get_ipma_box())) {
Expand All @@ -343,6 +342,17 @@ Error HeifContext::interpret_heif_file()
}


// --- Are there any parse errors in optional properties? Attach the errors as warnings to the images.

for (const auto& prop : properties) {
if (auto errorbox = std::dynamic_pointer_cast<Box_Error>(prop)) {
if (errorbox->get_parse_error_fatality() == parse_error_fatality::optional) {
image->add_decoding_warning(errorbox->get_error());
}
}
}


// --- extract image resolution

bool ispe_read = false;
Expand Down Expand Up @@ -997,6 +1007,8 @@ Result<std::shared_ptr<HeifPixelImage>> HeifContext::decode_image(heif_item_id I
}
}

img->add_warnings(imginfo->get_decoding_warnings());

return img;
}

Expand Down
2 changes: 2 additions & 0 deletions libheif/pixelimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ class HeifPixelImage : public std::enable_shared_from_this<HeifPixelImage>,

void add_warning(Error warning) { m_warnings.emplace_back(std::move(warning)); }

void add_warnings(const std::vector<Error>& warning) { for (const auto& err : warning) m_warnings.emplace_back(err); }

const std::vector<Error>& get_warnings() const { return m_warnings; }

private:
Expand Down

0 comments on commit 858d8a0

Please sign in to comment.