
Updated to use new libdeflate integration that I implemented upstream in https://github.com/shssoichiro/oxipng/pull/203.
61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
import * as wasm from './oxipng_bg.wasm';
|
|
|
|
const lTextDecoder = typeof TextDecoder === 'undefined' ? require('util').TextDecoder : TextDecoder;
|
|
|
|
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
|
|
cachedTextDecoder.decode();
|
|
|
|
let cachegetUint8Memory0 = null;
|
|
function getUint8Memory0() {
|
|
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
|
|
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
}
|
|
return cachegetUint8Memory0;
|
|
}
|
|
|
|
function getStringFromWasm0(ptr, len) {
|
|
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
}
|
|
|
|
let WASM_VECTOR_LEN = 0;
|
|
|
|
function passArray8ToWasm0(arg, malloc) {
|
|
const ptr = malloc(arg.length * 1);
|
|
getUint8Memory0().set(arg, ptr / 1);
|
|
WASM_VECTOR_LEN = arg.length;
|
|
return ptr;
|
|
}
|
|
|
|
let cachegetInt32Memory0 = null;
|
|
function getInt32Memory0() {
|
|
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
}
|
|
return cachegetInt32Memory0;
|
|
}
|
|
|
|
function getArrayU8FromWasm0(ptr, len) {
|
|
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
}
|
|
/**
|
|
* @param {Uint8Array} data
|
|
* @param {number} level
|
|
* @returns {Uint8Array}
|
|
*/
|
|
export function optimise(data, level) {
|
|
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
var len0 = WASM_VECTOR_LEN;
|
|
wasm.optimise(8, ptr0, len0, level);
|
|
var r0 = getInt32Memory0()[8 / 4 + 0];
|
|
var r1 = getInt32Memory0()[8 / 4 + 1];
|
|
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
wasm.__wbindgen_free(r0, r1 * 1);
|
|
return v1;
|
|
}
|
|
|
|
export const __wbindgen_throw = function(arg0, arg1) {
|
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
};
|
|
|