Skip to content

Commit

Permalink
deduplicate all remaining boxes (except j2kH, because that has child …
Browse files Browse the repository at this point in the history
…boxes) (#1175)
  • Loading branch information
farindk committed Jun 10, 2024
1 parent 26b9971 commit fb45533
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ void HeifContext::write_image_metadata(std::shared_ptr<HeifPixelImage> src_image
auto pasp = std::make_shared<Box_pasp>();
src_image->get_pixel_ratio(&pasp->hSpacing, &pasp->vSpacing);

int index = m_heif_file->get_ipco_box()->append_child_box(pasp);
int index = m_heif_file->get_ipco_box()->find_or_append_child_box(pasp);
m_heif_file->get_ipma_box()->add_property_for_item_ID(image_id, Box_ipma::PropertyAssociation{false, uint16_t(index + 1)});
}

Expand All @@ -2377,7 +2377,7 @@ void HeifContext::write_image_metadata(std::shared_ptr<HeifPixelImage> src_image
auto clli = std::make_shared<Box_clli>();
clli->clli = src_image->get_clli();

int index = m_heif_file->get_ipco_box()->append_child_box(clli);
int index = m_heif_file->get_ipco_box()->find_or_append_child_box(clli);
m_heif_file->get_ipma_box()->add_property_for_item_ID(image_id, Box_ipma::PropertyAssociation{false, uint16_t(index + 1)});
}

Expand All @@ -2388,7 +2388,7 @@ void HeifContext::write_image_metadata(std::shared_ptr<HeifPixelImage> src_image
auto mdcv = std::make_shared<Box_mdcv>();
mdcv->mdcv = src_image->get_mdcv();

int index = m_heif_file->get_ipco_box()->append_child_box(mdcv);
int index = m_heif_file->get_ipco_box()->find_or_append_child_box(mdcv);
m_heif_file->get_ipma_box()->add_property_for_item_ID(image_id, Box_ipma::PropertyAssociation{false, uint16_t(index + 1)});
}
}
Expand Down Expand Up @@ -3125,7 +3125,7 @@ Error HeifContext::encode_image_as_jpeg(const std::shared_ptr<HeifPixelImage>& i
jpgC->set_data(jpgC_data);

auto ipma_box = m_heif_file->get_ipma_box();
int index = m_heif_file->get_ipco_box()->append_child_box(jpgC);
int index = m_heif_file->get_ipco_box()->find_or_append_child_box(jpgC);
ipma_box->add_property_for_item_ID(image_id, Box_ipma::PropertyAssociation{true, uint16_t(index + 1)});

std::vector<uint8_t> image_data(vec.begin() + pos, vec.end());
Expand Down
8 changes: 4 additions & 4 deletions libheif/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ void HeifFile::add_orientation_properties(heif_item_id id, heif_orientation orie
auto irot = std::make_shared<Box_irot>();
irot->set_rotation_ccw(rotation_ccw);

int index = m_ipco_box->append_child_box(irot);
int index = m_ipco_box->find_or_append_child_box(irot);

m_ipma_box->add_property_for_item_ID(id, Box_ipma::PropertyAssociation{false, uint16_t(index + 1)});
}
Expand All @@ -1051,7 +1051,7 @@ void HeifFile::add_orientation_properties(heif_item_id id, heif_orientation orie
auto imir = std::make_shared<Box_imir>();
imir->set_mirror_direction(mirror);

int index = m_ipco_box->append_child_box(imir);
int index = m_ipco_box->find_or_append_child_box(imir);

m_ipma_box->add_property_for_item_ID(id, Box_ipma::PropertyAssociation{false, uint16_t(index + 1)});
}
Expand Down Expand Up @@ -1085,7 +1085,7 @@ void HeifFile::add_av1C_property(heif_item_id id, const Box_av1C::configuration&
std::shared_ptr<Box_j2kH> HeifFile::add_j2kH_property(heif_item_id id)
{
auto j2kH = std::make_shared<Box_j2kH>();
int index = m_ipco_box->append_child_box(j2kH);
int index = m_ipco_box->append_child_box(j2kH); // do not deduplicate because this can have a child box

m_ipma_box->add_property_for_item_ID(id, Box_ipma::PropertyAssociation{true, uint16_t(index + 1)});

Expand Down Expand Up @@ -1135,7 +1135,7 @@ void HeifFile::set_auxC_property(heif_item_id id, const std::string& type)
auto auxC = std::make_shared<Box_auxC>();
auxC->set_aux_type(type);

int index = m_ipco_box->append_child_box(auxC);
int index = m_ipco_box->find_or_append_child_box(auxC);

m_ipma_box->add_property_for_item_ID(id, Box_ipma::PropertyAssociation{true, uint16_t(index + 1)});
}
Expand Down

0 comments on commit fb45533

Please sign in to comment.