
This delegates loading of Wasm modules to Webpack itself, making wrapper code simpler. Emscripten-generated modules are still using custom loading glue as they're not compatible with Webpack.
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
import * as wasm from './resize_bg.wasm';
|
|
|
|
let cachegetUint8Memory = null;
|
|
function getUint8Memory() {
|
|
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
|
|
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
|
|
}
|
|
return cachegetUint8Memory;
|
|
}
|
|
|
|
let WASM_VECTOR_LEN = 0;
|
|
|
|
function passArray8ToWasm(arg) {
|
|
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
|
|
getUint8Memory().set(arg, ptr / 1);
|
|
WASM_VECTOR_LEN = arg.length;
|
|
return ptr;
|
|
}
|
|
|
|
let cachegetInt32Memory = null;
|
|
function getInt32Memory() {
|
|
if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) {
|
|
cachegetInt32Memory = new Int32Array(wasm.memory.buffer);
|
|
}
|
|
return cachegetInt32Memory;
|
|
}
|
|
|
|
function getArrayU8FromWasm(ptr, len) {
|
|
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
|
|
}
|
|
/**
|
|
* @param {Uint8Array} input_image
|
|
* @param {number} input_width
|
|
* @param {number} input_height
|
|
* @param {number} output_width
|
|
* @param {number} output_height
|
|
* @param {number} typ_idx
|
|
* @param {boolean} premultiply
|
|
* @param {boolean} color_space_conversion
|
|
* @returns {Uint8Array}
|
|
*/
|
|
export function resize(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {
|
|
const retptr = 8;
|
|
const ret = wasm.resize(retptr, passArray8ToWasm(input_image), WASM_VECTOR_LEN, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);
|
|
const memi32 = getInt32Memory();
|
|
const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
|
|
wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1);
|
|
return v0;
|
|
}
|
|
|