summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authormio <[email protected]>2024-10-01 16:40:37 +1000
committermio <[email protected]>2024-10-01 16:40:37 +1000
commit508ae3fc06f4c4407eab9fc38e951d168a2e0519 (patch)
treeb56a79e69098e458a332cd413ea6dbad1bcb4d48 /kernel
parent39d98694a71e1af634ae23723775421bea09a778 (diff)
downloadlibksquirrel-508ae3fc06f4c4407eab9fc38e951d168a2e0519.tar.gz
libksquirrel-508ae3fc06f4c4407eab9fc38e951d168a2e0519.zip
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 <[email protected]>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/kls_jpeg2000/fmt_codec_jpeg2000.cpp66
1 files changed, 64 insertions, 2 deletions
diff --git a/kernel/kls_jpeg2000/fmt_codec_jpeg2000.cpp b/kernel/kls_jpeg2000/fmt_codec_jpeg2000.cpp
index 4b54009..b5a0eee 100644
--- a/kernel/kls_jpeg2000/fmt_codec_jpeg2000.cpp
+++ b/kernel/kls_jpeg2000/fmt_codec_jpeg2000.cpp
@@ -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])