/*!
*  filename: openjpeg.js
*  version : 33.2.5
*  Copyright Syncfusion Inc. 2001 - 2025. All rights reserved.
*  Use of this code is subject to the terms of our license.
*  A copy of the current license can be obtained at any time by e-mailing
*  licensing@syncfusion.com. Any infringement will be prosecuted under
*  applicable laws. 
*/
/* THIS FILE IS GENERATED - DO NOT EDIT */
var OpenJpegModule = ( () => {

    return (function(OpenJpegModule ={}) {
        var Module = typeof OpenJpegModule  != "undefined" ? OpenJpegModule  : {};
        var ENVIRONMENT_IS_WEB = typeof window == "object";
        var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined";
        var ENVIRONMENT_IS_NODE = typeof process == "object" && process.versions && process.versions.node && process.type != "renderer";
        var arguments_ = [];
        var thisProgram = "./this.program";
        var quit_ = (status, toThrow) => {
            throw toThrow
        };
        var _scriptName = typeof document != "undefined" ? document.currentScript && document.currentScript.src : undefined;
        if (typeof __filename != "undefined") {
            _scriptName = __filename
        } else if (ENVIRONMENT_IS_WORKER) {
            _scriptName = self.location.href
        }
        var scriptDirectory = "";
        function locateFile(path) {
            if (Module["locateFile"]) {
                return Module["locateFile"](path, scriptDirectory)
            }
            return scriptDirectory + path
        }
        var readAsync, readBinary;
        if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
            try {
                scriptDirectory = new URL(".",_scriptName).href
            } catch {}
            {
                readAsync = async url => {
                    var response = await fetch(url, {
                        credentials: "same-origin"
                    });
                    if (response.ok) {
                        return response.arrayBuffer()
                    }
                    throw new Error(response.status + " : " + response.url)
                }
            }
        } else {}
        var out = console.log.bind(console);
        var err = console.error.bind(console);
        var wasmBinary;
        var wasmMemory;
        var ABORT = false;
        var EXITSTATUS;
        var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAP64, HEAPU64, HEAPF64;
        var runtimeInitialized = false;
        function updateMemoryViews() {
            var b = wasmMemory.buffer;
            HEAP8 = new Int8Array(b);
            HEAP16 = new Int16Array(b);
            HEAPU8 = new Uint8Array(b);
            HEAPU16 = new Uint16Array(b);
            HEAP32 = new Int32Array(b);
            HEAPU32 = new Uint32Array(b);
            HEAPF32 = new Float32Array(b);
            HEAPF64 = new Float64Array(b);
            HEAP64 = new BigInt64Array(b);
            HEAPU64 = new BigUint64Array(b)
        }
        function preRun() {
            if (Module["preRun"]) {
                if (typeof Module["preRun"] == "function")
                    Module["preRun"] = [Module["preRun"]];
                while (Module["preRun"].length) {
                    addOnPreRun(Module["preRun"].shift())
                }
            }
            callRuntimeCallbacks(onPreRuns)
        }
        function initRuntime() {
            runtimeInitialized = true;
            wasmExports["t"]()
        }
        function postRun() {
            if (Module["postRun"]) {
                if (typeof Module["postRun"] == "function")
                    Module["postRun"] = [Module["postRun"]];
                while (Module["postRun"].length) {
                    addOnPostRun(Module["postRun"].shift())
                }
            }
            callRuntimeCallbacks(onPostRuns)
        }
        var runDependencies = 0;
        var dependenciesFulfilled = null;
        function addRunDependency(id) {
            runDependencies++;
            Module["monitorRunDependencies"]?.(runDependencies)
        }
        function removeRunDependency(id) {
            runDependencies--;
            Module["monitorRunDependencies"]?.(runDependencies);
            if (runDependencies == 0) {
                if (dependenciesFulfilled) {
                    var callback = dependenciesFulfilled;
                    dependenciesFulfilled = null;
                    callback()
                }
            }
        }
        function abort(what) {
            Module["onAbort"]?.(what);
            what = "Aborted(" + what + ")";
            err(what);
            ABORT = true;
            what += ". Build with -sASSERTIONS for more info.";
            var e = new WebAssembly.RuntimeError(what);
            readyPromiseReject(e);
            throw e
        }
        var dataURIPrefix = "data:application/octet-stream;base64,";
        function isDataURI(filename) {
            return filename.startsWith(dataURIPrefix)
        }
        var wasmBinaryFile;
        function findWasmBinary() {
            var wasmBinaryFile;
            if (OpenJpegModule.url) {
                wasmBinaryFile = OpenJpegModule.url + '/openjpeg.wasm';
            }
            else {
                wasmBinaryFile = 'openjpeg.wasm';
            }
            if (!isDataURI(wasmBinaryFile)) {
                wasmBinaryFile = locateFile(wasmBinaryFile)
            }
            return locateFile(wasmBinaryFile)
        }
        function getBinarySync(file) {
            if (file == wasmBinaryFile && wasmBinary) {
                return new Uint8Array(wasmBinary)
            }
            if (readBinary) {
                return readBinary(file)
            }
            throw "both async and sync fetching of the wasm failed"
        }
        async function getWasmBinary(binaryFile) {
            if (!wasmBinary) {
                try {
                    var response = await readAsync(binaryFile);
                    return new Uint8Array(response)
                } catch {}
            }
            return getBinarySync(binaryFile)
        }
        async function instantiateArrayBuffer(binaryFile, imports) {
            try {
                var binary = await getWasmBinary(binaryFile);
                var instance = await WebAssembly.instantiate(binary, imports);
                return instance
            } catch (reason) {
                err(`failed to asynchronously prepare wasm: ${reason}`);
                abort(reason)
            }
        }
        async function instantiateAsync(binary, binaryFile, imports) {
            if (!binary && typeof WebAssembly.instantiateStreaming == "function") {
                try {
                    var response = fetch(binaryFile, {
                        credentials: "same-origin"
                    });
                    var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
                    return instantiationResult
                } catch (reason) {
                    err(`wasm streaming compile failed: ${reason}`);
                    err("falling back to ArrayBuffer instantiation")
                }
            }
            return instantiateArrayBuffer(binaryFile, imports)
        }
        function getWasmImports() {
            return {
                a: wasmImports
            }
        }
        async function createWasm() {
            function receiveInstance(instance, module) {
                wasmExports = instance.exports;
                wasmMemory = wasmExports["s"];
                updateMemoryViews();
                removeRunDependency("wasm-instantiate");
                return wasmExports
            }
            addRunDependency("wasm-instantiate");
            function receiveInstantiationResult(result) {
                return receiveInstance(result["instance"])
            }
            var info = getWasmImports();
            // if (Module["instantiateWasm"]) {
            //     return new Promise( (resolve, reject) => {
            //         Module["instantiateWasm"](info, (mod, inst) => {
            //             resolve(receiveInstance(mod, inst))
            //         }
            //         )
            //     }
            //     )
            // }
            wasmBinaryFile ??= findWasmBinary();
            try {
                var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
                var exports = receiveInstantiationResult(result);
                        var ___wasm_call_ctors = exports["t"];
        var _malloc = Module["_malloc"] = exports["u"];
        var _free = Module["_free"] = exports["v"];
        var _jp2_decode = Module["_jp2_decode"] = exports["w"];
                return exports
            } catch (e) {
                readyPromiseReject(e);
                return Promise.reject(e)
            }
        }
        class ExitStatus {
            name = "ExitStatus";
            constructor(status) {
                this.message = `Program terminated with exit(${status})`;
                this.status = status
            }
        }
        var callRuntimeCallbacks = callbacks => {
            while (callbacks.length > 0) {
                callbacks.shift()(Module)
            }
        }
        ;
        var onPostRuns = [];
        var addOnPostRun = cb => onPostRuns.push(cb);
        var onPreRuns = [];
        var addOnPreRun = cb => onPreRuns.push(cb);
        var noExitRuntime = true;
        var __abort_js = () => abort("");
        var runtimeKeepaliveCounter = 0;
        var __emscripten_runtime_keepalive_clear = () => {
            noExitRuntime = false;
            runtimeKeepaliveCounter = 0
        }
        ;
        var timers = {};
        var handleException = e => {
            if (e instanceof ExitStatus || e == "unwind") {
                return EXITSTATUS
            }
            quit_(1, e)
        }
        ;
        var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
        var _proc_exit = code => {
            EXITSTATUS = code;
            if (!keepRuntimeAlive()) {
                Module["onExit"]?.(code);
                ABORT = true
            }
            quit_(code, new ExitStatus(code))
        }
        ;
        var exitJS = (status, implicit) => {
            EXITSTATUS = status;
            _proc_exit(status)
        }
        ;
        var _exit = exitJS;
        var maybeExit = () => {
            if (!keepRuntimeAlive()) {
                try {
                    _exit(EXITSTATUS)
                } catch (e) {
                    handleException(e)
                }
            }
        }
        ;
        var callUserCallback = func => {
            if (ABORT) {
                return
            }
            try {
                func();
                maybeExit()
            } catch (e) {
                handleException(e)
            }
        }
        ;
        var _emscripten_get_now = () => performance.now();
        var __setitimer_js = (which, timeout_ms) => {
            if (timers[which]) {
                clearTimeout(timers[which].id);
                delete timers[which]
            }
            if (!timeout_ms)
                return 0;
            var id = setTimeout( () => {
                delete timers[which];
                callUserCallback( () => __emscripten_timeout(which, _emscripten_get_now()))
            }
            , timeout_ms);
            timers[which] = {
                id,
                timeout_ms
            };
            return 0
        }
        ;
        function _copy_pixels_1(compG_ptr, nb_pixels) {
            compG_ptr >>= 2;
            const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels);
            const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels);
            imageData.set(compG)
        }
        function _copy_pixels_3(compR_ptr, compG_ptr, compB_ptr, nb_pixels) {
            compR_ptr >>= 2;
            compG_ptr >>= 2;
            compB_ptr >>= 2;
            const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 3);
            const compR = HEAP32.subarray(compR_ptr, compR_ptr + nb_pixels);
            const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels);
            const compB = HEAP32.subarray(compB_ptr, compB_ptr + nb_pixels);
            for (let i = 0; i < nb_pixels; i++) {
                imageData[3 * i] = compR[i];
                imageData[3 * i + 1] = compG[i];
                imageData[3 * i + 2] = compB[i]
            }
        }
        function _copy_pixels_4(compR_ptr, compG_ptr, compB_ptr, compA_ptr, nb_pixels) {
            compR_ptr >>= 2;
            compG_ptr >>= 2;
            compB_ptr >>= 2;
            compA_ptr >>= 2;
            const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4);
            const compR = HEAP32.subarray(compR_ptr, compR_ptr + nb_pixels);
            const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels);
            const compB = HEAP32.subarray(compB_ptr, compB_ptr + nb_pixels);
            const compA = HEAP32.subarray(compA_ptr, compA_ptr + nb_pixels);
            for (let i = 0; i < nb_pixels; i++) {
                imageData[4 * i] = compR[i];
                imageData[4 * i + 1] = compG[i];
                imageData[4 * i + 2] = compB[i];
                imageData[4 * i + 3] = compA[i]
            }
        }
        var getHeapMax = () => 2147483648;
        var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;
        var growMemory = size => {
            var b = wasmMemory.buffer;
            var pages = (size - b.byteLength + 65535) / 65536 | 0;
            try {
                wasmMemory.grow(pages);
                updateMemoryViews();
                return 1
            } catch (e) {}
        }
        ;
        var _emscripten_resize_heap = requestedSize => {
            var oldSize = HEAPU8.length;
            requestedSize >>>= 0;
            var maxHeapSize = getHeapMax();
            if (requestedSize > maxHeapSize) {
                return false
            }
            for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
                var overGrownHeapSize = oldSize * (1 + .2 / cutDown);
                overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
                var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
                var replacement = growMemory(newSize);
                if (replacement) {
                    return true
                }
            }
            return false
        }
        ;
        var ENV = {};
        var getExecutableName = () => thisProgram || "./this.program";
        var getEnvStrings = () => {
            if (!getEnvStrings.strings) {
                var lang = (typeof navigator == "object" && navigator.languages && navigator.languages[0] || "C").replace("-", "_") + ".UTF-8";
                var env = {
                    USER: "web_user",
                    LOGNAME: "web_user",
                    PATH: "/",
                    PWD: "/",
                    HOME: "/home/web_user",
                    LANG: lang,
                    _: getExecutableName()
                };
                for (var x in ENV) {
                    if (ENV[x] === undefined)
                        delete env[x];
                    else
                        env[x] = ENV[x]
                }
                var strings = [];
                for (var x in env) {
                    strings.push(`${x}=${env[x]}`)
                }
                getEnvStrings.strings = strings
            }
            return getEnvStrings.strings
        }
        ;
        var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
            if (!(maxBytesToWrite > 0))
                return 0;
            var startIdx = outIdx;
            var endIdx = outIdx + maxBytesToWrite - 1;
            for (var i = 0; i < str.length; ++i) {
                var u = str.charCodeAt(i);
                if (u >= 55296 && u <= 57343) {
                    var u1 = str.charCodeAt(++i);
                    u = 65536 + ((u & 1023) << 10) | u1 & 1023
                }
                if (u <= 127) {
                    if (outIdx >= endIdx)
                        break;
                    heap[outIdx++] = u
                } else if (u <= 2047) {
                    if (outIdx + 1 >= endIdx)
                        break;
                    heap[outIdx++] = 192 | u >> 6;
                    heap[outIdx++] = 128 | u & 63
                } else if (u <= 65535) {
                    if (outIdx + 2 >= endIdx)
                        break;
                    heap[outIdx++] = 224 | u >> 12;
                    heap[outIdx++] = 128 | u >> 6 & 63;
                    heap[outIdx++] = 128 | u & 63
                } else {
                    if (outIdx + 3 >= endIdx)
                        break;
                    heap[outIdx++] = 240 | u >> 18;
                    heap[outIdx++] = 128 | u >> 12 & 63;
                    heap[outIdx++] = 128 | u >> 6 & 63;
                    heap[outIdx++] = 128 | u & 63
                }
            }
            heap[outIdx] = 0;
            return outIdx - startIdx
        }
        ;
        var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
        var _environ_get = (__environ, environ_buf) => {
            var bufSize = 0;
            var envp = 0;
            for (var string of getEnvStrings()) {
                var ptr = environ_buf + bufSize;
                HEAPU32[__environ + envp >> 2] = ptr;
                bufSize += stringToUTF8(string, ptr, Infinity) + 1;
                envp += 4
            }
            return 0
        }
        ;
        var lengthBytesUTF8 = str => {
            var len = 0;
            for (var i = 0; i < str.length; ++i) {
                var c = str.charCodeAt(i);
                if (c <= 127) {
                    len++
                } else if (c <= 2047) {
                    len += 2
                } else if (c >= 55296 && c <= 57343) {
                    len += 4;
                    ++i
                } else {
                    len += 3
                }
            }
            return len
        }
        ;
        var _environ_sizes_get = (penviron_count, penviron_buf_size) => {
            var strings = getEnvStrings();
            HEAPU32[penviron_count >> 2] = strings.length;
            var bufSize = 0;
            for (var string of strings) {
                bufSize += lengthBytesUTF8(string) + 1
            }
            HEAPU32[penviron_buf_size >> 2] = bufSize;
            return 0
        }
        ;
        var _fd_close = fd => 52;
        var INT53_MAX = 9007199254740992;
        var INT53_MIN = -9007199254740992;
        var bigintToI53Checked = num => num < INT53_MIN || num > INT53_MAX ? NaN : Number(num);
        function _fd_seek(fd, offset, whence, newOffset) {
            offset = bigintToI53Checked(offset);
            return 70
        }
        var printCharBuffers = [null, [], []];
        var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder : undefined;
        var UTF8ArrayToString = (heapOrArray, idx=0, maxBytesToRead=NaN) => {
            var endIdx = idx + maxBytesToRead;
            var endPtr = idx;
            while (heapOrArray[endPtr] && !(endPtr >= endIdx))
                ++endPtr;
            if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
                return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr))
            }
            var str = "";
            while (idx < endPtr) {
                var u0 = heapOrArray[idx++];
                if (!(u0 & 128)) {
                    str += String.fromCharCode(u0);
                    continue
                }
                var u1 = heapOrArray[idx++] & 63;
                if ((u0 & 224) == 192) {
                    str += String.fromCharCode((u0 & 31) << 6 | u1);
                    continue
                }
                var u2 = heapOrArray[idx++] & 63;
                if ((u0 & 240) == 224) {
                    u0 = (u0 & 15) << 12 | u1 << 6 | u2
                } else {
                    u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63
                }
                if (u0 < 65536) {
                    str += String.fromCharCode(u0)
                } else {
                    var ch = u0 - 65536;
                    str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023)
                }
            }
            return str
        }
        ;
        var printChar = (stream, curr) => {
            var buffer = printCharBuffers[stream];
            if (curr === 0 || curr === 10) {
                (stream === 1 ? out : err)(UTF8ArrayToString(buffer));
                buffer.length = 0
            } else {
                buffer.push(curr)
            }
        }
        ;
        var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
        var _fd_write = (fd, iov, iovcnt, pnum) => {
            var num = 0;
            for (var i = 0; i < iovcnt; i++) {
                var ptr = HEAPU32[iov >> 2];
                var len = HEAPU32[iov + 4 >> 2];
                iov += 8;
                for (var j = 0; j < len; j++) {
                    printChar(fd, HEAPU8[ptr + j])
                }
                num += len
            }
            HEAPU32[pnum >> 2] = num;
            return 0
        }
        ;
        function _gray_to_rgba(compG_ptr, nb_pixels) {
            compG_ptr >>= 2;
            const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4);
            const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels);
            for (let i = 0; i < nb_pixels; i++) {
                imageData[4 * i] = imageData[4 * i + 1] = imageData[4 * i + 2] = compG[i];
                imageData[4 * i + 3] = 255
            }
        }
        function _graya_to_rgba(compG_ptr, compA_ptr, nb_pixels) {
            compG_ptr >>= 2;
            compA_ptr >>= 2;
            const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4);
            const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels);
            const compA = HEAP32.subarray(compA_ptr, compA_ptr + nb_pixels);
            for (let i = 0; i < nb_pixels; i++) {
                imageData[4 * i] = imageData[4 * i + 1] = imageData[4 * i + 2] = compG[i];
                imageData[4 * i + 3] = compA[i]
            }
        }
        function _jsPrintWarning(message_ptr) {
            const message = UTF8ToString(message_ptr);
            (Module.warn || console.warn)(`OpenJPEG: ${message}`)
        }
        function _rgb_to_rgba(compR_ptr, compG_ptr, compB_ptr, nb_pixels) {
            compR_ptr >>= 2;
            compG_ptr >>= 2;
            compB_ptr >>= 2;
            const imageData = Module.imageData = new Uint8ClampedArray(nb_pixels * 4);
            const compR = HEAP32.subarray(compR_ptr, compR_ptr + nb_pixels);
            const compG = HEAP32.subarray(compG_ptr, compG_ptr + nb_pixels);
            const compB = HEAP32.subarray(compB_ptr, compB_ptr + nb_pixels);
            for (let i = 0; i < nb_pixels; i++) {
                imageData[4 * i] = compR[i];
                imageData[4 * i + 1] = compG[i];
                imageData[4 * i + 2] = compB[i];
                imageData[4 * i + 3] = 255
            }
        }
        function _storeErrorMessage(message_ptr) {
            const message = UTF8ToString(message_ptr);
            if (!Module.errorMessages) {
                Module.errorMessages = message
            } else {
                Module.errorMessages += "\n" + message
            }
        }
        var writeArrayToMemory = (array, buffer) => {
            HEAP8.set(array, buffer)
        }
        ;
        {
            if (Module["noExitRuntime"])
                noExitRuntime = Module["noExitRuntime"];
            if (Module["print"])
                out = Module["print"];
            if (Module["printErr"])
                err = Module["printErr"];
            if (Module["wasmBinary"])
                wasmBinary = Module["wasmBinary"];
            // if (Module["arguments"])
            //     arguments_ = Module["arguments"];
            if (Module["thisProgram"])
                thisProgram = Module["thisProgram"]
        }
        Module["writeArrayToMemory"] = writeArrayToMemory;
        var wasmImports = {
            l: __abort_js,
            k: __emscripten_runtime_keepalive_clear,
            m: __setitimer_js,
            g: _copy_pixels_1,
            f: _copy_pixels_3,
            e: _copy_pixels_4,
            n: _emscripten_resize_heap,
            p: _environ_get,
            q: _environ_sizes_get,
            b: _fd_close,
            o: _fd_seek,
            c: _fd_write,
            r: _gray_to_rgba,
            i: _graya_to_rgba,
            d: _jsPrintWarning,
            j: _proc_exit,
            h: _rgb_to_rgba,
            a: _storeErrorMessage
        };
        var wasmExports = createWasm();
        var __emscripten_timeout = wasmExports["x"];
        function run() {
            if (runDependencies > 0) {
                dependenciesFulfilled = run;
                return
            }
            preRun();
            if (runDependencies > 0) {
                dependenciesFulfilled = run;
                return
            }
            function doRun() {
                Module["calledRun"] = true;
                if (ABORT)
                    return;
                initRuntime();
                //readyPromiseResolve(Module);
                Module["onRuntimeInitialized"]?.();
                postRun()
            }
            if (Module["setStatus"]) {
                Module["setStatus"]("Running...");
                setTimeout( () => {
                    setTimeout( () => Module["setStatus"](""), 1);
                    doRun()
                }
                , 1)
            } else {
                doRun()
            }
        }
        function preInit() {
            if (Module["preInit"]) {
                if (typeof Module["preInit"] == "function")
                    Module["preInit"] = [Module["preInit"]];
                while (Module["preInit"].length > 0) {
                    Module["preInit"].shift()()
                }
            }
        }
        preInit();
        run();
        return OpenJpegModule.ready
    }
    );
}
)();
if (typeof exports === 'object' && typeof module === 'object')
    module.exports = OpenJpegModule;
else if (typeof define === 'function' && define['amd'])
    define([], function () {
        return OpenJpegModule;
    });
else if (typeof exports === 'object')
    exports["OpenJpegModule"] = OpenJpegModule;