Skip to content

Commit 07d06fd

Browse files
brechtvllgritz
authored andcommitted
fix(heif): Can not output AVIF when libheif has no HEVC support (AcademySoftwareFoundation#5013)
Initializing the encoder to `heif_compression_HEVC` by default throws an exception when libheif was built without HEVC support, which prevents it from being used entirely even if there is AVIF support. So delay that initialization until we are sure which encoding we want. Not really any practical way to automatically test this. Signed-off-by: Brecht Van Lommel <brecht@blender.org>
1 parent 65e13a3 commit 07d06fd

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/heif.imageio/heifoutput.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class HeifOutput final : public ImageOutput {
4242
std::unique_ptr<heif::Context> m_ctx;
4343
heif::ImageHandle m_ihandle;
4444
heif::Image m_himage;
45-
heif::Encoder m_encoder { heif_compression_HEVC };
45+
// Undefined until we know the specific requested encoder, because an
46+
// exception is thrown if libheif is built without support for it.
47+
heif::Encoder m_encoder { heif_compression_undefined };
4648
std::vector<unsigned char> scratch;
4749
std::vector<unsigned char> m_tilebuffer;
4850
};
@@ -118,12 +120,13 @@ HeifOutput::open(const std::string& name, const ImageSpec& newspec,
118120
m_himage.add_plane(heif_channel_interleaved, newspec.width,
119121
newspec.height, 8 * m_spec.nchannels /*bit depth*/);
120122

121-
m_encoder = heif::Encoder(heif_compression_HEVC);
122123
auto compqual = m_spec.decode_compression_metadata("", 75);
123124
auto extension = Filesystem::extension(m_filename);
124125
if (compqual.first == "avif"
125126
|| (extension == ".avif" && compqual.first == "")) {
126127
m_encoder = heif::Encoder(heif_compression_AV1);
128+
} else {
129+
m_encoder = heif::Encoder(heif_compression_HEVC);
127130
}
128131
} catch (const heif::Error& err) {
129132
std::string e = err.get_message();

0 commit comments

Comments
 (0)