diff --git a/codecs/oxipng/Cargo.lock b/codecs/oxipng/Cargo.lock index 7b304a0c1..a8b333c9a 100644 --- a/codecs/oxipng/Cargo.lock +++ b/codecs/oxipng/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - [[package]] name = "bitvec" version = "1.0.1" @@ -22,21 +16,21 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.4.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" [[package]] name = "cc" -version = "1.0.66" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" +checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" [[package]] name = "cfg-if" @@ -45,51 +39,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "crossbeam-channel" -version = "0.5.10" +name = "crc32fast" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.17" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.18" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "either" -version = "1.6.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "equivalent" @@ -111,9 +107,9 @@ checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", @@ -122,42 +118,42 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.48" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libdeflate-sys" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67921a7f85100c1559efc3d1c7c472091b7da05f304b4bbd5356f075e97f1cc2" +checksum = "669ea17f9257bcb48c09c7ee4bef3957777504acffac557263e20c11001977bc" dependencies = [ "cc", ] [[package]] name = "libdeflater" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a31b22f662350ec294b13859f935aea772ba7b2bc8776269f4a5627308eab7d" +checksum = "8dfd6424f7010ee0a3416f1d796d0450e3ad3ac237a237644f728277c4ded016" dependencies = [ "libdeflate-sys", ] [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oxipng" @@ -174,22 +170,23 @@ dependencies = [ "rgb", "rustc-hash", "rustc_version", + "zopfli", ] [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.8" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -202,22 +199,24 @@ checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" [[package]] name = "rayon" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", + "wasm_sync", ] [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", + "wasm_sync", ] [[package]] @@ -246,15 +245,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] -name = "spmc" -version = "0.3.0" +name = "simd-adler32" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02a8428da277a8e3a15271d79943e80ccc2ef254e78813a166a08d65e4c3ece5" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "squoosh-oxipng" @@ -268,13 +267,13 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.72" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -284,16 +283,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] -name = "unicode-xid" -version = "0.2.1" +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" + +[[package]] +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -301,13 +306,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -316,9 +321,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -326,9 +331,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -339,21 +344,42 @@ dependencies = [ [[package]] name = "wasm-bindgen-rayon" -version = "1.0.1" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3069d2a42e7a7e3bfde668f84adb5fbc35701ca2b39b27a064cbd5ede4e78194" +checksum = "c9e02b7785fe15de188657b7d3a234ef042bfd8da10822016915e06d4e29cba7" dependencies = [ + "crossbeam-channel", "js-sys", "rayon", - "spmc", "wasm-bindgen", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "wasm_sync" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff360cade7fec41ff0e9d2cda57fe58258c5f16def0e21302394659e6bbb0ea" +dependencies = [ + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "web-sys" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "wyz" @@ -363,3 +389,15 @@ checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] + +[[package]] +name = "zopfli" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1f48f3508a3a3f2faee01629564400bc12260f6214a056d06a3aaaa6ef0736" +dependencies = [ + "crc32fast", + "log", + "simd-adler32", + "typed-arena", +] diff --git a/codecs/oxipng/Cargo.toml b/codecs/oxipng/Cargo.toml index 8951fe788..521da2e48 100644 --- a/codecs/oxipng/Cargo.toml +++ b/codecs/oxipng/Cargo.toml @@ -12,7 +12,7 @@ wasm-opt = ["-O", "--no-validation"] crate-type = ["cdylib"] [dependencies] -oxipng = { version = "9.0", default-features = false, features = ["freestanding"] } +oxipng = { version = "9.0", default-features = false, features = ["freestanding", "zopfli"] } wasm-bindgen = "0.2.73" log = { version = "0.4.11", features = ["release_max_level_off"] } wasm-bindgen-rayon = { version = "1.0", optional = true } @@ -22,4 +22,4 @@ lto = true opt-level = "s" [features] -parallel = ["oxipng/parallel", "wasm-bindgen-rayon"] +parallel = ["oxipng/parallel", "wasm-bindgen-rayon", "oxipng/zopfli"] diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts index b776436b0..978363059 100644 --- a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts +++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts @@ -1,14 +1,29 @@ /* tslint:disable */ /* eslint-disable */ + +import { Deflaters } from "features/encoders/oxiPNG/shared/meta"; + /** * @param {Uint8ClampedArray} data * @param {number} width * @param {number} height * @param {number} level * @param {boolean} interlace +* @param {Deflaters} deflater +* @param {number} iterations +* @param {number} compressionLevel * @returns {Uint8Array} */ -export function optimise(data: Uint8ClampedArray, width: number, height: number, level: number, interlace: boolean): Uint8Array; +export function optimise( + data: Uint8ClampedArray, + width: number, + height: number, + level: number, + interlace: boolean, + deflater: Deflaters, + iterations: number, + compressionLevel: number, +): Uint8Array; /** * @param {number} num_threads * @returns {Promise} @@ -38,7 +53,7 @@ export class wbg_rayon_PoolBuilder { export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export interface InitOutput { - readonly optimise: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void; + readonly optimise: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void; readonly __wbg_wbg_rayon_poolbuilder_free: (a: number) => void; readonly wbg_rayon_poolbuilder_numThreads: (a: number) => number; readonly wbg_rayon_poolbuilder_receiver: (a: number) => number; diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng.js b/codecs/oxipng/pkg-parallel/squoosh_oxipng.js index b857edafc..a8639802c 100644 --- a/codecs/oxipng/pkg-parallel/squoosh_oxipng.js +++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng.js @@ -59,14 +59,17 @@ function getArrayU8FromWasm0(ptr, len) { * @param {number} height * @param {number} level * @param {boolean} interlace +* @param {Deflaters} deflater +* @param {number} iterations +* @param {number} compressionLevel * @returns {Uint8Array} */ -export function optimise(data, width, height, level, interlace) { +export function optimise(data, width, height, level, interlace, deflater, iterations, compressionLevel) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc); var len0 = WASM_VECTOR_LEN; - wasm.optimise(retptr, ptr0, len0, width, height, level, interlace); + wasm.optimise(retptr, ptr0, len0, width, height, level, interlace, deflater, iterations, compressionLevel); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getArrayU8FromWasm0(r0, r1).slice(); 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 e47f8eb5a..88302920c 100644 --- a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts +++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts @@ -1,6 +1,6 @@ /* tslint:disable */ /* eslint-disable */ -export function optimise(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; +export function optimise(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; export function __wbg_wbg_rayon_poolbuilder_free(a: number): void; export function wbg_rayon_poolbuilder_numThreads(a: number): number; export function wbg_rayon_poolbuilder_receiver(a: number): number; diff --git a/codecs/oxipng/pkg/squoosh_oxipng.d.ts b/codecs/oxipng/pkg/squoosh_oxipng.d.ts index a82fca90e..659600d78 100644 --- a/codecs/oxipng/pkg/squoosh_oxipng.d.ts +++ b/codecs/oxipng/pkg/squoosh_oxipng.d.ts @@ -1,20 +1,35 @@ /* tslint:disable */ /* eslint-disable */ + +import { Deflaters } from "features/encoders/oxiPNG/shared/meta"; + /** * @param {Uint8ClampedArray} data * @param {number} width * @param {number} height * @param {number} level * @param {boolean} interlace +* @param {Deflaters} deflater +* @param {number} iterations +* @param {number} compressionLevel * @returns {Uint8Array} */ -export function optimise(data: Uint8ClampedArray, width: number, height: number, level: number, interlace: boolean): Uint8Array; +export function optimise( + data: Uint8ClampedArray, + width: number, + height: number, + level: number, + interlace: boolean, + deflater: Deflaters, + iterations: number, + compressionLevel: number, +): Uint8Array; export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export interface InitOutput { readonly memory: WebAssembly.Memory; - readonly optimise: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void; + readonly optimise: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void; readonly __wbindgen_add_to_stack_pointer: (a: number) => number; readonly __wbindgen_malloc: (a: number) => number; readonly __wbindgen_free: (a: number, b: number) => void; diff --git a/codecs/oxipng/pkg/squoosh_oxipng.js b/codecs/oxipng/pkg/squoosh_oxipng.js index eb9bb70e3..9239da99a 100644 --- a/codecs/oxipng/pkg/squoosh_oxipng.js +++ b/codecs/oxipng/pkg/squoosh_oxipng.js @@ -43,14 +43,17 @@ function getArrayU8FromWasm0(ptr, len) { * @param {number} height * @param {number} level * @param {boolean} interlace +* @param {Deflaters} deflater +* @param {number} iterations +* @param {number} compressionLevel * @returns {Uint8Array} */ -export function optimise(data, width, height, level, interlace) { +export function optimise(data, width, height, level, interlace, deflater, iterations, compressionLevel) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc); var len0 = WASM_VECTOR_LEN; - wasm.optimise(retptr, ptr0, len0, width, height, level, interlace); + wasm.optimise(retptr, ptr0, len0, width, height, level, interlace, deflater, iterations, compressionLevel); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getArrayU8FromWasm0(r0, r1).slice(); diff --git a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts index a5eaf8565..613d92800 100644 --- a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts +++ b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts @@ -1,7 +1,7 @@ /* tslint:disable */ /* eslint-disable */ export const memory: WebAssembly.Memory; -export function optimise(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; +export function optimise(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; export function __wbindgen_add_to_stack_pointer(a: number): number; export function __wbindgen_malloc(a: number): number; export function __wbindgen_free(a: number, b: number): void; diff --git a/codecs/oxipng/src/lib.rs b/codecs/oxipng/src/lib.rs index 1047a2ab4..f1a033019 100644 --- a/codecs/oxipng/src/lib.rs +++ b/codecs/oxipng/src/lib.rs @@ -1,7 +1,8 @@ #[cfg(feature = "parallel")] pub use wasm_bindgen_rayon::init_thread_pool; -use oxipng::{BitDepth, ColorType, Interlacing}; +use oxipng::{BitDepth, ColorType, Deflaters, Interlacing}; +use std::num::NonZeroU8; use wasm_bindgen::prelude::*; use wasm_bindgen::Clamped; @@ -12,9 +13,22 @@ pub fn optimise( height: u32, level: u8, interlace: bool, + deflater: u8, + iterations: u8, + compression_level: u8, ) -> Vec { + let def = match deflater { + 0 => Deflaters::Libdeflater { + compression: compression_level, + }, + 1 => Deflaters::Zopfli { + iterations: NonZeroU8::new(iterations).unwrap(), + }, + _ => panic!("Invalid deflater id"), + }; let mut options = oxipng::Options::from_preset(level); options.optimize_alpha = true; + options.deflate = def; options.interlace = Some(if interlace { Interlacing::Adam7 } else { diff --git a/src/features/encoders/oxiPNG/client/index.tsx b/src/features/encoders/oxiPNG/client/index.tsx index e16b8e7ca..c597d4997 100644 --- a/src/features/encoders/oxiPNG/client/index.tsx +++ b/src/features/encoders/oxiPNG/client/index.tsx @@ -1,11 +1,12 @@ import { inputFieldChecked } from 'client/lazy-app/util'; -import { EncodeOptions } from '../shared/meta'; +import { defaultOptions, Deflaters, EncodeOptions } from '../shared/meta'; import type WorkerBridge from 'client/lazy-app/worker-bridge'; import { h, Component } from 'preact'; import { inputFieldValueAsNumber, preventDefault } from 'client/lazy-app/util'; import * as style from 'client/lazy-app/Compress/Options/style.css'; import Range from 'client/lazy-app/Compress/Options/Range'; import Checkbox from 'client/lazy-app/Compress/Options/Checkbox'; +import Select from 'client/lazy-app/Compress/Options/Select'; export async function encode( signal: AbortSignal, @@ -30,7 +31,11 @@ export class Options extends Component { const options: EncodeOptions = { level: inputFieldValueAsNumber(form.level), interlace: inputFieldChecked(form.interlace), + deflater: inputFieldValueAsNumber(form.deflater), + iterations: inputFieldValueAsNumber(form.iterations, 5), + compressionLevel: inputFieldValueAsNumber(form.compressionLevel, 11), }; + this.props.onChange(options); }; @@ -57,6 +62,45 @@ export class Options extends Component { Effort: + + {this.props.options.deflater == Deflaters.libdeflater && ( +
+ + Compression level: + +
+ )} + {this.props.options.deflater == Deflaters.zopfli && ( +
+ + Iterations: + +
+ )} ); } diff --git a/src/features/encoders/oxiPNG/shared/meta.ts b/src/features/encoders/oxiPNG/shared/meta.ts index 7ee614005..6cbf1fcc2 100644 --- a/src/features/encoders/oxiPNG/shared/meta.ts +++ b/src/features/encoders/oxiPNG/shared/meta.ts @@ -10,9 +10,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +export const enum Deflaters { + libdeflater, + zopfli, +} + export interface EncodeOptions { level: number; interlace: boolean; + deflater: Deflaters; + iterations: number; + compressionLevel: number; } export const label = 'OxiPNG'; @@ -22,4 +30,7 @@ export const extension = 'png'; export const defaultOptions: EncodeOptions = { level: 2, interlace: false, + deflater: Deflaters.libdeflater, + iterations: 5, + compressionLevel: 11, }; diff --git a/src/features/encoders/oxiPNG/worker/oxipngEncode.ts b/src/features/encoders/oxiPNG/worker/oxipngEncode.ts index f964f91d8..e9b9e0ca7 100644 --- a/src/features/encoders/oxiPNG/worker/oxipngEncode.ts +++ b/src/features/encoders/oxiPNG/worker/oxipngEncode.ts @@ -51,5 +51,8 @@ export default async function encode( data.height, options.level, options.interlace, + options.deflater, + options.iterations, + options.compressionLevel, ).buffer; }