|
| 1 | +const {readFile} = require('fs').promises; |
| 2 | +const {join} = require('path'); |
| 3 | + |
| 4 | +let wasm = new Promise(async resolve => { |
| 5 | + const module = new WebAssembly.Module(await readFile(join(__dirname, './jpeg.wasm'))); |
| 6 | + const instance = new WebAssembly.Instance(module); |
| 7 | + const wasm = instance.exports; |
| 8 | + |
| 9 | + resolve(wasm); |
| 10 | +}); |
| 11 | + |
| 12 | +let cachegetUint8Memory0 = null; |
| 13 | + |
| 14 | +function getUint8Memory0() { |
| 15 | + if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) { |
| 16 | + cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer); |
| 17 | + } |
| 18 | + return cachegetUint8Memory0; |
| 19 | +} |
| 20 | + |
| 21 | +let WASM_VECTOR_LEN = 0; |
| 22 | + |
| 23 | +function passArray8ToWasm0(arg, malloc) { |
| 24 | + const ptr = malloc(arg.length * 1); |
| 25 | + getUint8Memory0().set(arg, ptr / 1); |
| 26 | + WASM_VECTOR_LEN = arg.length; |
| 27 | + return ptr; |
| 28 | +} |
| 29 | + |
| 30 | +let cachegetInt32Memory0 = null; |
| 31 | + |
| 32 | +function getInt32Memory0() { |
| 33 | + if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { |
| 34 | + cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); |
| 35 | + } |
| 36 | + return cachegetInt32Memory0; |
| 37 | +} |
| 38 | + |
| 39 | +let cachegetUint16Memory0 = null; |
| 40 | + |
| 41 | +function getUint16Memory0() { |
| 42 | + if (cachegetUint16Memory0 === null || cachegetUint16Memory0.buffer !== wasm.memory.buffer) { |
| 43 | + cachegetUint16Memory0 = new Uint16Array(wasm.memory.buffer); |
| 44 | + } |
| 45 | + return cachegetUint16Memory0; |
| 46 | +} |
| 47 | + |
| 48 | +function getArrayU16FromWasm0(ptr, len) { |
| 49 | + return getUint16Memory0().subarray(ptr / 2, ptr / 2 + len); |
| 50 | +} |
| 51 | + |
| 52 | +function getArrayU8FromWasm0(ptr, len) { |
| 53 | + return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); |
| 54 | +} |
| 55 | + |
| 56 | +module.exports = { |
| 57 | + /** |
| 58 | + * @param {number} ptr |
| 59 | + * @param {Uint8Array} buffer |
| 60 | + * @param {number} _width |
| 61 | + * @param {number} _height |
| 62 | + * @returns {number} |
| 63 | + */ |
| 64 | + async decode(ptr, buffer, _width, _height) { |
| 65 | + wasm = await wasm; |
| 66 | + const ptr0 = passArray8ToWasm0(buffer, wasm.__wbindgen_malloc); |
| 67 | + return wasm.decode(ptr, ptr0, WASM_VECTOR_LEN, _width, _height); |
| 68 | + }, |
| 69 | + /** |
| 70 | + * @param {number} id |
| 71 | + * @returns {Uint16Array} |
| 72 | + */ |
| 73 | + meta(id) { |
| 74 | + try { |
| 75 | + const retptr = wasm.__wbindgen_export_1.value - 16; |
| 76 | + wasm.__wbindgen_export_1.value = retptr; |
| 77 | + wasm.meta(retptr, id); |
| 78 | + const r0 = getInt32Memory0()[retptr / 4]; |
| 79 | + const r1 = getInt32Memory0()[retptr / 4 + 1]; |
| 80 | + const v0 = getArrayU16FromWasm0(r0, r1).slice(); |
| 81 | + wasm.__wbindgen_free(r0, r1 * 2); |
| 82 | + return v0; |
| 83 | + } finally { |
| 84 | + wasm.__wbindgen_export_1.value += 16; |
| 85 | + } |
| 86 | + }, |
| 87 | + /** |
| 88 | + * @param {number} id |
| 89 | + * @returns {Uint8Array} |
| 90 | + */ |
| 91 | + buffer(id) { |
| 92 | + try { |
| 93 | + const retptr = wasm.__wbindgen_export_1.value - 16; |
| 94 | + wasm.__wbindgen_export_1.value = retptr; |
| 95 | + wasm.buffer(retptr, id); |
| 96 | + const r0 = getInt32Memory0()[retptr / 4]; |
| 97 | + const r1 = getInt32Memory0()[retptr / 4 + 1]; |
| 98 | + const v0 = getArrayU8FromWasm0(r0, r1).slice(); |
| 99 | + wasm.__wbindgen_free(r0, r1 * 1); |
| 100 | + return v0; |
| 101 | + } finally { |
| 102 | + wasm.__wbindgen_export_1.value += 16; |
| 103 | + } |
| 104 | + }, |
| 105 | + /** |
| 106 | + * @param {number} id |
| 107 | + */ |
| 108 | + free(id) { |
| 109 | + wasm.free(id); |
| 110 | + } |
| 111 | +}; |
| 112 | + |
0 commit comments