Skip to content

Commit

Permalink
support re-use of thumbnail images
Browse files Browse the repository at this point in the history
  • Loading branch information
bradh committed Mar 23, 2024
1 parent b5c8179 commit 26dbaf3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
43 changes: 19 additions & 24 deletions libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -656,34 +656,29 @@ Error HeifContext::interpret_heif_file()
// --- this is a thumbnail image, attach to the main image

std::vector<heif_item_id> refs = ref.to_item_ID;
if (refs.size() != 1) {
return Error(heif_error_Invalid_input,
heif_suberror_Unspecified,
"Too many thumbnail references");
}
for (heif_item_id ref: refs) {
image->set_is_thumbnail();

image->set_is_thumbnail_of(refs[0]);

auto master_iter = m_all_images.find(refs[0]);
if (master_iter == m_all_images.end()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Thumbnail references a non-existing image");
}
auto master_iter = m_all_images.find(ref);
if (master_iter == m_all_images.end()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Thumbnail references a non-existing image");
}

if (master_iter->second->is_thumbnail()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Thumbnail references another thumbnail");
}
if (master_iter->second->is_thumbnail()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Thumbnail references another thumbnail");
}

if (image.get() == master_iter->second.get()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Recursive thumbnail image detected");
if (image.get() == master_iter->second.get()) {
return Error(heif_error_Invalid_input,
heif_suberror_Nonexisting_item_referenced,
"Recursive thumbnail image detected");
}
master_iter->second->add_thumbnail(image);
}
master_iter->second->add_thumbnail(image);

remove_top_level_image(image);
}
else if (type == fourcc("auxl")) {
Expand Down
4 changes: 1 addition & 3 deletions libheif/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ class HeifContext : public ErrorBuffer

// -- thumbnails

void set_is_thumbnail_of(heif_item_id id)
void set_is_thumbnail()
{
m_is_thumbnail = true;
m_thumbnail_ref_id = id;
}

void add_thumbnail(const std::shared_ptr<Image>& img) { m_thumbnails.push_back(img); }
Expand Down Expand Up @@ -290,7 +289,6 @@ class HeifContext : public ErrorBuffer
bool m_is_primary = false;

bool m_is_thumbnail = false;
heif_item_id m_thumbnail_ref_id = 0;

std::vector<std::shared_ptr<Image>> m_thumbnails;

Expand Down

0 comments on commit 26dbaf3

Please sign in to comment.