Use JasPer 3 library initialization routines

Update to use the jas_init_library() and jas_init_thread() functions as
JasPer 3 deprecated jas_init and changed its behaviour to not register
jas_cleanup() as an atexit callback.

Signed-off-by: mio <stigma@disroot.org>
(cherry picked from commit 508ae3fc06)
r14.1.x r14.1.3
mio 2 months ago committed by Michele Calgaro
parent 8ae5191e0d
commit 51f42b6fdf
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -63,14 +63,66 @@
*
*/
static bool jasperInitialized = false;
static void initializeJasper()
{
#if (JAS_VERSION_MAJOR >= 3)
jas_conf_clear();
// Limit JasPer memory usage to at most 512 MB
size_t memoryLimit = (512 * 1024) * 1024;
size_t jasperTotalMem = jas_get_total_mem_size();
if (!jasperTotalMem)
{
jasperTotalMem = JAS_DEFAULT_MAX_MEM_USAGE;
}
memoryLimit = (memoryLimit < jasperTotalMem) ? memoryLimit : jasperTotalMem;
jas_conf_set_max_mem_usage(memoryLimit);
if (!jas_init_library())
{
if (!jas_init_thread())
{
jasperInitialized = true;
}
else
{
jas_cleanup_library();
}
}
#else
if (!jas_init())
{
jasperInitialized = true;
}
#endif
}
static void cleanupJasper()
{
#if (JAS_VERSION_MAJOR >= 3)
if (jasperInitialized)
{
jas_cleanup_thread();
jas_cleanup_library();
}
#else
if (jasperInitialized)
{
jas_cleanup();
}
#endif
}
fmt_codec::fmt_codec() : fmt_codec_base()
{
jas_init();
initializeJasper();
}
fmt_codec::~fmt_codec()
{
jas_cleanup();
cleanupJasper();
}
void fmt_codec::options(codec_options *o)
@ -101,6 +153,11 @@ s32 fmt_codec::read_init(const std::string &file)
gs.data[1] = 0;
gs.data[2] = 0;
if (!jasperInitialized)
{
return SQE_NOTOK;
}
in = jas_stream_fopen(file.c_str(), "rb");
if(!in)
@ -253,6 +310,11 @@ s32 fmt_codec::read_scanline(RGBA *scan)
void fmt_codec::read_close()
{
if (!jasperInitialized)
{
return;
}
for(s32 cmptno = 0; cmptno < 3; ++cmptno)
{
if (gs.data[cmptno])

Loading…
Cancel
Save