diff options
Diffstat (limited to 'src/plugins/imageformats/jp2/qjp2handler.cpp')
-rw-r--r-- | src/plugins/imageformats/jp2/qjp2handler.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/plugins/imageformats/jp2/qjp2handler.cpp b/src/plugins/imageformats/jp2/qjp2handler.cpp index ce23480..cb34374 100644 --- a/src/plugins/imageformats/jp2/qjp2handler.cpp +++ b/src/plugins/imageformats/jp2/qjp2handler.cpp @@ -43,8 +43,10 @@ #include "qimage.h" #include "qvariant.h" #include "qcolor.h" +#include "qimagereader.h" #include <jasper/jasper.h> +#include <math.h> // for pow QT_BEGIN_NAMESPACE @@ -308,17 +310,6 @@ bool QJp2Handler::supportsOption(ImageOption option) const return (option == Quality || option == SubType); } -#if QT_DEPRECATED_SINCE(5, 13) -/*! - Return the common identifier of the format. - For JPEG 2000 this will return "jp2". - */ -QByteArray QJp2Handler::name() const -{ - return QByteArrayLiteral("jp2"); -} -#endif - /*! Automatic resource handling for a jas_image_t*. */ @@ -343,16 +334,46 @@ private: Jpeg2000JasperReader::Jpeg2000JasperReader(QIODevice *iod, SubFormat format) : jasperOk(true), ioDevice(iod), format(format), hasAlpha(false) { +#if JAS_VERSION_MAJOR < 3 if (jas_init()) { jasperOk = false; qDebug("Jasper Library initialization failed"); } +#else + jas_conf_clear(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + jas_conf_set_max_mem_usage(QImageReader::allocationLimit() * 1024 * 1024); +#else + // 128MB seems to be enough. + jas_conf_set_max_mem_usage(128 * 1024 * 1024); +#endif + if (jas_init_library()) { + jasperOk = false; + qDebug("Jasper library initialization failed"); + } + if (jas_init_thread()) { + jas_cleanup_library(); + jasperOk = false; + qDebug("Jasper thread initialization failed"); + } +#endif } Jpeg2000JasperReader::~Jpeg2000JasperReader() { +#if JAS_VERSION_MAJOR < 3 if (jasperOk) jas_cleanup(); +#else + if (jasperOk) { + if (jas_cleanup_thread()) { + qDebug("Jasper thread cleanup failed"); + } + if (jas_cleanup_library()) { + qDebug("Jasper library cleanup failed"); + } + } +#endif } /*! \internal @@ -867,7 +888,7 @@ bool Jpeg2000JasperReader::write(const QImage &image, int quality) } // Open an empty jasper stream that grows automatically - jas_stream_t * memory_stream = jas_stream_memopen(0, -1); + jas_stream_t * memory_stream = jas_stream_memopen(0, 0); // Jasper wants a non-const string. char *str = qstrdup(jasperFormatString.toLatin1().constData()); |