From a9122ff32f79c786f067280a638d9032ac6ea9a9 Mon Sep 17 00:00:00 2001 From: Szilagyi Csaba Date: Sat, 13 Apr 2024 20:21:21 +0200 Subject: [PATCH 1/7] added drop-down --- src/features/encoders/oxiPNG/client/index.tsx | 12 +++++++++++- src/features/encoders/oxiPNG/shared/meta.ts | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/features/encoders/oxiPNG/client/index.tsx b/src/features/encoders/oxiPNG/client/index.tsx index e16b8e7ca..f1cbbff41 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 { Compressors, 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,9 @@ export class Options extends Component { const options: EncodeOptions = { level: inputFieldValueAsNumber(form.level), interlace: inputFieldChecked(form.interlace), + compressor: inputFieldValueAsNumber(form.compressor), }; + this.props.onChange(options); }; @@ -57,6 +60,13 @@ export class Options extends Component { Effort: + ); } diff --git a/src/features/encoders/oxiPNG/shared/meta.ts b/src/features/encoders/oxiPNG/shared/meta.ts index 7ee614005..9132fec92 100644 --- a/src/features/encoders/oxiPNG/shared/meta.ts +++ b/src/features/encoders/oxiPNG/shared/meta.ts @@ -10,9 +10,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +export const enum Compressors { + default, + zopfli, +} + export interface EncodeOptions { level: number; interlace: boolean; + compressor: number; } export const label = 'OxiPNG'; @@ -22,4 +28,5 @@ export const extension = 'png'; export const defaultOptions: EncodeOptions = { level: 2, interlace: false, + compressor: 0, }; From ca9c710e1d741e20b522e42667616a2c6f4c6cb1 Mon Sep 17 00:00:00 2001 From: Szilagyi Csaba Date: Mon, 15 Apr 2024 18:40:26 +0200 Subject: [PATCH 2/7] Added extra settings --- codecs/oxipng/Cargo.lock | 34 ++++++++++++ codecs/oxipng/Cargo.toml | 2 +- .../oxipng/pkg-parallel/squoosh_oxipng.d.ts | 17 +++++- codecs/oxipng/src/lib.rs | 23 +++++++- src/features/encoders/oxiPNG/client/index.tsx | 52 ++++++++++++++++--- src/features/encoders/oxiPNG/shared/meta.ts | 12 +++-- .../encoders/oxiPNG/worker/oxipngEncode.ts | 3 ++ src/shared/missing-preact-types.d.ts | 6 ++- 8 files changed, 135 insertions(+), 14 deletions(-) diff --git a/codecs/oxipng/Cargo.lock b/codecs/oxipng/Cargo.lock index 7b304a0c1..1630a9f74 100644 --- a/codecs/oxipng/Cargo.lock +++ b/codecs/oxipng/Cargo.lock @@ -44,6 +44,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-channel" version = "0.5.10" @@ -174,6 +183,7 @@ dependencies = [ "rgb", "rustc-hash", "rustc_version", + "zopfli", ] [[package]] @@ -250,6 +260,12 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "spmc" version = "0.3.0" @@ -283,6 +299,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" + [[package]] name = "unicode-xid" version = "0.2.1" @@ -363,3 +385,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..96d58eb0c 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 } diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts index b776436b0..96f54b5ed 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} diff --git a/codecs/oxipng/src/lib.rs b/codecs/oxipng/src/lib.rs index 1047a2ab4..2d56a952a 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,6 +13,9 @@ pub fn optimise( height: u32, level: u8, interlace: bool, + deflater: u8, + iterations: u8, + compression_level: u8, ) -> Vec { let mut options = oxipng::Options::from_preset(level); options.optimize_alpha = true; @@ -20,6 +24,23 @@ pub fn optimise( } else { Interlacing::None }); + match deflater { + 0 => { + options.deflate = Deflaters::Libdeflater { + compression: compression_level, + } + } + 1 => { + options.deflate = Deflaters::Zopfli { + iterations: Option::expect(NonZeroU8::new(iterations), "Should be larger than 0"), + } + } + _ => { + options.deflate = Deflaters::Libdeflater { + compression: compression_level, + } + } + } let raw = oxipng::RawImage::new(width, height, ColorType::RGBA, BitDepth::Eight, data.0) .unwrap_throw(); diff --git a/src/features/encoders/oxiPNG/client/index.tsx b/src/features/encoders/oxiPNG/client/index.tsx index f1cbbff41..9e46aa9f3 100644 --- a/src/features/encoders/oxiPNG/client/index.tsx +++ b/src/features/encoders/oxiPNG/client/index.tsx @@ -1,5 +1,5 @@ import { inputFieldChecked } from 'client/lazy-app/util'; -import { Compressors, 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'; @@ -31,7 +31,15 @@ export class Options extends Component { const options: EncodeOptions = { level: inputFieldValueAsNumber(form.level), interlace: inputFieldChecked(form.interlace), - compressor: inputFieldValueAsNumber(form.compressor), + deflater: inputFieldValueAsNumber(form.deflater), + iterations: + inputFieldValueAsNumber(form.deflater) == Deflaters.zopfli + ? inputFieldValueAsNumber(form.iterations, 1) + : defaultOptions.iterations, + compressionLevel: + inputFieldValueAsNumber(form.deflater) == Deflaters.libdeflater + ? inputFieldValueAsNumber(form.compressionLevel, 1) + : defaultOptions.compressionLevel, }; this.props.onChange(options); @@ -61,12 +69,44 @@ export class Options extends Component { + {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 9132fec92..2bc85e0b6 100644 --- a/src/features/encoders/oxiPNG/shared/meta.ts +++ b/src/features/encoders/oxiPNG/shared/meta.ts @@ -10,15 +10,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export const enum Compressors { - default, +export const enum Deflaters { + libdeflater, zopfli, } export interface EncodeOptions { level: number; interlace: boolean; - compressor: number; + deflater: Deflaters; + iterations: number; + compressionLevel: number; } export const label = 'OxiPNG'; @@ -28,5 +30,7 @@ export const extension = 'png'; export const defaultOptions: EncodeOptions = { level: 2, interlace: false, - compressor: 0, + deflater: Deflaters.libdeflater, + iterations: 1, + compressionLevel: 1, }; 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; } diff --git a/src/shared/missing-preact-types.d.ts b/src/shared/missing-preact-types.d.ts index c7c1c81dc..092987b97 100644 --- a/src/shared/missing-preact-types.d.ts +++ b/src/shared/missing-preact-types.d.ts @@ -1,7 +1,11 @@ declare module 'preact' { namespace JSX { interface HTMLAttributes { - decoding?: 'sync' | 'async' | 'auto'; + decoding?: + | 'sync' + | 'async' + | 'auto' + | SignalLike<'sync' | 'async' | 'auto' | undefined>; } } } From 931e32a8c13290ae7cfcd3b45dd07aa971700c4b Mon Sep 17 00:00:00 2001 From: Szilagyi Csaba Date: Mon, 15 Apr 2024 21:06:02 +0200 Subject: [PATCH 3/7] Filled missing parameters --- codecs/oxipng/pkg-parallel/squoosh_oxipng.js | 7 +++++-- codecs/oxipng/pkg/squoosh_oxipng.d.ts | 17 ++++++++++++++++- codecs/oxipng/pkg/squoosh_oxipng.js | 7 +++++-- src/features/encoders/oxiPNG/client/index.tsx | 10 ++-------- 4 files changed, 28 insertions(+), 13 deletions(-) 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/squoosh_oxipng.d.ts b/codecs/oxipng/pkg/squoosh_oxipng.d.ts index a82fca90e..cf001fd12 100644 --- a/codecs/oxipng/pkg/squoosh_oxipng.d.ts +++ b/codecs/oxipng/pkg/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; export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; 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/src/features/encoders/oxiPNG/client/index.tsx b/src/features/encoders/oxiPNG/client/index.tsx index 9e46aa9f3..c5de08d7d 100644 --- a/src/features/encoders/oxiPNG/client/index.tsx +++ b/src/features/encoders/oxiPNG/client/index.tsx @@ -32,14 +32,8 @@ export class Options extends Component { level: inputFieldValueAsNumber(form.level), interlace: inputFieldChecked(form.interlace), deflater: inputFieldValueAsNumber(form.deflater), - iterations: - inputFieldValueAsNumber(form.deflater) == Deflaters.zopfli - ? inputFieldValueAsNumber(form.iterations, 1) - : defaultOptions.iterations, - compressionLevel: - inputFieldValueAsNumber(form.deflater) == Deflaters.libdeflater - ? inputFieldValueAsNumber(form.compressionLevel, 1) - : defaultOptions.compressionLevel, + iterations: inputFieldValueAsNumber(form.iterations, 1), + compressionLevel: inputFieldValueAsNumber(form.compressionLevel, 1), }; this.props.onChange(options); From 58859d586f278418629017a9a3b538ea23f9c061 Mon Sep 17 00:00:00 2001 From: Szilagyi Csaba Date: Wed, 17 Apr 2024 22:40:19 +0200 Subject: [PATCH 4/7] Default value and parameter corrections --- codecs/oxipng/Cargo.lock | 168 +++++++++--------- .../oxipng/pkg-parallel/squoosh_oxipng.d.ts | 2 +- .../pkg-parallel/squoosh_oxipng_bg.wasm.d.ts | 2 +- codecs/oxipng/pkg/squoosh_oxipng.d.ts | 2 +- codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts | 2 +- codecs/oxipng/src/lib.rs | 2 +- src/features/encoders/oxiPNG/client/index.tsx | 4 +- src/features/encoders/oxiPNG/shared/meta.ts | 4 +- 8 files changed, 95 insertions(+), 91 deletions(-) diff --git a/codecs/oxipng/Cargo.lock b/codecs/oxipng/Cargo.lock index 1630a9f74..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" @@ -55,50 +49,43 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.10" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" dependencies = [ - "cfg-if", "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" @@ -120,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", @@ -131,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" @@ -188,18 +175,18 @@ dependencies = [ [[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", ] @@ -212,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]] @@ -256,9 +245,9 @@ 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 = "simd-adler32" @@ -266,12 +255,6 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" -[[package]] -name = "spmc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02a8428da277a8e3a15271d79943e80ccc2ef254e78813a166a08d65e4c3ece5" - [[package]] name = "squoosh-oxipng" version = "0.1.0" @@ -284,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]] @@ -306,16 +289,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" [[package]] -name = "unicode-xid" -version = "0.2.1" +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", @@ -323,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", @@ -338,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", @@ -348,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", @@ -361,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 = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +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 = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "wyz" diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts index 96f54b5ed..978363059 100644 --- a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts +++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts @@ -53,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_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 cf001fd12..659600d78 100644 --- a/codecs/oxipng/pkg/squoosh_oxipng.d.ts +++ b/codecs/oxipng/pkg/squoosh_oxipng.d.ts @@ -29,7 +29,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl 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_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 2d56a952a..fdfe024be 100644 --- a/codecs/oxipng/src/lib.rs +++ b/codecs/oxipng/src/lib.rs @@ -32,7 +32,7 @@ pub fn optimise( } 1 => { options.deflate = Deflaters::Zopfli { - iterations: Option::expect(NonZeroU8::new(iterations), "Should be larger than 0"), + iterations: Option::unwrap(NonZeroU8::new(iterations)), } } _ => { diff --git a/src/features/encoders/oxiPNG/client/index.tsx b/src/features/encoders/oxiPNG/client/index.tsx index c5de08d7d..c597d4997 100644 --- a/src/features/encoders/oxiPNG/client/index.tsx +++ b/src/features/encoders/oxiPNG/client/index.tsx @@ -32,8 +32,8 @@ export class Options extends Component { level: inputFieldValueAsNumber(form.level), interlace: inputFieldChecked(form.interlace), deflater: inputFieldValueAsNumber(form.deflater), - iterations: inputFieldValueAsNumber(form.iterations, 1), - compressionLevel: inputFieldValueAsNumber(form.compressionLevel, 1), + iterations: inputFieldValueAsNumber(form.iterations, 5), + compressionLevel: inputFieldValueAsNumber(form.compressionLevel, 11), }; this.props.onChange(options); diff --git a/src/features/encoders/oxiPNG/shared/meta.ts b/src/features/encoders/oxiPNG/shared/meta.ts index 2bc85e0b6..6cbf1fcc2 100644 --- a/src/features/encoders/oxiPNG/shared/meta.ts +++ b/src/features/encoders/oxiPNG/shared/meta.ts @@ -31,6 +31,6 @@ export const defaultOptions: EncodeOptions = { level: 2, interlace: false, deflater: Deflaters.libdeflater, - iterations: 1, - compressionLevel: 1, + iterations: 5, + compressionLevel: 11, }; From c8bf9616eba77cf173dcf3c83c4bcbdb80d20ad6 Mon Sep 17 00:00:00 2001 From: Szilagyi Csaba Date: Thu, 18 Apr 2024 20:21:01 +0200 Subject: [PATCH 5/7] Enable zopfli in cargo file --- codecs/oxipng/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codecs/oxipng/Cargo.toml b/codecs/oxipng/Cargo.toml index 96d58eb0c..521da2e48 100644 --- a/codecs/oxipng/Cargo.toml +++ b/codecs/oxipng/Cargo.toml @@ -22,4 +22,4 @@ lto = true opt-level = "s" [features] -parallel = ["oxipng/parallel", "wasm-bindgen-rayon"] +parallel = ["oxipng/parallel", "wasm-bindgen-rayon", "oxipng/zopfli"] From b62d9ffc2de04377a8c3c8e550372c9f9c1ce99e Mon Sep 17 00:00:00 2001 From: Csaba Szilagyi Date: Fri, 19 Apr 2024 15:56:37 +0200 Subject: [PATCH 6/7] Build error fix --- src/shared/missing-preact-types.d.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/shared/missing-preact-types.d.ts b/src/shared/missing-preact-types.d.ts index 092987b97..c7c1c81dc 100644 --- a/src/shared/missing-preact-types.d.ts +++ b/src/shared/missing-preact-types.d.ts @@ -1,11 +1,7 @@ declare module 'preact' { namespace JSX { interface HTMLAttributes { - decoding?: - | 'sync' - | 'async' - | 'auto' - | SignalLike<'sync' | 'async' | 'auto' | undefined>; + decoding?: 'sync' | 'async' | 'auto'; } } } From e3bb3a946cd06cc491b4682ac02fa80f6dc00c7f Mon Sep 17 00:00:00 2001 From: Szilagyi Csaba Date: Mon, 22 Apr 2024 19:52:00 +0200 Subject: [PATCH 7/7] Review based fixes --- codecs/oxipng/src/lib.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/codecs/oxipng/src/lib.rs b/codecs/oxipng/src/lib.rs index fdfe024be..f1a033019 100644 --- a/codecs/oxipng/src/lib.rs +++ b/codecs/oxipng/src/lib.rs @@ -17,30 +17,23 @@ pub fn optimise( 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 { Interlacing::None }); - match deflater { - 0 => { - options.deflate = Deflaters::Libdeflater { - compression: compression_level, - } - } - 1 => { - options.deflate = Deflaters::Zopfli { - iterations: Option::unwrap(NonZeroU8::new(iterations)), - } - } - _ => { - options.deflate = Deflaters::Libdeflater { - compression: compression_level, - } - } - } let raw = oxipng::RawImage::new(width, height, ColorType::RGBA, BitDepth::Eight, data.0) .unwrap_throw();