Skip to content

Commit e6ccb76

Browse files
authored
fix(heif): Can not output AVIF when libheif has no HEVC support (#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 a0db580 commit e6ccb76

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
@@ -49,7 +49,9 @@ class HeifOutput final : public ImageOutput {
4949
std::unique_ptr<heif::Context> m_ctx;
5050
heif::ImageHandle m_ihandle;
5151
heif::Image m_himage;
52-
heif::Encoder m_encoder { heif_compression_HEVC };
52+
// Undefined until we know the specific requested encoder, because an
53+
// exception is thrown if libheif is built without support for it.
54+
heif::Encoder m_encoder { heif_compression_undefined };
5355
std::vector<unsigned char> scratch;
5456
std::vector<unsigned char> m_tilebuffer;
5557
int m_bitdepth = 0;
@@ -140,12 +142,13 @@ HeifOutput::open(const std::string& name, const ImageSpec& newspec,
140142
m_himage.add_plane(heif_channel_interleaved, newspec.width,
141143
newspec.height, m_bitdepth);
142144

143-
m_encoder = heif::Encoder(heif_compression_HEVC);
144145
auto compqual = m_spec.decode_compression_metadata("", 75);
145146
auto extension = Filesystem::extension(m_filename);
146147
if (compqual.first == "avif"
147148
|| (extension == ".avif" && compqual.first == "")) {
148149
m_encoder = heif::Encoder(heif_compression_AV1);
150+
} else {
151+
m_encoder = heif::Encoder(heif_compression_HEVC);
149152
}
150153
} catch (const heif::Error& err) {
151154
std::string e = err.get_message();

0 commit comments

Comments
 (0)