Skip to content

Make images smaller using best-in-class codecs, right in the browser.

JavaScript

Point oxipng to a patched version

Ingvar Stepanyan02c113a68ffd
diff --git a/codecs/oxipng/Cargo.lock b/codecs/oxipng/Cargo.lock
index b3d587f8..3e61cb0a 100644
--- a/codecs/oxipng/Cargo.lock
+++ b/codecs/oxipng/Cargo.lock
@@ -347,13 +347,13 @@ checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
[[package]]
name = "oxipng"
version = "3.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5687a277f33b5fe5ee2ff5ceab4417885a428a1a938e944aa7df9d7e58c35762"
+source = "git+https://github.com/RReverser/oxipng?branch=crossbeam#d0f86d2e84eb55b423b8ad194a176e71ba3aa2c3"
dependencies = [
"bit-vec",
"byteorder",
"cloudflare-zlib",
"crc",
+ "crossbeam-channel",
"image",
"indexmap",
"itertools",
diff --git a/codecs/oxipng/Cargo.toml b/codecs/oxipng/Cargo.toml
index 809a5de4..ffa9f764 100644
--- a/codecs/oxipng/Cargo.toml
+++ b/codecs/oxipng/Cargo.toml
@@ -16,6 +16,10 @@ rayon = { version = "1.3.0", optional = true }
once_cell = { version = "1.3.1", optional = true }
crossbeam-channel = { version = "0.4.2", optional = true }
+[patch.crates-io]
+# TODO: replace with upstream version once https://github.com/shssoichiro/oxipng/pull/327 is merged.
+oxipng = { git = "https://github.com/RReverser/oxipng", branch = "crossbeam" }
+
[profile.release]
lto = true
opt-level = "s"
@@ -24,4 +28,4 @@ opt-level = "s"
parallel = ["oxipng/parallel", "rayon", "crossbeam-channel", "once_cell"]
[package.metadata.wasm-pack.profile.release]
-wasm-opt = false
+wasm-opt = ["-O", "--no-validation"]
diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts
index fdd04965..b544f846 100644
--- a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts
+++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts
@@ -1,12 +1,6 @@
/* tslint:disable */
/* eslint-disable */
/**
-* @param {Uint8Array} data
-* @param {number} level
-* @returns {Uint8Array}
-*/
-export function optimise(data: Uint8Array, level: number): Uint8Array;
-/**
* @param {number} num
* @returns {any}
*/
@@ -17,16 +11,22 @@ export function start_main_thread(): void;
/**
*/
export function start_worker_thread(): void;
+/**
+* @param {Uint8Array} data
+* @param {number} level
+* @returns {Uint8Array}
+*/
+export function optimise(data: Uint8Array, level: number): Uint8Array;
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export interface InitOutput {
- readonly optimise: (a: number, b: number, c: number, d: number) => void;
readonly malloc: (a: number) => number;
readonly free: (a: number) => void;
readonly worker_initializer: (a: number) => number;
readonly start_main_thread: () => void;
readonly start_worker_thread: () => void;
+ readonly optimise: (a: number, b: number, c: number, d: number) => void;
readonly __wbindgen_export_0: WebAssembly.Memory;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng.js b/codecs/oxipng/pkg-parallel/squoosh_oxipng.js
index 0988144b..9a2a1a86 100644
--- a/codecs/oxipng/pkg-parallel/squoosh_oxipng.js
+++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng.js
@@ -33,6 +33,40 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().slice(ptr, ptr + len));
}
+function getObject(idx) { return heap[idx]; }
+
+function dropObject(idx) {
+ if (idx < 36) return;
+ heap[idx] = heap_next;
+ heap_next = idx;
+}
+
+function takeObject(idx) {
+ const ret = getObject(idx);
+ dropObject(idx);
+ return ret;
+}
+/**
+* @param {number} num
+* @returns {any}
+*/
+export function worker_initializer(num) {
+ var ret = wasm.worker_initializer(num);
+ return takeObject(ret);
+}
+
+/**
+*/
+export function start_main_thread() {
+ wasm.start_main_thread();
+}
+
+/**
+*/
+export function start_worker_thread() {
+ wasm.start_worker_thread();
+}
+
let WASM_VECTOR_LEN = 0;
function passArray8ToWasm0(arg, malloc) {
@@ -75,40 +109,6 @@ export function optimise(data, level) {
}
}
-function getObject(idx) { return heap[idx]; }
-
-function dropObject(idx) {
- if (idx < 36) return;
- heap[idx] = heap_next;
- heap_next = idx;
-}
-
-function takeObject(idx) {
- const ret = getObject(idx);
- dropObject(idx);
- return ret;
-}
-/**
-* @param {number} num
-* @returns {any}
-*/
-export function worker_initializer(num) {
- var ret = wasm.worker_initializer(num);
- return takeObject(ret);
-}
-
-/**
-*/
-export function start_main_thread() {
- wasm.start_main_thread();
-}
-
-/**
-*/
-export function start_worker_thread() {
- wasm.start_worker_thread();
-}
-
async function load(module, imports, maybe_memory) {
if (typeof Response === 'function' && module instanceof Response) {
memory = imports.wbg.memory = new WebAssembly.Memory({initial:17,maximum:16384,shared:true});
diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm
index 9f4559a0..d74672e6 100644
Binary files a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm and b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm differ
diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts
index e4189249..fb600d81 100644
--- a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts
+++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts
@@ -1,11 +1,11 @@
/* tslint:disable */
/* eslint-disable */
-export function optimise(a: number, b: number, c: number, d: number): void;
export function malloc(a: number): number;
export function free(a: number): void;
export function worker_initializer(a: number): number;
export function start_main_thread(): void;
export function start_worker_thread(): void;
+export function optimise(a: number, b: number, c: number, d: number): void;
export const __wbindgen_export_0: WebAssembly.Memory;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_free(a: number, b: number): void;
diff --git a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm
index add80603..34f4f5a2 100644
Binary files a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm and b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm differ