Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Nov 19, 2024
1 parent 7a7bdd1 commit c596ba0
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -803,26 +803,19 @@ Error HeifContext::interpret_heif_file()
// --- assign metadata to the image

if (iref_box) {
std::vector<Box_iref::Reference> references = iref_box->get_references_from(id);
for (const auto& ref : references) {
if (ref.header.get_short_type() == fourcc("cdsc")) {
std::vector<uint32_t> refs = ref.to_item_ID;

for(uint32_t ref: refs) {
uint32_t exif_image_id = ref;
auto img_iter = m_all_images.find(exif_image_id);
if (img_iter == m_all_images.end()) {
if (!m_heif_file->has_item_with_id(exif_image_id)) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Metadata assigned to non-existing image");
}

continue;
}
img_iter->second->add_metadata(metadata);
std::vector<heif_item_id> references = iref_box->get_references(id, fourcc("cdsc"));
for (heif_item_id exif_image_id : references) {
auto img_iter = m_all_images.find(exif_image_id);
if (img_iter == m_all_images.end()) {
if (!m_heif_file->has_item_with_id(exif_image_id)) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Metadata assigned to non-existing image");
}

continue;
}
img_iter->second->add_metadata(metadata);
}
}
}
Expand All @@ -831,19 +824,19 @@ Error HeifContext::interpret_heif_file()

for (heif_item_id id : image_IDs) {
if (iref_box) {
std::vector<Box_iref::Reference> references = iref_box->get_references_from(id);
for (const auto& ref : references) {
if (ref.header.get_short_type() == fourcc("prem")) {
uint32_t color_image_id = ref.from_item_ID;
auto img_iter = m_all_images.find(color_image_id);
if (img_iter == m_all_images.end()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"`prem` link assigned to non-existing image");
}

img_iter->second->set_is_premultiplied_alpha(true);
std::vector<heif_item_id> references = iref_box->get_references(id, fourcc("prem"));
for (heif_item_id ref : references) {
(void)ref;

heif_item_id color_image_id = id;
auto img_iter = m_all_images.find(color_image_id);
if (img_iter == m_all_images.end()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"`prem` link assigned to non-existing image");
}

img_iter->second->set_is_premultiplied_alpha(true);
}
}
}
Expand Down

0 comments on commit c596ba0

Please sign in to comment.