Skip to content

Commit a2beff4

Browse files
committed
fix(heif): Fix incorrect tracking of current subimage (AcademySoftwareFoundation#5166)
Oh dear, somehow our heif reader never correctly overloaded the current_subimage method, instead inheriting the one from the base class that always returns 0. That's very bad for a file type that supports multiple subimages. Along the way, simplified how we deal with the fact that the "primary" subimage doesn't need to be first in the file, but we always want to present it as if it were first. There was a point where I thought that was related to the bug so I was rewriting it; it turned out to not be the problem, but I'd still like to keep the cleanup I had done. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 4e0887d commit a2beff4

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/heif.imageio/heifinput.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class HeifInput final : public ImageInput {
4343
bool open(const std::string& name, ImageSpec& newspec,
4444
const ImageSpec& config) override;
4545
bool close() override;
46+
int current_subimage(void) const override { return m_subimage; }
4647
bool seek_subimage(int subimage, int miplevel) override;
4748
bool read_native_scanline(int subimage, int miplevel, int y, int z,
4849
void* data) override;
@@ -145,16 +146,18 @@ HeifInput::open(const std::string& name, ImageSpec& newspec,
145146
m_ctx->read_from_file(name);
146147
// FIXME: should someday be read_from_reader to give full flexibility
147148

148-
m_item_ids = m_ctx->get_list_of_top_level_image_IDs();
149+
// Get the item IDs for each subimage, and force the "primary" one to
150+
// have index 0.
149151
m_primary_id = m_ctx->get_primary_image_ID();
150-
for (size_t i = 0; i < m_item_ids.size(); ++i)
151-
if (m_item_ids[i] == m_primary_id) {
152-
m_item_ids.erase(m_item_ids.begin() + i);
153-
break;
154-
}
152+
m_item_ids.resize(0);
153+
m_item_ids.push_back(m_primary_id);
154+
for (auto id : m_ctx->get_list_of_top_level_image_IDs()) {
155+
if (id != m_primary_id)
156+
m_item_ids.push_back(id);
157+
}
155158
// std::cout << " primary id: " << m_primary_id << "\n";
156159
// std::cout << " item ids: " << Strutil::join(m_item_ids, ", ") << "\n";
157-
m_num_subimages = 1 + int(m_item_ids.size());
160+
m_num_subimages = int(m_item_ids.size());
158161

159162
} catch (const heif::Error& err) {
160163
std::string e = err.get_message();

0 commit comments

Comments
 (0)