diff --git a/INSTALL.md b/INSTALL.md index 7e7ad229b4..3ad0cb4c62 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -61,7 +61,8 @@ NEW or CHANGED MINIMUM dependencies since the last major release are **bold**. * giflib >= 4.1 (tested through 5.2; 5.0+ is strongly recommended for stability and thread safety) * If you want support for HEIF/HEIC or AVIF images: - * libheif >= 1.3 (1.7 required for AVIF support, tested through 1.17.6) + * libheif >= 1.3 (1.7 required for AVIF support, 1.16 required for + correct orientation support, tested through 1.17.6) * libheif must be built with an AV1 encoder/decoder for AVIF support. * Avoid libheif 1.10 on Mac, it is very broken. Libheif 1.11+ is fine. * If you want support for DICOM medical image files: diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 4068330fb2..6b21270b32 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -212,8 +212,8 @@ checked_find_package (GIF # For HEIF/HEIC/AVIF formats checked_find_package (Libheif VERSION_MIN 1.3 - RECOMMEND_MIN 1.7 - RECOMMEND_MIN_REASON "for AVIF support") + RECOMMEND_MIN 1.16 + RECOMMEND_MIN_REASON "for orientation support") if (APPLE AND LIBHEIF_VERSION VERSION_GREATER_EQUAL 1.10 AND LIBHEIF_VERSION VERSION_LESS 1.11) message (WARNING "Libheif 1.10 on Apple is known to be broken, disabling libheif support") set (Libheif_FOUND 0) diff --git a/src/heif.imageio/heifinput.cpp b/src/heif.imageio/heifinput.cpp index cba7b20d16..436b9a5110 100644 --- a/src/heif.imageio/heifinput.cpp +++ b/src/heif.imageio/heifinput.cpp @@ -309,6 +309,7 @@ HeifInput::seek_subimage(int subimage, int miplevel) } } +#if LIBHEIF_NUMERIC_VERSION >= MAKE_LIBHEIF_VERSION(1, 16, 0, 0) // Try to discover the orientation. The Exif is unreliable. We have to go // through the transformation properties ourselves. A tricky bit is that // 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) = reinterpret_cast*>(m_ctx.get())->get(); int xpcount = heif_item_get_transformation_properties(raw_ctx, id, nullptr, 100); - orientation = 1; xpcount = std::min(xpcount, 100); // clamp to some reasonable limit std::vector xprops(xpcount); heif_item_get_transformation_properties(raw_ctx, id, xprops.data(), @@ -348,6 +348,11 @@ HeifInput::seek_subimage(int subimage, int miplevel) } } } +#else + // Prior to libheif 1.16, the get_transformation_properties API was not + // available, so we have to rely on the Exif orientation tag. + int orientation = m_spec.get_int_attribute("Orientation", 1); +#endif // Erase the orientation metadata because libheif appears to be doing // the rotation-to-canonical-direction for us.