mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 00:58:15 -04:00
heif: enable saving of hej2 format
This commit is contained in:
parent
cdf3be3af1
commit
9bee29cc01
@ -31,6 +31,7 @@ bool HEIFHandler::m_plugins_queried = false;
|
|||||||
bool HEIFHandler::m_heif_decoder_available = false;
|
bool HEIFHandler::m_heif_decoder_available = false;
|
||||||
bool HEIFHandler::m_heif_encoder_available = false;
|
bool HEIFHandler::m_heif_encoder_available = false;
|
||||||
bool HEIFHandler::m_hej2_decoder_available = false;
|
bool HEIFHandler::m_hej2_decoder_available = false;
|
||||||
|
bool HEIFHandler::m_hej2_encoder_available = false;
|
||||||
bool HEIFHandler::m_avci_decoder_available = false;
|
bool HEIFHandler::m_avci_decoder_available = false;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -154,6 +155,14 @@ bool HEIFHandler::write_helper(const QImage &image)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heif_compression_format encoder_codec = heif_compression_HEVC;
|
||||||
|
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||||
|
if (format() == "hej2") {
|
||||||
|
encoder_codec = heif_compression_JPEG2000;
|
||||||
|
save_depth = 8; // for compatibility reasons
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
heif_chroma chroma;
|
heif_chroma chroma;
|
||||||
if (save_depth > 8) {
|
if (save_depth > 8) {
|
||||||
if (save_alpha) {
|
if (save_alpha) {
|
||||||
@ -286,7 +295,7 @@ bool HEIFHandler::write_helper(const QImage &image)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct heif_encoder *encoder = nullptr;
|
struct heif_encoder *encoder = nullptr;
|
||||||
err = heif_context_get_encoder_for_format(context, heif_compression_HEVC, &encoder);
|
err = heif_context_get_encoder_for_format(context, encoder_codec, &encoder);
|
||||||
if (err.code) {
|
if (err.code) {
|
||||||
qWarning() << "Unable to get an encoder instance:" << err.message;
|
qWarning() << "Unable to get an encoder instance:" << err.message;
|
||||||
heif_image_release(h_image);
|
heif_image_release(h_image);
|
||||||
@ -1019,6 +1028,13 @@ bool HEIFHandler::isHej2DecoderAvailable()
|
|||||||
return m_hej2_decoder_available;
|
return m_hej2_decoder_available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HEIFHandler::isHej2EncoderAvailable()
|
||||||
|
{
|
||||||
|
HEIFHandler::queryHeifLib();
|
||||||
|
|
||||||
|
return m_hej2_encoder_available;
|
||||||
|
}
|
||||||
|
|
||||||
bool HEIFHandler::isAVCIDecoderAvailable()
|
bool HEIFHandler::isAVCIDecoderAvailable()
|
||||||
{
|
{
|
||||||
HEIFHandler::queryHeifLib();
|
HEIFHandler::queryHeifLib();
|
||||||
@ -1041,6 +1057,7 @@ void HEIFHandler::queryHeifLib()
|
|||||||
m_heif_decoder_available = heif_have_decoder_for_format(heif_compression_HEVC);
|
m_heif_decoder_available = heif_have_decoder_for_format(heif_compression_HEVC);
|
||||||
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||||
m_hej2_decoder_available = heif_have_decoder_for_format(heif_compression_JPEG2000);
|
m_hej2_decoder_available = heif_have_decoder_for_format(heif_compression_JPEG2000);
|
||||||
|
m_hej2_encoder_available = heif_have_encoder_for_format(heif_compression_JPEG2000);
|
||||||
#endif
|
#endif
|
||||||
#if LIBHEIF_HAVE_VERSION(1, 19, 6)
|
#if LIBHEIF_HAVE_VERSION(1, 19, 6)
|
||||||
m_avci_decoder_available = heif_have_decoder_for_format(heif_compression_AVC);
|
m_avci_decoder_available = heif_have_decoder_for_format(heif_compression_AVC);
|
||||||
@ -1109,6 +1126,9 @@ QImageIOPlugin::Capabilities HEIFPlugin::capabilities(QIODevice *device, const Q
|
|||||||
if (HEIFHandler::isHej2DecoderAvailable()) {
|
if (HEIFHandler::isHej2DecoderAvailable()) {
|
||||||
format_cap |= CanRead;
|
format_cap |= CanRead;
|
||||||
}
|
}
|
||||||
|
if (HEIFHandler::isHej2EncoderAvailable()) {
|
||||||
|
format_cap |= CanWrite;
|
||||||
|
}
|
||||||
return format_cap;
|
return format_cap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1138,7 +1158,7 @@ QImageIOPlugin::Capabilities HEIFPlugin::capabilities(QIODevice *device, const Q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device->isWritable() && HEIFHandler::isHeifEncoderAvailable()) {
|
if (device->isWritable() && (HEIFHandler::isHeifEncoderAvailable() || HEIFHandler::isHej2EncoderAvailable())) {
|
||||||
cap |= CanWrite;
|
cap |= CanWrite;
|
||||||
}
|
}
|
||||||
return cap;
|
return cap;
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
static bool isHeifDecoderAvailable();
|
static bool isHeifDecoderAvailable();
|
||||||
static bool isHeifEncoderAvailable();
|
static bool isHeifEncoderAvailable();
|
||||||
static bool isHej2DecoderAvailable();
|
static bool isHej2DecoderAvailable();
|
||||||
|
static bool isHej2EncoderAvailable();
|
||||||
static bool isAVCIDecoderAvailable();
|
static bool isAVCIDecoderAvailable();
|
||||||
|
|
||||||
static bool isSupportedBMFFType(const QByteArray &header);
|
static bool isSupportedBMFFType(const QByteArray &header);
|
||||||
@ -62,6 +63,7 @@ private:
|
|||||||
static bool m_heif_decoder_available;
|
static bool m_heif_decoder_available;
|
||||||
static bool m_heif_encoder_available;
|
static bool m_heif_encoder_available;
|
||||||
static bool m_hej2_decoder_available;
|
static bool m_hej2_decoder_available;
|
||||||
|
static bool m_hej2_encoder_available;
|
||||||
static bool m_avci_decoder_available;
|
static bool m_avci_decoder_available;
|
||||||
|
|
||||||
static QMutex &getHEIFHandlerMutex();
|
static QMutex &getHEIFHandlerMutex();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user