mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 16:57:26 +00:00
Compare commits
94 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b7d3fa394 | ||
|
|
650db99818 | ||
|
|
7638bb795e | ||
|
|
570e604be0 | ||
|
|
a056d1c363 | ||
|
|
fce61c8c89 | ||
|
|
d60d0ae47d | ||
|
|
8bf741ed4e | ||
|
|
9f660e5178 | ||
|
|
ef2318bcc1 | ||
|
|
364a5db5d5 | ||
|
|
4a01d0d548 | ||
|
|
4a9c28f89f | ||
|
|
3aed873467 | ||
|
|
2b7f059b8f | ||
|
|
33726e9c68 | ||
|
|
3d29f486e7 | ||
|
|
79e8a26f06 | ||
|
|
e8efd54766 | ||
|
|
edcc774c16 | ||
|
|
746b33a590 | ||
|
|
8a264efc67 | ||
|
|
f0af6e97a0 | ||
|
|
043107c101 | ||
|
|
e9e3b923e0 | ||
|
|
aea6e91b1d | ||
|
|
9c4717a13d | ||
|
|
559cabce9e | ||
|
|
7f6a3de7ca | ||
|
|
f3adc87f52 | ||
|
|
6499e9f63d | ||
|
|
ac1f104e49 | ||
|
|
87f89e6b2f | ||
|
|
7f6404d5a8 | ||
|
|
8e857cd393 | ||
|
|
b8f801333d | ||
|
|
499956e216 | ||
|
|
3932ee2c00 | ||
|
|
68177b7590 | ||
|
|
0a2a4122dc | ||
|
|
e6299569d0 | ||
|
|
578ad8c291 | ||
|
|
eaa294b689 | ||
|
|
6e97cfb8d5 | ||
|
|
80a68c48b2 | ||
|
|
98865f8141 | ||
|
|
78da9fd144 | ||
|
|
94c50a989b | ||
|
|
3e525e767c | ||
|
|
dfcc1e24e4 | ||
|
|
f3aa8edfca | ||
|
|
ffd7ee6013 | ||
|
|
64bb09dbc5 | ||
|
|
35fcbc40ed | ||
|
|
1b55a48680 | ||
|
|
88fbb19d29 | ||
|
|
3dc1501ff7 | ||
|
|
b7576c559a | ||
|
|
69ed2e1d56 | ||
|
|
55f7f3d72a | ||
|
|
055d0b4ea1 | ||
|
|
7735346ed0 | ||
|
|
2a06fdbbe0 | ||
|
|
19169199e9 | ||
|
|
76f3c39b78 | ||
|
|
8da52acc4c | ||
|
|
9253522a3a | ||
|
|
cf39a3e5a5 | ||
|
|
a08877f0ac | ||
|
|
2f0dc1c067 | ||
|
|
535d8c9142 | ||
|
|
6dc2ba3bef | ||
|
|
93cfdc8f98 | ||
|
|
671544349e | ||
|
|
d3c1939692 | ||
|
|
99642aef96 | ||
|
|
ac4942b640 | ||
|
|
23cb004a86 | ||
|
|
4b6de60978 | ||
|
|
de204aa56a | ||
|
|
976f811b36 | ||
|
|
855fc9e602 | ||
|
|
a8848e717c | ||
|
|
90b99faf8b | ||
|
|
d3cfffbbcf | ||
|
|
fade7f9be8 | ||
|
|
b10dd055d3 | ||
|
|
7532f01222 | ||
|
|
2df09efdee | ||
|
|
bed4f49a12 | ||
|
|
2b7fefff8b | ||
|
|
bdcf2519ce | ||
|
|
3f8afb72a6 | ||
|
|
2f834db224 |
@@ -1,21 +1,12 @@
|
|||||||
FROM ubuntu
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -qqy git build-essential cmake python2.7
|
|
||||||
|
|
||||||
RUN git clone --depth 1 --recursive https://github.com/WebAssembly/wabt /usr/src/wabt
|
|
||||||
RUN mkdir -p /usr/src/wabt/build
|
|
||||||
WORKDIR /usr/src/wabt/build
|
|
||||||
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \
|
|
||||||
make && \
|
|
||||||
make install
|
|
||||||
|
|
||||||
FROM rust
|
FROM rust
|
||||||
RUN rustup install nightly && \
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
rustup target add --toolchain nightly wasm32-unknown-unknown && \
|
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||||
cargo install wasm-pack
|
|
||||||
|
|
||||||
COPY --from=0 /opt/wabt /opt/wabt
|
|
||||||
RUN mkdir /opt/binaryen && \
|
RUN mkdir /opt/binaryen && \
|
||||||
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.38.32/binaryen-1.38.32-x86-linux.tar.gz | tar -xzf - -C /opt/binaryen --strip 1
|
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.38.32/binaryen-1.38.32-x86-linux.tar.gz | tar -xzf - -C /opt/binaryen --strip 1
|
||||||
ENV PATH="/opt/binaryen:/opt/wabt/bin:${PATH}"
|
|
||||||
|
RUN mkdir /opt/wabt && \
|
||||||
|
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.11/wabt-1.0.11-linux.tar.gz | tar -xzf - -C /opt/wabt --strip 1
|
||||||
|
|
||||||
|
ENV PATH="/opt/binaryen:/opt/wabt:${PATH}"
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ echo "============================================="
|
|||||||
echo "Compiling wasm"
|
echo "Compiling wasm"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
rustup run nightly \
|
wasm-pack build
|
||||||
wasm-pack build --target no-modules
|
|
||||||
wasm-strip pkg/squooshhqx_bg.wasm
|
wasm-strip pkg/squooshhqx_bg.wasm
|
||||||
echo "Optimising WASM so it doesn't break Chrome (this takes like 10-15mins. get a cup of tea)"
|
echo "Optimising Wasm so it doesn't break Chrome (this takes like 10-15mins. get a cup of tea)"
|
||||||
echo "Once https://bugs.chromium.org/p/chromium/issues/detail?id=97480 is fixed, we can remove this step"
|
echo "Once https://crbug.com/974804 is fixed, we can remove this step"
|
||||||
wasm-opt -Os --no-validation -o pkg/squooshhqx_bg.wasm pkg/squooshhqx_bg.wasm
|
wasm-opt -Os --no-validation -o pkg/squooshhqx_bg.wasm pkg/squooshhqx_bg.wasm
|
||||||
rm pkg/.gitignore
|
rm pkg/.gitignore
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<script src ="./pkg/squooshhqx.js"></script>
|
|
||||||
<script type="module">
|
|
||||||
async function run() {
|
|
||||||
await wasm_bindgen("./pkg/squooshhqx_bg.wasm");
|
|
||||||
const bitmap = await createImageBitmap(await fetch("https://i.imgur.com/MNDnBSc.png").then(r => r.blob()));
|
|
||||||
const canvas = document.createElement("canvas");
|
|
||||||
canvas.width = bitmap.width;
|
|
||||||
canvas.height = bitmap.height;
|
|
||||||
const ctx = canvas.getContext("2d");
|
|
||||||
ctx.drawImage(bitmap, 0, 0);
|
|
||||||
const imgdata = ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
||||||
const factor = 4;
|
|
||||||
const r = wasm_bindgen.resize(new Uint32Array(imgdata.data.buffer), bitmap.width, bitmap.height, factor);
|
|
||||||
|
|
||||||
canvas.width = bitmap.width * factor;
|
|
||||||
canvas.height = bitmap.height * factor;
|
|
||||||
const output = new ImageData(new Uint8ClampedArray(r.buffer), canvas.width, canvas.height);
|
|
||||||
ctx.putImageData(output, 0, 0);
|
|
||||||
canvas.style = `width: ${canvas.width}px; height: ${canvas.height}px; image-rendering: pixelated;`;
|
|
||||||
document.body.append(canvas);
|
|
||||||
}
|
|
||||||
run();
|
|
||||||
</script>
|
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
"squooshhqx.js",
|
"squooshhqx.js",
|
||||||
"squooshhqx.d.ts"
|
"squooshhqx.d.ts"
|
||||||
],
|
],
|
||||||
"browser": "squooshhqx.js",
|
"module": "squooshhqx.js",
|
||||||
"types": "squooshhqx.d.ts"
|
"types": "squooshhqx.d.ts",
|
||||||
|
"sideEffects": "false"
|
||||||
}
|
}
|
||||||
11
codecs/hqx/pkg/squooshhqx.d.ts
vendored
11
codecs/hqx/pkg/squooshhqx.d.ts
vendored
@@ -7,14 +7,3 @@
|
|||||||
* @returns {Uint32Array}
|
* @returns {Uint32Array}
|
||||||
*/
|
*/
|
||||||
export function resize(input_image: Uint32Array, input_width: number, input_height: number, factor: number): Uint32Array;
|
export function resize(input_image: Uint32Array, input_width: number, input_height: number, factor: number): Uint32Array;
|
||||||
|
|
||||||
/**
|
|
||||||
* If `module_or_path` is {RequestInfo}, makes a request and
|
|
||||||
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
||||||
*
|
|
||||||
* @param {RequestInfo | BufferSource | WebAssembly.Module} module_or_path
|
|
||||||
*
|
|
||||||
* @returns {Promise<any>}
|
|
||||||
*/
|
|
||||||
export default function init (module_or_path: RequestInfo | BufferSource | WebAssembly.Module): Promise<any>;
|
|
||||||
|
|
||||||
@@ -1,97 +1,46 @@
|
|||||||
(function() {
|
import * as wasm from './squooshhqx_bg.wasm';
|
||||||
const __exports = {};
|
|
||||||
let wasm;
|
|
||||||
|
|
||||||
let cachegetUint32Memory = null;
|
let cachegetUint32Memory = null;
|
||||||
function getUint32Memory() {
|
function getUint32Memory() {
|
||||||
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
|
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
|
||||||
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
|
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
|
||||||
}
|
}
|
||||||
return cachegetUint32Memory;
|
return cachegetUint32Memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
let WASM_VECTOR_LEN = 0;
|
let WASM_VECTOR_LEN = 0;
|
||||||
|
|
||||||
function passArray32ToWasm(arg) {
|
function passArray32ToWasm(arg) {
|
||||||
const ptr = wasm.__wbindgen_malloc(arg.length * 4);
|
const ptr = wasm.__wbindgen_malloc(arg.length * 4);
|
||||||
getUint32Memory().set(arg, ptr / 4);
|
getUint32Memory().set(arg, ptr / 4);
|
||||||
WASM_VECTOR_LEN = arg.length;
|
WASM_VECTOR_LEN = arg.length;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArrayU32FromWasm(ptr, len) {
|
let cachegetInt32Memory = null;
|
||||||
|
function getInt32Memory() {
|
||||||
|
if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) {
|
||||||
|
cachegetInt32Memory = new Int32Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachegetInt32Memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrayU32FromWasm(ptr, len) {
|
||||||
return getUint32Memory().subarray(ptr / 4, ptr / 4 + len);
|
return getUint32Memory().subarray(ptr / 4, ptr / 4 + len);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {Uint32Array} input_image
|
||||||
|
* @param {number} input_width
|
||||||
|
* @param {number} input_height
|
||||||
|
* @param {number} factor
|
||||||
|
* @returns {Uint32Array}
|
||||||
|
*/
|
||||||
|
export function resize(input_image, input_width, input_height, factor) {
|
||||||
|
const retptr = 8;
|
||||||
|
const ret = wasm.resize(retptr, passArray32ToWasm(input_image), WASM_VECTOR_LEN, input_width, input_height, factor);
|
||||||
|
const memi32 = getInt32Memory();
|
||||||
|
const v0 = getArrayU32FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
|
||||||
|
wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 4);
|
||||||
|
return v0;
|
||||||
|
}
|
||||||
|
|
||||||
let cachedGlobalArgumentPtr = null;
|
|
||||||
function globalArgumentPtr() {
|
|
||||||
if (cachedGlobalArgumentPtr === null) {
|
|
||||||
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
|
||||||
}
|
|
||||||
return cachedGlobalArgumentPtr;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param {Uint32Array} input_image
|
|
||||||
* @param {number} input_width
|
|
||||||
* @param {number} input_height
|
|
||||||
* @param {number} factor
|
|
||||||
* @returns {Uint32Array}
|
|
||||||
*/
|
|
||||||
__exports.resize = function(input_image, input_width, input_height, factor) {
|
|
||||||
const ptr0 = passArray32ToWasm(input_image);
|
|
||||||
const len0 = WASM_VECTOR_LEN;
|
|
||||||
const retptr = globalArgumentPtr();
|
|
||||||
wasm.resize(retptr, ptr0, len0, input_width, input_height, factor);
|
|
||||||
const mem = getUint32Memory();
|
|
||||||
const rustptr = mem[retptr / 4];
|
|
||||||
const rustlen = mem[retptr / 4 + 1];
|
|
||||||
|
|
||||||
const realRet = getArrayU32FromWasm(rustptr, rustlen).slice();
|
|
||||||
wasm.__wbindgen_free(rustptr, rustlen * 4);
|
|
||||||
return realRet;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
function init(module) {
|
|
||||||
|
|
||||||
let result;
|
|
||||||
const imports = {};
|
|
||||||
|
|
||||||
if (module instanceof URL || typeof module === 'string' || module instanceof Request) {
|
|
||||||
|
|
||||||
const response = fetch(module);
|
|
||||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
||||||
result = WebAssembly.instantiateStreaming(response, imports)
|
|
||||||
.catch(e => {
|
|
||||||
console.warn("`WebAssembly.instantiateStreaming` failed. Assuming this is because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
||||||
return response
|
|
||||||
.then(r => r.arrayBuffer())
|
|
||||||
.then(bytes => WebAssembly.instantiate(bytes, imports));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
result = response
|
|
||||||
.then(r => r.arrayBuffer())
|
|
||||||
.then(bytes => WebAssembly.instantiate(bytes, imports));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
result = WebAssembly.instantiate(module, imports)
|
|
||||||
.then(result => {
|
|
||||||
if (result instanceof WebAssembly.Instance) {
|
|
||||||
return { instance: result, module };
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return result.then(({instance, module}) => {
|
|
||||||
wasm = instance.exports;
|
|
||||||
init.__wbindgen_wasm_module = module;
|
|
||||||
|
|
||||||
return wasm;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.wasm_bindgen = Object.assign(init, __exports);
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|||||||
3
codecs/hqx/pkg/squooshhqx_bg.d.ts
vendored
3
codecs/hqx/pkg/squooshhqx_bg.d.ts
vendored
@@ -1,6 +1,5 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
export const memory: WebAssembly.Memory;
|
export const memory: WebAssembly.Memory;
|
||||||
export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
||||||
export function __wbindgen_global_argument_ptr(): number;
|
|
||||||
export function __wbindgen_malloc(a: number): number;
|
export function __wbindgen_malloc(a: number): number;
|
||||||
export function __wbindgen_free(a: number, b: number): void;
|
export function __wbindgen_free(a: number, b: number): void;
|
||||||
|
export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||||
|
|||||||
Binary file not shown.
@@ -4,84 +4,40 @@ set -e
|
|||||||
|
|
||||||
export OPTIMIZE="-Os"
|
export OPTIMIZE="-Os"
|
||||||
export PREFIX="/src/build"
|
export PREFIX="/src/build"
|
||||||
export CFLAGS="${OPTIMIZE} -I${PREFIX}/include/"
|
|
||||||
export CPPFLAGS="${OPTIMIZE} -I${PREFIX}/include/"
|
|
||||||
export LDFLAGS="${OPTIMIZE} -L${PREFIX}/lib/"
|
|
||||||
|
|
||||||
apt-get update
|
|
||||||
apt-get install -qqy autoconf libtool
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling zlib"
|
|
||||||
echo "============================================="
|
|
||||||
test -n "$SKIP_ZLIB" || (
|
|
||||||
cd node_modules/zlib
|
|
||||||
emconfigure ./configure --prefix=${PREFIX}/
|
|
||||||
emmake make
|
|
||||||
emmake make install
|
|
||||||
)
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling zlib done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling libpng"
|
|
||||||
echo "============================================="
|
|
||||||
test -n "$SKIP_LIBPNG" || (
|
|
||||||
cd node_modules/libpng
|
|
||||||
autoreconf -i
|
|
||||||
emconfigure ./configure --with-zlib-prefix=${PREFIX}/ --prefix=${PREFIX}/
|
|
||||||
emmake make
|
|
||||||
emmake make install
|
|
||||||
)
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling libpng done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling optipng"
|
echo "Compiling optipng"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
emcc \
|
cd node_modules/optipng
|
||||||
${OPTIMIZE} \
|
CFLAGS="${OPTIMIZE} -Isrc/zlib" emconfigure ./configure --prefix=${PREFIX}
|
||||||
-Wno-implicit-function-declaration \
|
emmake make
|
||||||
-I ${PREFIX}/include \
|
emmake make install
|
||||||
-I node_modules/optipng/src/opngreduc \
|
mkdir -p ${PREFIX}/lib
|
||||||
-I node_modules/optipng/src/pngxtern \
|
mv ${PREFIX}/bin/optipng ${PREFIX}/lib/liboptipng.so
|
||||||
-I node_modules/optipng/src/cexcept \
|
|
||||||
-I node_modules/optipng/src/gifread \
|
|
||||||
-I node_modules/optipng/src/pnmio \
|
|
||||||
-I node_modules/optipng/src/minitiff \
|
|
||||||
--std=c99 -c \
|
|
||||||
node_modules/optipng/src/opngreduc/*.c \
|
|
||||||
node_modules/optipng/src/pngxtern/*.c \
|
|
||||||
node_modules/optipng/src/gifread/*.c \
|
|
||||||
node_modules/optipng/src/minitiff/*.c \
|
|
||||||
node_modules/optipng/src/pnmio/*.c \
|
|
||||||
node_modules/optipng/src/optipng/*.c
|
|
||||||
|
|
||||||
emcc \
|
|
||||||
--bind \
|
|
||||||
${OPTIMIZE} \
|
|
||||||
-s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME="optipng"' \
|
|
||||||
-I ${PREFIX}/include \
|
|
||||||
-I node_modules/optipng/src/opngreduc \
|
|
||||||
-I node_modules/optipng/src/pngxtern \
|
|
||||||
-I node_modules/optipng/src/cexcept \
|
|
||||||
-I node_modules/optipng/src/gifread \
|
|
||||||
-I node_modules/optipng/src/pnmio \
|
|
||||||
-I node_modules/optipng/src/minitiff \
|
|
||||||
-o "optipng.js" \
|
|
||||||
--std=c++11 \
|
|
||||||
optipng.cpp \
|
|
||||||
*.o \
|
|
||||||
${PREFIX}/lib/libz.so ${PREFIX}/lib/libpng.a
|
|
||||||
)
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling optipng done"
|
echo "Compiling optipng done"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling optipng wrapper"
|
||||||
|
echo "============================================="
|
||||||
|
(
|
||||||
|
emcc \
|
||||||
|
--bind \
|
||||||
|
${OPTIMIZE} \
|
||||||
|
-s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME="optipng"' \
|
||||||
|
-o "optipng.js" \
|
||||||
|
--std=c++11 \
|
||||||
|
optipng.cpp \
|
||||||
|
${PREFIX}/lib/liboptipng.so
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling optipng wrapper done"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
echo "Did you update your docker image?"
|
echo "Did you update your docker image?"
|
||||||
echo "Run \`docker pull trzeci/emscripten\`"
|
echo "Run \`docker pull trzeci/emscripten-upstream\`"
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
918
codecs/optipng/package-lock.json
generated
918
codecs/optipng/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "optipng",
|
"name": "optipng",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "tar-dependency install && napa",
|
"install": "tar-dependency install",
|
||||||
"build": "npm run build:wasm",
|
"build": "npm run build:wasm",
|
||||||
"build:wasm": "docker run --rm -v $(pwd):/src -e SKIP_ZLIB=\"${SKIP_ZLIB}\" -e SKIP_LIBPNG=\"${SKIP_LIBPNG}\" trzeci/emscripten ./build.sh"
|
"build:wasm": "docker run --rm -v $(pwd):/src trzeci/emscripten-upstream ./build.sh"
|
||||||
},
|
},
|
||||||
"tarDependencies": {
|
"tarDependencies": {
|
||||||
"node_modules/optipng": {
|
"node_modules/optipng": {
|
||||||
@@ -11,12 +11,7 @@
|
|||||||
"strip": 1
|
"strip": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"napa": {
|
|
||||||
"libpng": "emscripten-ports/libpng",
|
|
||||||
"zlib": "emscripten-ports/zlib"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"napa": "3.0.0",
|
|
||||||
"tar-dependency": "0.0.3"
|
"tar-dependency": "0.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "squooshresize"
|
name = "resize"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Surma <surma@surma.link>"]
|
authors = ["Surma <surma@surma.link>"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,9 @@
|
|||||||
FROM ubuntu
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -qqy git build-essential cmake python2.7
|
|
||||||
RUN git clone --recursive https://github.com/WebAssembly/wabt /usr/src/wabt
|
|
||||||
RUN mkdir -p /usr/src/wabt/build
|
|
||||||
WORKDIR /usr/src/wabt/build
|
|
||||||
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \
|
|
||||||
make && \
|
|
||||||
make install
|
|
||||||
|
|
||||||
FROM rust
|
FROM rust
|
||||||
RUN rustup install nightly && \
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
rustup target add --toolchain nightly wasm32-unknown-unknown && \
|
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||||
cargo install wasm-pack
|
|
||||||
|
|
||||||
COPY --from=0 /opt/wabt /opt/wabt
|
RUN mkdir /opt/wabt && \
|
||||||
ENV PATH="/opt/wabt/bin:${PATH}"
|
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.11/wabt-1.0.11-linux.tar.gz | tar -xzf - -C /opt/wabt --strip 1
|
||||||
|
|
||||||
|
ENV PATH="/opt/wabt:${PATH}"
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
// THIS IS NOT A NODE SCRIPT
|
|
||||||
// This is a d8 script. Please install jsvu[1] and install v8.
|
|
||||||
// Then run `npm run --silent benchmark`.
|
|
||||||
// [1]: https://github.com/GoogleChromeLabs/jsvu
|
|
||||||
|
|
||||||
self = global = this;
|
|
||||||
load("./pkg/resize.js");
|
|
||||||
|
|
||||||
async function init() {
|
|
||||||
// Adjustable constants.
|
|
||||||
const inputDimensions = 2000;
|
|
||||||
const outputDimensions = 1500;
|
|
||||||
const algorithm = 3; // Lanczos
|
|
||||||
const iterations = new Array(100);
|
|
||||||
|
|
||||||
// Constants. Don’t change.
|
|
||||||
const imageByteSize = inputDimensions * inputDimensions * 4;
|
|
||||||
const imageBuffer = new Uint8ClampedArray(imageByteSize);
|
|
||||||
|
|
||||||
const module = await WebAssembly.compile(readbuffer("./pkg/resize_bg.wasm"));
|
|
||||||
await wasm_bindgen(module);
|
|
||||||
[[false, false], [true, false], [false, true], [true, true]].forEach(
|
|
||||||
opts => {
|
|
||||||
print(`\npremultiplication: ${opts[0]}`);
|
|
||||||
print(`color space conversion: ${opts[1]}`);
|
|
||||||
print(`==============================`);
|
|
||||||
for (let i = 0; i < 100; i++) {
|
|
||||||
const start = Date.now();
|
|
||||||
wasm_bindgen.resize(
|
|
||||||
imageBuffer,
|
|
||||||
inputDimensions,
|
|
||||||
inputDimensions,
|
|
||||||
outputDimensions,
|
|
||||||
outputDimensions,
|
|
||||||
algorithm,
|
|
||||||
...opts
|
|
||||||
);
|
|
||||||
iterations[i] = Date.now() - start;
|
|
||||||
}
|
|
||||||
const average =
|
|
||||||
iterations.reduce((sum, c) => sum + c) / iterations.length;
|
|
||||||
const stddev = Math.sqrt(
|
|
||||||
iterations
|
|
||||||
.map(i => Math.pow(i - average, 2))
|
|
||||||
.reduce((sum, c) => sum + c) / iterations.length
|
|
||||||
);
|
|
||||||
print(`n = ${iterations.length}`);
|
|
||||||
print(`Average: ${average}`);
|
|
||||||
print(`StdDev: ${stddev}`);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
init().catch(e => console.error(e, e.stack));
|
|
||||||
@@ -6,9 +6,9 @@ echo "============================================="
|
|||||||
echo "Compiling wasm"
|
echo "Compiling wasm"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
rustup run nightly \
|
wasm-pack build
|
||||||
wasm-pack build --target no-modules
|
|
||||||
wasm-strip pkg/resize_bg.wasm
|
wasm-strip pkg/resize_bg.wasm
|
||||||
|
rm pkg/.gitignore
|
||||||
)
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm done"
|
echo "Compiling wasm done"
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
"name": "resize",
|
"name": "resize",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:image": "docker build -t squoosh-resize .",
|
"build:image": "docker build -t squoosh-resize .",
|
||||||
"build": "docker run --rm -v $(pwd):/src squoosh-resize ./build.sh",
|
"build": "docker run --rm -v $(pwd):/src squoosh-resize ./build.sh"
|
||||||
"benchmark": "v8 --no-liftoff --no-wasm-tier-up ./benchmark.js"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
codecs/resize/pkg/package.json
Normal file
15
codecs/resize/pkg/package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "resize",
|
||||||
|
"collaborators": [
|
||||||
|
"Surma <surma@surma.link>"
|
||||||
|
],
|
||||||
|
"version": "0.1.0",
|
||||||
|
"files": [
|
||||||
|
"resize_bg.wasm",
|
||||||
|
"resize.js",
|
||||||
|
"resize.d.ts"
|
||||||
|
],
|
||||||
|
"module": "resize.js",
|
||||||
|
"types": "resize.d.ts",
|
||||||
|
"sideEffects": "false"
|
||||||
|
}
|
||||||
18
codecs/resize/pkg/resize.d.ts
vendored
18
codecs/resize/pkg/resize.d.ts
vendored
@@ -1,13 +1,13 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
/**
|
/**
|
||||||
* @param {Uint8Array} arg0
|
* @param {Uint8Array} input_image
|
||||||
* @param {number} arg1
|
* @param {number} input_width
|
||||||
* @param {number} arg2
|
* @param {number} input_height
|
||||||
* @param {number} arg3
|
* @param {number} output_width
|
||||||
* @param {number} arg4
|
* @param {number} output_height
|
||||||
* @param {number} arg5
|
* @param {number} typ_idx
|
||||||
* @param {boolean} arg6
|
* @param {boolean} premultiply
|
||||||
* @param {boolean} arg7
|
* @param {boolean} color_space_conversion
|
||||||
* @returns {Uint8Array}
|
* @returns {Uint8Array}
|
||||||
*/
|
*/
|
||||||
export function resize(arg0: Uint8Array, arg1: number, arg2: number, arg3: number, arg4: number, arg5: number, arg6: boolean, arg7: boolean): Uint8Array;
|
export function resize(input_image: Uint8Array, input_width: number, input_height: number, output_width: number, output_height: number, typ_idx: number, premultiply: boolean, color_space_conversion: boolean): Uint8Array;
|
||||||
|
|||||||
@@ -1,114 +1,50 @@
|
|||||||
(function() {
|
import * as wasm from './resize_bg.wasm';
|
||||||
var wasm;
|
|
||||||
const __exports = {};
|
|
||||||
|
|
||||||
|
let cachegetUint8Memory = null;
|
||||||
let cachegetUint8Memory = null;
|
function getUint8Memory() {
|
||||||
function getUint8Memory() {
|
|
||||||
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
|
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
|
||||||
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
|
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
|
||||||
}
|
}
|
||||||
return cachegetUint8Memory;
|
return cachegetUint8Memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
let WASM_VECTOR_LEN = 0;
|
let WASM_VECTOR_LEN = 0;
|
||||||
|
|
||||||
function passArray8ToWasm(arg) {
|
function passArray8ToWasm(arg) {
|
||||||
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
|
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
|
||||||
getUint8Memory().set(arg, ptr / 1);
|
getUint8Memory().set(arg, ptr / 1);
|
||||||
WASM_VECTOR_LEN = arg.length;
|
WASM_VECTOR_LEN = arg.length;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getArrayU8FromWasm(ptr, len) {
|
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);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
let cachedGlobalArgumentPtr = null;
|
|
||||||
function globalArgumentPtr() {
|
|
||||||
if (cachedGlobalArgumentPtr === null) {
|
|
||||||
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
|
||||||
}
|
|
||||||
return cachedGlobalArgumentPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cachegetUint32Memory = null;
|
|
||||||
function getUint32Memory() {
|
|
||||||
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
|
|
||||||
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachegetUint32Memory;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param {Uint8Array} arg0
|
|
||||||
* @param {number} arg1
|
|
||||||
* @param {number} arg2
|
|
||||||
* @param {number} arg3
|
|
||||||
* @param {number} arg4
|
|
||||||
* @param {number} arg5
|
|
||||||
* @param {boolean} arg6
|
|
||||||
* @param {boolean} arg7
|
|
||||||
* @returns {Uint8Array}
|
|
||||||
*/
|
|
||||||
__exports.resize = function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
|
|
||||||
const ptr0 = passArray8ToWasm(arg0);
|
|
||||||
const len0 = WASM_VECTOR_LEN;
|
|
||||||
const retptr = globalArgumentPtr();
|
|
||||||
wasm.resize(retptr, ptr0, len0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
|
|
||||||
const mem = getUint32Memory();
|
|
||||||
const rustptr = mem[retptr / 4];
|
|
||||||
const rustlen = mem[retptr / 4 + 1];
|
|
||||||
|
|
||||||
const realRet = getArrayU8FromWasm(rustptr, rustlen).slice();
|
|
||||||
wasm.__wbindgen_free(rustptr, rustlen * 1);
|
|
||||||
return realRet;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const heap = new Array(32);
|
|
||||||
|
|
||||||
heap.fill(undefined);
|
|
||||||
|
|
||||||
heap.push(undefined, null, true, false);
|
|
||||||
|
|
||||||
let heap_next = heap.length;
|
|
||||||
|
|
||||||
function dropObject(idx) {
|
|
||||||
if (idx < 36) return;
|
|
||||||
heap[idx] = heap_next;
|
|
||||||
heap_next = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
__exports.__wbindgen_object_drop_ref = function(i) { dropObject(i); };
|
|
||||||
|
|
||||||
function init(path_or_module) {
|
|
||||||
let instantiation;
|
|
||||||
const imports = { './resize': __exports };
|
|
||||||
if (path_or_module instanceof WebAssembly.Module) {
|
|
||||||
instantiation = WebAssembly.instantiate(path_or_module, imports)
|
|
||||||
.then(instance => {
|
|
||||||
return { instance, module: path_or_module }
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const data = fetch(path_or_module);
|
|
||||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
||||||
instantiation = WebAssembly.instantiateStreaming(data, imports)
|
|
||||||
.catch(e => {
|
|
||||||
console.warn("`WebAssembly.instantiateStreaming` failed. Assuming this is because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
||||||
return data
|
|
||||||
.then(r => r.arrayBuffer())
|
|
||||||
.then(bytes => WebAssembly.instantiate(bytes, imports));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
instantiation = data
|
|
||||||
.then(response => response.arrayBuffer())
|
|
||||||
.then(buffer => WebAssembly.instantiate(buffer, imports));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instantiation.then(({instance}) => {
|
|
||||||
wasm = init.wasm = instance.exports;
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
self.wasm_bindgen = Object.assign(init, __exports);
|
|
||||||
})();
|
|
||||||
|
|||||||
1
codecs/resize/pkg/resize_bg.d.ts
vendored
1
codecs/resize/pkg/resize_bg.d.ts
vendored
@@ -1,6 +1,5 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
export const memory: WebAssembly.Memory;
|
export const memory: WebAssembly.Memory;
|
||||||
export function __wbindgen_global_argument_ptr(): number;
|
|
||||||
export function __wbindgen_malloc(a: number): number;
|
export function __wbindgen_malloc(a: number): number;
|
||||||
export function __wbindgen_free(a: number, b: number): void;
|
export function __wbindgen_free(a: number, b: number): void;
|
||||||
export function resize(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
|
export function resize(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
|
||||||
|
|||||||
Binary file not shown.
@@ -1,17 +1,8 @@
|
|||||||
FROM ubuntu
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -qqy git build-essential cmake python2.7
|
|
||||||
RUN git clone --recursive https://github.com/WebAssembly/wabt /usr/src/wabt
|
|
||||||
RUN mkdir -p /usr/src/wabt/build
|
|
||||||
WORKDIR /usr/src/wabt/build
|
|
||||||
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \
|
|
||||||
make && \
|
|
||||||
make install
|
|
||||||
|
|
||||||
FROM rust
|
FROM rust
|
||||||
RUN rustup install nightly && \
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
rustup target add --toolchain nightly wasm32-unknown-unknown
|
|
||||||
|
|
||||||
COPY --from=0 /opt/wabt /opt/wabt
|
RUN mkdir /opt/wabt && \
|
||||||
ENV PATH="/opt/wabt/bin:${PATH}"
|
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.11/wabt-1.0.11-linux.tar.gz | tar -xzf - -C /opt/wabt --strip 1
|
||||||
|
|
||||||
|
ENV PATH="/opt/wabt:${PATH}"
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ echo "============================================="
|
|||||||
echo "Compiling wasm"
|
echo "Compiling wasm"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
rustup run nightly \
|
|
||||||
cargo build \
|
cargo build \
|
||||||
--target wasm32-unknown-unknown \
|
--target wasm32-unknown-unknown \
|
||||||
--release
|
--release
|
||||||
|
|||||||
Binary file not shown.
BIN
icon-large-maskable.png
Normal file
BIN
icon-large-maskable.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
1517
package-lock.json
generated
1517
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "squoosh",
|
"name": "squoosh",
|
||||||
"version": "1.8.1",
|
"version": "1.9.1",
|
||||||
"license": "apache-2.0",
|
"license": "apache-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack-dev-server --host 0.0.0.0 --hot",
|
"start": "webpack-dev-server --host 0.0.0.0 --hot",
|
||||||
@@ -16,32 +16,32 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "10.14.9",
|
"@types/node": "10.14.15",
|
||||||
"@types/pretty-bytes": "5.1.0",
|
"@types/pretty-bytes": "5.1.0",
|
||||||
"@types/webassembly-js-api": "0.0.3",
|
"@types/webassembly-js-api": "0.0.3",
|
||||||
"@webcomponents/custom-elements": "1.2.4",
|
"@webcomponents/custom-elements": "1.2.4",
|
||||||
"@webpack-cli/serve": "0.1.8",
|
"@webpack-cli/serve": "0.1.8",
|
||||||
"assets-webpack-plugin": "3.9.10",
|
"assets-webpack-plugin": "3.9.10",
|
||||||
"chalk": "2.4.2",
|
"chalk": "2.4.2",
|
||||||
"chokidar": "3.0.1",
|
"chokidar": "3.0.2",
|
||||||
"classnames": "2.2.6",
|
"classnames": "2.2.6",
|
||||||
"clean-webpack-plugin": "1.0.1",
|
"clean-webpack-plugin": "1.0.1",
|
||||||
"comlink": "3.1.1",
|
"comlink": "3.1.1",
|
||||||
"copy-webpack-plugin": "5.0.3",
|
"copy-webpack-plugin": "5.0.4",
|
||||||
"critters-webpack-plugin": "2.3.0",
|
"critters-webpack-plugin": "2.4.0",
|
||||||
"css-loader": "1.0.1",
|
"css-loader": "1.0.1",
|
||||||
"ejs": "2.6.2",
|
"ejs": "2.6.2",
|
||||||
"escape-string-regexp": "2.0.0",
|
"escape-string-regexp": "2.0.0",
|
||||||
"exports-loader": "0.7.0",
|
"exports-loader": "0.7.0",
|
||||||
"file-drop-element": "0.2.0",
|
"file-drop-element": "0.2.0",
|
||||||
"file-loader": "4.0.0",
|
"file-loader": "4.2.0",
|
||||||
"gzip-size": "5.1.1",
|
"gzip-size": "5.1.1",
|
||||||
"html-webpack-plugin": "3.2.0",
|
"html-webpack-plugin": "3.2.0",
|
||||||
"husky": "2.4.1",
|
"husky": "3.0.4",
|
||||||
"idb-keyval": "3.2.0",
|
"idb-keyval": "3.2.0",
|
||||||
"linkstate": "1.1.1",
|
"linkstate": "1.1.1",
|
||||||
"loader-utils": "1.2.3",
|
"loader-utils": "1.2.3",
|
||||||
"mini-css-extract-plugin": "0.7.0",
|
"mini-css-extract-plugin": "0.8.0",
|
||||||
"minimatch": "3.0.4",
|
"minimatch": "3.0.4",
|
||||||
"node-fetch": "2.6.0",
|
"node-fetch": "2.6.0",
|
||||||
"node-sass": "4.12.0",
|
"node-sass": "4.12.0",
|
||||||
@@ -49,28 +49,28 @@
|
|||||||
"pointer-tracker": "2.0.3",
|
"pointer-tracker": "2.0.3",
|
||||||
"preact": "8.4.2",
|
"preact": "8.4.2",
|
||||||
"prerender-loader": "1.3.0",
|
"prerender-loader": "1.3.0",
|
||||||
"pretty-bytes": "5.2.0",
|
"pretty-bytes": "5.3.0",
|
||||||
"progress-bar-webpack-plugin": "1.12.1",
|
"progress-bar-webpack-plugin": "1.12.1",
|
||||||
"raw-loader": "3.0.0",
|
"raw-loader": "3.1.0",
|
||||||
"readdirp": "3.0.2",
|
"readdirp": "3.1.2",
|
||||||
"sass-loader": "7.1.0",
|
"sass-loader": "7.3.1",
|
||||||
"script-ext-html-webpack-plugin": "2.1.3",
|
"script-ext-html-webpack-plugin": "2.1.4",
|
||||||
"source-map-loader": "0.2.4",
|
"source-map-loader": "0.2.4",
|
||||||
"style-loader": "0.23.1",
|
"style-loader": "1.0.0",
|
||||||
"terser-webpack-plugin": "1.3.0",
|
"terser-webpack-plugin": "1.4.1",
|
||||||
"travis-size-report": "1.0.1",
|
"travis-size-report": "1.1.0",
|
||||||
"ts-loader": "6.0.3",
|
"ts-loader": "6.0.3",
|
||||||
"tslint": "5.17.0",
|
"tslint": "5.19.0",
|
||||||
"tslint-config-airbnb": "5.11.1",
|
"tslint-config-airbnb": "5.11.1",
|
||||||
"tslint-config-semistandard": "8.0.1",
|
"tslint-config-semistandard": "8.0.1",
|
||||||
"tslint-react": "4.0.0",
|
"tslint-react": "4.0.0",
|
||||||
"typed-css-modules": "0.4.2",
|
"typed-css-modules": "0.4.2",
|
||||||
"typescript": "3.5.2",
|
"typescript": "3.5.3",
|
||||||
"url-loader": "2.0.0",
|
"url-loader": "2.1.0",
|
||||||
"webpack": "4.28.0",
|
"webpack": "4.28.0",
|
||||||
"webpack-bundle-analyzer": "3.3.2",
|
"webpack-bundle-analyzer": "3.4.1",
|
||||||
"webpack-cli": "3.3.4",
|
"webpack-cli": "3.3.4",
|
||||||
"webpack-dev-server": "3.7.1",
|
"webpack-dev-server": "3.8.0",
|
||||||
"worker-plugin": "3.1.0"
|
"worker-plugin": "3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,12 @@
|
|||||||
import wasmUrl from '../../../codecs/hqx/pkg/squooshhqx_bg.wasm';
|
import { resize } from '../../../codecs/hqx/pkg';
|
||||||
import '../../../codecs/hqx/pkg/squooshhqx';
|
|
||||||
import { HqxOptions } from './processor-meta';
|
import { HqxOptions } from './processor-meta';
|
||||||
|
|
||||||
interface WasmBindgenExports {
|
|
||||||
resize: typeof import('../../../codecs/hqx/pkg/squooshhqx').resize;
|
|
||||||
}
|
|
||||||
|
|
||||||
type WasmBindgen = ((url: string) => Promise<void>) & WasmBindgenExports;
|
|
||||||
|
|
||||||
declare var wasm_bindgen: WasmBindgen;
|
|
||||||
|
|
||||||
const ready = wasm_bindgen(wasmUrl);
|
|
||||||
|
|
||||||
export async function hqx(
|
export async function hqx(
|
||||||
data: ImageData,
|
data: ImageData,
|
||||||
opts: HqxOptions,
|
opts: HqxOptions,
|
||||||
): Promise<ImageData> {
|
): Promise<ImageData> {
|
||||||
const input = data;
|
const input = data;
|
||||||
await ready;
|
const result = resize(
|
||||||
const result = wasm_bindgen.resize(
|
|
||||||
new Uint32Array(input.data.buffer),
|
new Uint32Array(input.data.buffer),
|
||||||
input.width,
|
input.width,
|
||||||
input.height,
|
input.height,
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
import wasmUrl from '../../../codecs/resize/pkg/resize_bg.wasm';
|
|
||||||
import '../../../codecs/resize/pkg/resize';
|
|
||||||
import { WorkerResizeOptions } from './processor-meta';
|
import { WorkerResizeOptions } from './processor-meta';
|
||||||
import { getContainOffsets } from './util';
|
import { getContainOffsets } from './util';
|
||||||
|
import { resize as codecResize } from '../../../codecs/resize/pkg';
|
||||||
interface WasmBindgenExports {
|
|
||||||
resize: typeof import('../../../codecs/resize/pkg/resize').resize;
|
|
||||||
}
|
|
||||||
|
|
||||||
type WasmBindgen = ((url: string) => Promise<void>) & WasmBindgenExports;
|
|
||||||
|
|
||||||
declare var wasm_bindgen: WasmBindgen;
|
|
||||||
|
|
||||||
const ready = wasm_bindgen(wasmUrl);
|
|
||||||
|
|
||||||
function crop(data: ImageData, sx: number, sy: number, sw: number, sh: number): ImageData {
|
function crop(data: ImageData, sx: number, sy: number, sw: number, sh: number): ImageData {
|
||||||
const inputPixels = new Uint32Array(data.data.buffer);
|
const inputPixels = new Uint32Array(data.data.buffer);
|
||||||
@@ -41,9 +30,7 @@ export async function resize(data: ImageData, opts: WorkerResizeOptions): Promis
|
|||||||
input = crop(input, Math.round(sx), Math.round(sy), Math.round(sw), Math.round(sh));
|
input = crop(input, Math.round(sx), Math.round(sy), Math.round(sw), Math.round(sh));
|
||||||
}
|
}
|
||||||
|
|
||||||
await ready;
|
const result = codecResize(
|
||||||
|
|
||||||
const result = wasm_bindgen.resize(
|
|
||||||
new Uint8Array(input.data.buffer), input.width, input.height, opts.width, opts.height,
|
new Uint8Array(input.data.buffer), input.width, input.height, opts.width, opts.height,
|
||||||
resizeMethods.indexOf(opts.method), opts.premultiply, opts.linearRGB,
|
resizeMethods.indexOf(opts.method), opts.premultiply, opts.linearRGB,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
"src": "/assets/icon-large.png",
|
"src": "/assets/icon-large.png",
|
||||||
"type": "image/png",
|
"type": "image/png",
|
||||||
"sizes": "1024x1024"
|
"sizes": "1024x1024"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/assets/icon-large-maskable.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "1024x1024",
|
||||||
|
"purpose": "maskable"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"share_target": {
|
"share_target": {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const CleanPlugin = require('clean-webpack-plugin');
|
const CleanPlugin = require('clean-webpack-plugin');
|
||||||
@@ -17,11 +16,7 @@ const CrittersPlugin = require('critters-webpack-plugin');
|
|||||||
const AssetTemplatePlugin = require('./config/asset-template-plugin');
|
const AssetTemplatePlugin = require('./config/asset-template-plugin');
|
||||||
const addCssTypes = require('./config/add-css-types');
|
const addCssTypes = require('./config/add-css-types');
|
||||||
|
|
||||||
function readJson (filename) {
|
const VERSION = require('./package.json').version;
|
||||||
return JSON.parse(fs.readFileSync(filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
const VERSION = readJson('./package.json').version;
|
|
||||||
|
|
||||||
module.exports = async function (_, env) {
|
module.exports = async function (_, env) {
|
||||||
const isProd = env.mode === 'production';
|
const isProd = env.mode === 'production';
|
||||||
@@ -147,11 +142,14 @@ module.exports = async function (_, env) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// All the codec files define a global with the same name as their file name. `exports-loader` attaches those to `module.exports`.
|
// All the codec files define a global with the same name as their file name. `exports-loader` attaches those to `module.exports`.
|
||||||
test: /\/codecs\/.*\.js$/,
|
test: /\.js$/,
|
||||||
|
include: path.join(__dirname, 'src/codecs'),
|
||||||
loader: 'exports-loader'
|
loader: 'exports-loader'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\/codecs\/.*\.wasm$/,
|
// Emscripten modules don't work with Webpack's Wasm loader.
|
||||||
|
test: /\.wasm$/,
|
||||||
|
exclude: /_bg\.wasm$/,
|
||||||
// This is needed to make webpack NOT process wasm files.
|
// This is needed to make webpack NOT process wasm files.
|
||||||
// See https://github.com/webpack/webpack/issues/6725
|
// See https://github.com/webpack/webpack/issues/6725
|
||||||
type: 'javascript/auto',
|
type: 'javascript/auto',
|
||||||
@@ -160,6 +158,11 @@ module.exports = async function (_, env) {
|
|||||||
name: '[name].[hash:5].[ext]',
|
name: '[name].[hash:5].[ext]',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Wasm modules generated by Rust + wasm-pack work great with Webpack.
|
||||||
|
test: /_bg\.wasm$/,
|
||||||
|
type: 'webassembly/experimental',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
test: /\.(png|svg|jpg|gif)$/,
|
test: /\.(png|svg|jpg|gif)$/,
|
||||||
loader: 'file-loader',
|
loader: 'file-loader',
|
||||||
@@ -172,7 +175,7 @@ module.exports = async function (_, env) {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new webpack.IgnorePlugin(
|
new webpack.IgnorePlugin(
|
||||||
/(fs|crypto|path)/,
|
/(fs|crypto|path)/,
|
||||||
new RegExp(`${path.sep}codecs${path.sep}`)
|
/[/\\]codecs[/\\]/
|
||||||
),
|
),
|
||||||
|
|
||||||
// Pretty progressbar showing build progress:
|
// Pretty progressbar showing build progress:
|
||||||
@@ -239,7 +242,7 @@ module.exports = async function (_, env) {
|
|||||||
removeRedundantAttributes: true,
|
removeRedundantAttributes: true,
|
||||||
removeComments: true
|
removeComments: true
|
||||||
},
|
},
|
||||||
manifest: readJson('./src/manifest.json'),
|
manifest: require('./src/manifest.json'),
|
||||||
inject: 'body',
|
inject: 'body',
|
||||||
compile: true
|
compile: true
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user