heif: use heif_init/heif_deinit with libheif 1.13.0+

In recent libheif, application should use
heif_init/heif_deinit calls. Unfortunately, these calls are
not thread-safe in released 1.13.0 version yet (will be in the
future) and HEIFHandler is often created in different threads.
So we have to guard their use with a mutex.
This commit is contained in:
Daniel Novomeský
2022-09-21 02:30:51 +02:00
parent 20f74ce5e6
commit 9ab64dbf22
2 changed files with 137 additions and 5 deletions

View File

@ -13,6 +13,7 @@
#include <QByteArray>
#include <QImage>
#include <QImageIOPlugin>
#include <QMutex>
class HEIFHandler : public QImageIOHandler
{
@ -29,6 +30,9 @@ public:
void setOption(ImageOption option, const QVariant &value) override;
bool supportsOption(ImageOption option) const override;
static bool isHeifDecoderAvailable();
static bool isHeifEncoderAvailable();
private:
static bool isSupportedBMFFType(const QByteArray &header);
bool ensureParsed() const;
@ -43,6 +47,18 @@ private:
ParseHeicState m_parseState;
int m_quality;
QImage m_current_image;
bool write_helper(const QImage &image);
static void startHeifLib();
static void finishHeifLib();
static size_t m_initialized_count;
static bool m_plugins_queried;
static bool m_heif_decoder_available;
static bool m_heif_encoder_available;
static QMutex &getHEIFHandlerMutex();
};
class HEIFPlugin : public QImageIOPlugin