Compare commits

..

1 Commits

Author SHA1 Message Date
Ingvar Stepanyan
02d038a8f3 Disable Worker termination on dev
This helps inspect the source code without it disappearing right from under your nose in 10 seconds.
2021-01-18 19:41:41 +00:00
18 changed files with 122 additions and 116 deletions

View File

@@ -33,7 +33,6 @@ Options:
--resize [config] Resize the image before compressing
--quant [config] Reduce the number of colors used (aka. paletting)
--rotate [config] Rotate image
--mozjpeg [config] Use MozJPEG to generate a .jpg file with the given configuration
--webp [config] Use WebP to generate a .webp file with the given configuration
--avif [config] Use AVIF to generate a .avif file with the given configuration
--jxl [config] Use JPEG-XL to generate a .jxl file with the given configuration

View File

@@ -3,9 +3,6 @@ name = "squooshhqx"
version = "0.1.0"
authors = ["Surma <surma@surma.link>"]
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
[lib]
crate-type = ["cdylib"]

28
codecs/hqx/pkg/squooshhqx.d.ts generated vendored
View File

@@ -7,13 +7,30 @@
* @param {number} factor
* @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;
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export type InitInput =
| RequestInfo
| URL
| Response
| BufferSource
| WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
readonly resize: (
a: number,
b: number,
c: number,
d: number,
e: number,
f: number,
) => void;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
}
@@ -26,5 +43,6 @@ export interface InitOutput {
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
export default function init(
module_or_path?: InitInput | Promise<InitInput>,
): Promise<InitOutput>;

View File

@@ -1,9 +1,11 @@
let wasm;
let cachegetUint32Memory0 = null;
function getUint32Memory0() {
if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
if (
cachegetUint32Memory0 === null ||
cachegetUint32Memory0.buffer !== wasm.memory.buffer
) {
cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory0;
@@ -20,7 +22,10 @@ function passArray32ToWasm0(arg, malloc) {
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
if (
cachegetInt32Memory0 === null ||
cachegetInt32Memory0.buffer !== wasm.memory.buffer
) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
@@ -49,15 +54,15 @@ export function resize(input_image, input_width, input_height, factor) {
async function load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
if (module.headers.get('Content-Type') != 'application/wasm') {
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
console.warn(
'`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n',
e,
);
} else {
throw e;
}
@@ -66,14 +71,11 @@ async function load(module, imports) {
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return { instance, module };
} else {
return instance;
}
@@ -86,8 +88,11 @@ async function init(input) {
}
const imports = {};
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
if (
typeof input === 'string' ||
(typeof Request === 'function' && input instanceof Request) ||
(typeof URL === 'function' && input instanceof URL)
) {
input = fetch(input);
}
@@ -100,4 +105,3 @@ async function init(input) {
}
export default init;

Binary file not shown.

View File

@@ -46,10 +46,7 @@ $(CODEC_DIR)/Makefile: $(CODEC_DIR)/configure
--without-turbojpeg \
--without-simd \
--without-arith-enc \
--without-arith-dec \
--with-build-date=squoosh
# ^ If not provided with a dummy value, MozJPEG includes a build date in the
# binary as part of the version string, making binaries different each time.
--without-arith-dec
$(CODEC_DIR)/configure: $(CODEC_DIR)/configure.ac
cd $(CODEC_DIR) && autoreconf -iv

Binary file not shown.

View File

@@ -6,7 +6,7 @@ edition = "2018"
publish = false
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
wasm-opt = ["-O", "--no-validation"]
[lib]
crate-type = ["cdylib"]

View File

@@ -4,12 +4,8 @@ set -e
rm -rf pkg,{-parallel}
export CFLAGS="${CFLAGS} -DUNALIGNED_ACCESS_IS_FAST=1"
wasm-pack build -t web -- --locked
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory' wasm-pack build -t web -d pkg-parallel -- -Z build-std=panic_abort,std --features=parallel --locked
wasm-pack build -t web
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory' wasm-pack build -t web -d pkg-parallel -- -Z build-std=panic_abort,std --features=parallel
# Workaround https://github.com/rustwasm/wasm-bindgen/issues/2133:
sed -i "s|maybe_memory:|maybe_memory?:|" pkg-parallel/squoosh_oxipng.d.ts
# Workaround wasm-pack using a very old wasm-opt.
echo "Optimizing wasm binaries with \`wasm-opt\`..."
wasm-opt -O pkg/squoosh_oxipng_bg.wasm -o pkg/squoosh_oxipng_bg.wasm
wasm-opt -O pkg-parallel/squoosh_oxipng_bg.wasm -o pkg-parallel/squoosh_oxipng_bg.wasm
rm pkg{,-parallel}/.gitignore

View File

@@ -6,7 +6,7 @@ edition = "2018"
publish = false
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
wasm-opt = ["-O", "--no-validation"]
[lib]
crate-type = ["cdylib"]

Binary file not shown.

View File

@@ -4,10 +4,8 @@ version = "0.1.0"
authors = ["Surma <surma@surma.link>"]
publish = false
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
[lib]
#crate-type = ["cdylib", "rlib"]
crate-type = ["cdylib"]
[features]
@@ -27,6 +25,8 @@ console_error_panic_hook = { version = "0.1.1", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.2", optional = true }
[dev-dependencies]

View File

@@ -16,11 +16,4 @@ COPY --from=wasm-tools /opt/wasm-tools/wasm-pack /usr/local/cargo/bin/
ENV CPATH="/wasm32/include"
WORKDIR /src
CMD ["sh", "-c", "\
rm -rf pkg && \
wasm-pack build --target web -- --locked && \
echo 'Optimising binaries...' && \
wasm-opt -O --enable-mutable-globals pkg/*.wasm -o pkg/*.wasm && \
rm pkg/.gitignore && \
echo Done \
"]
CMD ["sh", "-c", "rm -rf pkg && wasm-pack build --target web -- --verbose --locked && rm pkg/.gitignore"]

View File

@@ -58,9 +58,11 @@ for (const methodName of methodNames) {
signal.removeEventListener('abort', onAbort);
// Start a timer to clear up the worker.
if (__PRODUCTION__) {
this._workerTimeout = setTimeout(() => {
this._terminateWorker();
}, workerTimeout);
}
});
});