Skip to content

Commit e41ac03

Browse files
authored
fix(heif): Fixes to recent orientation support (#4184)
We inadvertently started using libheif functions that only became available in their version 1.16.0. Guard against that and now we recommend at least that version (but we aren't yet changing the minimum requirement). This fixes a build break introduced in #4142 (but only breaks for older libheif). Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent f2ad2c7 commit e41ac03

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

INSTALL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ NEW or CHANGED MINIMUM dependencies since the last major release are **bold**.
6161
* giflib >= 4.1 (tested through 5.2; 5.0+ is strongly recommended for
6262
stability and thread safety)
6363
* If you want support for HEIF/HEIC or AVIF images:
64-
* libheif >= 1.3 (1.7 required for AVIF support, tested through 1.17.6)
64+
* libheif >= 1.3 (1.7 required for AVIF support, 1.16 required for
65+
correct orientation support, tested through 1.17.6)
6566
* libheif must be built with an AV1 encoder/decoder for AVIF support.
6667
* Avoid libheif 1.10 on Mac, it is very broken. Libheif 1.11+ is fine.
6768
* If you want support for DICOM medical image files:

src/cmake/externalpackages.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ checked_find_package (GIF
212212

213213
# For HEIF/HEIC/AVIF formats
214214
checked_find_package (Libheif VERSION_MIN 1.3
215-
RECOMMEND_MIN 1.7
216-
RECOMMEND_MIN_REASON "for AVIF support")
215+
RECOMMEND_MIN 1.16
216+
RECOMMEND_MIN_REASON "for orientation support")
217217
if (APPLE AND LIBHEIF_VERSION VERSION_GREATER_EQUAL 1.10 AND LIBHEIF_VERSION VERSION_LESS 1.11)
218218
message (WARNING "Libheif 1.10 on Apple is known to be broken, disabling libheif support")
219219
set (Libheif_FOUND 0)

src/heif.imageio/heifinput.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ HeifInput::seek_subimage(int subimage, int miplevel)
309309
}
310310
}
311311

312+
#if LIBHEIF_NUMERIC_VERSION >= MAKE_LIBHEIF_VERSION(1, 16, 0, 0)
312313
// Try to discover the orientation. The Exif is unreliable. We have to go
313314
// through the transformation properties ourselves. A tricky bit is that
314315
// the C++ API doesn't give us a direct way to get the context ptr, we
@@ -321,7 +322,6 @@ HeifInput::seek_subimage(int subimage, int miplevel)
321322
= reinterpret_cast<std::shared_ptr<heif_context>*>(m_ctx.get())->get();
322323
int xpcount = heif_item_get_transformation_properties(raw_ctx, id, nullptr,
323324
100);
324-
orientation = 1;
325325
xpcount = std::min(xpcount, 100); // clamp to some reasonable limit
326326
std::vector<heif_property_id> xprops(xpcount);
327327
heif_item_get_transformation_properties(raw_ctx, id, xprops.data(),
@@ -348,6 +348,11 @@ HeifInput::seek_subimage(int subimage, int miplevel)
348348
}
349349
}
350350
}
351+
#else
352+
// Prior to libheif 1.16, the get_transformation_properties API was not
353+
// available, so we have to rely on the Exif orientation tag.
354+
int orientation = m_spec.get_int_attribute("Orientation", 1);
355+
#endif
351356

352357
// Erase the orientation metadata because libheif appears to be doing
353358
// the rotation-to-canonical-direction for us.

0 commit comments

Comments
 (0)